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

Calling a delegate containing a LuaFunction throws an exception #11

Closed
jacobdufault opened this issue Oct 16, 2010 · 4 comments
Closed
Labels

Comments

@jacobdufault
Copy link

Storing a LuaFunction inside of a delegate and then calling that delegate causes an exception.

void registeredLuaFunction(LuaFunction luaFunc) {
    auto func = (Entity e) {luaFunc(new EntityWrapper(e));};
    func(new Entity());
}

(EntityWrapper "wraps" Entity so that it is usable in Lua)

This issues "An exception was thrown while finalizing an instance of class luad.state.LuaState".

Any ideas? Sadly, if this is not resolved then I will probably not be able to use LuaD.

@JakobOvrum
Copy link
Owner

When creating the LuaState in which luaFunc resides, try:
auto lua = new LuaState; // or however you are creating the LuaState

//replace with:
auto L = luaL_newstate(); // requires you to import luad.c.all
auto lua = new LuaState(L);

Tell me if that fixes the exception.

@jacobdufault
Copy link
Author

Looks like it did, but why? I'm looking at LuaState and don't see the connection.

Thanks.

@JakobOvrum
Copy link
Owner

It's an internal problem which doesn't really have anything to do with your code in the first post, but may have seemed to be caused by it because it's a problem with a finalizer, which runs whenever the GC decides to do a full collect.

The work-around works by allocating your own lua_State object. It will never be closed unless you insert a call to lua_close(L) somewhere, so when the LuaState is finalized, nothing is touched. Keep in mind that this form will not install a throwing panic handler for the Lua state, so you'd have to do that manually.

I'll leave this issue open until this is properly fixed, thanks for the bug report :)

@JakobOvrum
Copy link
Owner

Should be fixed with the merging of the gcfix branch

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

No branches or pull requests

2 participants