Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning multiple unpacked values to Lua from a D function #68

Open
aubade opened this issue May 30, 2014 · 3 comments
Open

Returning multiple unpacked values to Lua from a D function #68

aubade opened this issue May 30, 2014 · 3 comments

Comments

@aubade
Copy link
Contributor

aubade commented May 30, 2014

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.

@JakobOvrum
Copy link
Owner

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?

@aubade
Copy link
Contributor Author

aubade commented May 31, 2014

...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.

@aubade
Copy link
Contributor Author

aubade commented Jun 2, 2014

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants