LuaD
LuaD copied to clipboard
Returning multiple unpacked values to Lua from a D function
I imagine this might be another ambiguity-dilemma issue, but in my code I've got a D-side function that does some processing and then returns results filtered through a LuaFunction.
However, if I pass the return value from LuaFunction directly back to Lua, the values are packed in an array.
For the moment, I can add a wrapper function Lua-side to run unpack() first, but it seems a little bit wasteful to just unpack what D already spent memory packing; it'd be nice to have a way of doing this directly.
Could you show some example code? I'm not entirely sure I fully understand your situation.
I think you might be looking for the variableReturn function?
...Oh, Duh! Sorry, I managed to completely overlook that. That's exactly what I want--Throwing it into my production code is triggering an ICE, but that's a problem to file with DMD.
Specifically, it seems like having a function that returns a LuaVariableReturn!(LuaObject[]), calling it from D code, and discarding the return value completely triggers an ICE, at least on DMD 2.065/Win32. Returning the contained LuaObject[] and discarding that is fine, though.
import luad.all;
static auto wrappedfunc (LuaFunction f, LuaObject[] args...) {
//ICE:
return f.call!(LuaVariableReturn!(LuaObject[]))(args);
//Works:
//return f.call!(LuaVariableReturn!(LuaObject[]))(args).returnValues;
}
void main() {
auto stat = new LuaState();
auto a = stat.loadString(`return nil`);
wrappedfunc(a);
}