System information

Manual:Scripting-examples
46
if ... then
local targs = {...}
for i,v in ipairs(targs) do
strPrintResult = strPrintResult .. tostring(v) .. " "
end
strPrintResult = strPrintResult .. "\r\n"
io.write(strPrintResult)
end
end
Now you can include this custom function to other scripts and use this cool custom print function :)
You can also modify this function to write messages in RouterOS log.
Read and write large files
Many users requested ability to work with files. Now you can do it without limitations.
Create and write to file:
:global newContent "new file content\r\nanother line\r\n";
[/lua "local f=assert(io.open('/test.txt', 'w+')); f:write(newContent); f:close()" ];
Read file content to variable:
:global cnt ""
[/lua "local f=assert(io.open('/test.txt', 'r')); cnt=f:read('*all'); f:close()" ];
:put $cnt
Include custom function in another script
This example will show where to store and how to include your cool custom created functions into another scripts
In router's file root directory create subdirectory named 'lua'
On your PC create new file named customprint.lua and write this function in it.
Upload newly created file in router's 'lua' directory that we made in first step
Now you can test your custom lua function
[:lua "require 'customprint'\n print('hello from custom print function')"]
References
[1] http:/ / lua-users. org/ wiki/ TutorialDirectory