moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

"moonscript.loadstring" doesn't work well with Lua 5.3

Open kazec opened this issue 8 years ago • 1 comments

In Lua 5.3, function load accepts four arguments, the last one being env, which is a table if provided.

So in Lua 5.3 you basic do:

local i = 1
f= load('print i', 'blah', 't', {i = i, print = print})
f()

and it prints 1 correctly.

However when you replace load with moonscript's loadstring, the above code no longer works. Because our env is intercepted by 'get_options'.

Would it be better to use the first argument as options? That way we can check if it is table and decide whether to use it as the options to the compiler or use an empty one.

kazec avatar Oct 29 '17 08:10 kazec

Well, forgot to mention that one can alleviate this manually by appending an extra empty table after the env to loadstring.

kazec avatar Oct 29 '17 08:10 kazec