LuaYan is an easy-to-use system that replaces the Lua load/loadstring function in controlled environments where such functionalities are limited or blocked, written in pure Lua.
It also allows the user to easily add or modify operators and introduces new assignment operators.
No dependencies are needed.
Just require the module.
local loader = require("luayan")
And use one of the functions loader.readScript
, loader.readLine
, loader.readExpression
, loader.removeComments
.
The loader makes it easy to add and modify operators functions.
Since it was written in lua 5.1, the normal version only adds the floor division operator "//"
The bitwise edition adds all bitwise operators but requires a bit library.
If you are using lua 5.3, it is easy to modify the bitwise edition and use the bitwise operators instead of the bit library.
You can add other operators by editing the operators
table in the source code, as well as editing the orderPatterns
and fastPatterns
that are used to match these operators. It is also possible to add unary operators.
Another thing that this loader adds is the assignment operators which are:
+=, -=, *=, /=, //=, %=, ^=, ..=, and=, or=
The bitwise edition also adds bitwise assignment operators such as >>=, |=, ~=
local loader = require("luayan")
local env = setmetatable({},{__index=_G})
local script = [==[
function test(arg1, arg2, ...)
local arg2 = arg2 or "test"
local all_arguments = arg1
for index, value in next, ({arg2, ...}) do
all_arguments = all_arguments .. " " .. value
end
print(all_arguments)
end
test("a", nil, "b", "c")
]==]
loader.readScript(script, env) --> a test b c