Built in function library

We are considering to add commonly used functions as built-in.
What functions would you like to see?
For example, MD5hash, random number generator and so on.

From most important to least importing in my opinion:

String replacement. Both by a string needle, and a regex match.

String splitting (into an array of strings). Both by a string needle, and a regex match.

Joining strings in an array into a single string with a specified string between each array member (implicitly convert array values with “:tostr”).

Date and time manipulation functions, such as returning the difference between two dates as a “time” value, or adding/subtracting a “time” value to a date (or “num” that is treated as plus seconds), to get a new date at that offset. Also timestamp convertion, i.e. a function to convert a “num” value to a date and time from the unix epoch, and convert a date to a “num” value that is such a timestamp. Being able to output the date and time in a different format would be nice, though it should always default to RouterOS’ current format. To that particular end, it would be awesome if there are two new scripting types - date, and datetime, to complement the already existing “time” type, along with type conversion functions. Places within RouterOS that have dates and datetimes should be updated to return typed values instead of strings.

String encoding and decoding functions. Notably, a function to convert a number to a character in a charset (defaulting to ASCII, should support at minimum that and UTF-8), and vice versa. Some other commonly used encoding schemes, such as raw URL encoding/decoding, hex encoding/decoding, hex encoding with a "" (when generating RouterOS scripts) would also be great.

Array manipulation functions. Such as a function for unique values in an array, getting the key at an index (return “nothing” if there isn’t one), sorting an array by key (with an option what to do for keyless members), or by value, in either ascending or descending order, ideally with the option to specify a comparrison function.

In addition to MD5, SHA1, SHA256 and any other OpenSSL supported hashes would be nice, for the purposes of computing hashes to either be posted to a 3rd party or comparing 3rd party checksums. On a related note, encrypting, decrypting and signing data (strings and files) with certificates in the “/certificate” menu (ala PGP) would be awesome.

In addition to a random number between two values, a “random bytes” function (where you just specify the number of bytes you want) would be nice too.

If you want to really jumpstart the Mikrotik scripting community then you should probably review the php most common sought after functions.
Also review scripts made for Mikrotik and the most commonly created functions there.
Personally any and all validation functions (ip, dns, email, url, time, date, etc) would be extremely helpfull for anyone trying to implement anything.
(disclaimer, this has nothing to do with php itself but the most adopted language by beginners, cant argue with history)

Oh, oh… one more important idea… A function to show the type and value of a variable. When outputting strings or arrays, include lengths, and when outputting strings, surround them with quotes and escape quotes, slashes and unprintable characters inside (so that what’s shown could potentially be copy&pasted into a script or parsed). Something analogus to PHP’s var_dump(), except that arrays will be shown with both indexes and keys (since RouterOS arrays can have both, whereas PHP can only have either), and perhaps return the string instead of outputting it on screen (allowing users to send it, store it in a file, etc.; not just output it on screen).

This same function, in addition to being useful when debugging scripts, will also enable RouterOS to output reliably parsable data from “print as-value”, as opposed to print’s other formats, that can all be broken if the user has set a certain value to a free form string field (e.g. comment).

I was about to post what I thought was important, then realized boen_robot has written everything I was going to :smiley:

So +1 to everything he said..

You could also take into consideration the future possibility of executing scheduled remote scripts from The Dude on remote Device.
(ex collect backups from monitored devices)

Easy, a function that creates Ports/Services groups, which then can be used in port forwarding and firewall rules etc…

I fully agree with that!

My suggestions :

ISODateTime - returns date/time in ISO format, great for saving backup files, that can be ordered, currently the ROS date used month as text.

FlashPrefix - receive an filename and return it with /flash/ when the device has an /flash directory to keep saved files

Function to keep only some characters from string (used to create safe filenames)

Replace characters on string , given an string, old character and new character all old characters found in the string are replaced by new character

Modulus of division (better to be an operator instead of function)

function to sort an array, by ascii strings or by numeric values.

hash function returning values in hex.

  1. The implementation of a switch function as an alternative to if,else.. or at least if,elseif,else.
  2. Add back in the LUA support for editing items/utilising datasets above 4k characters long.
  3. A random function would be very handy
  4. All the things boen said.

A better debugger would also be nice, but now I’m just being picky. :slight_smile:

Date/time comparison (NOW():wink: and option to get time in different formats.
Json parsing.
LUA or whatever to be able to parse larger files.

url_encode();

LUA +1
Internal JSON parser to associative array variable (by type http://www.embest.ru/mikrotik/json-parser-script)

Can you please raise the fetch variable 65535 character limit (double it or remove it completely), so that the error case “max line length 65535 exceeded!” is resolved?
It happens both with GET and POST.

As routerOS is more and more involved in the big data domain, it is imperative that such limitations are removed.

Also, is there a hardcoded fetch timeout? Can it be exposed as a fetch parameter?

SNMP-GET
I would like to poll external devices and have based on the results change routes, enable/disable interfaces.
It would be a nice feature.

I have been thinking about polling SNR/CCQ of radio links and tuning BGP parameters using the results.
First from some external Linux system, when it is workable it would be nice when the router itself could do it.

+1 for SHA1 and SHA256 hash function
better debugging environment
indication of the line number instead of no response when attempting to start a script with an syntax error
output of line number when importing a script encounters a run-time failure

JSON encoder
regexp (PCRE) string manipulation

function for in RAM memory save\load\parse any big raw data.
“tool fetch”, any backup and e.t.c scripts need save data to NAND … NAND have write limit or small size
Mikrotik need any power functions for manipulate big data in available RAM.

Would be nice the see the bitwise operator for IPv6 addresses…

[admin@MikroTik] > :put (192.168.88.10 & 255.255.0.0)
192.168.0.0
[admin@MikroTik] > :put (2003:cf:2f1e:5c00:d250:99ff:fec0:d180 & ffff:ffff:ffff:ff00::)
Script Error: cannot compute bitwise "and" of internal number and internal number