Open coldino opened 5 years ago
loadstring is not an official function any more.
To get this to work, I need to change a lot of stuff down to the parser. But it is possible to create this default argument (for load).
Btw: I use as reference: https://www.lua.org/cgi-bin/demo
I'm happy to do work for this, if you can provide more information.
My requirement is to read from a file - loadstring
was just used to demo the issue, but I see it has been replaced by simply load
.
The compile funktion has no arguments, the null needs to get an array of objects.
The offset point for all changes is in LuaGlobal.cs:333. The third parameter of CompileChunk
need the change.
First I will checkout the differents between dochunk and load. May you can provide me some detailed information, examples.
I'll do what I can. The reproduction I gave is an example of many generated files in the project I'm working on. The files in question look like:
local data = ...
data.points = { } -- with lots of data
There are also cases like this:
local skills, mod, flag, skill = ...
skills["Blah"] = { } -- with lots of data
These files are loaded using the function:
function LoadModule(fileName, ...)
if not fileName:match("%.lua") then
fileName = fileName .. ".lua"
end
local func, err = loadfile(fileName)
if func then
return func(...)
else
error("LoadModule() error loading '"..fileName.."': "..err)
end
end
The Lua docs are somewhat vague on this and state:
Vararg expressions, denoted by three dots ('...'), can only be used when directly inside a vararg function; they are explained in §3.4.11.
...but, this file is being treated as a function so I assume that means this is a valid use.
It is vague indeed, and this is not the only thing.
I changed it, know that your code should run?
local fn = load('local a, b = ...; return a, b;');
return fn(23,42);
From a quick check this does appear to help - thank you. I'll test further tomorrow.
I can't find in the Lua docs if this usage of
...
insideloadstring
orloadfile
is valid or standardised, but I do see it working on LuaJit.NeoLua Version: Latest commit (a0fdcc68d0dbb847296322e761e4adeee5db0859)
Example to reproduce:
Expected behaviour (from LuaJit):