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

added support to get the return value(s) of lua callbacks #315

Merged
merged 3 commits into from May 16, 2022

Conversation

the0ne
Copy link
Collaborator

@the0ne the0ne commented Oct 2, 2019

special care must be taken on cleanup (see bottom lines)

lua_State *state = luaS_callback_state(callback_variable);
int top = lua_gettop(state);

luaS_callback_call_return(callback_variable, 0, 2);

int nResults = lua_gettop(state) - top;
lua_pop(state, 1); // first remove the Copy of the callback

// query+use variables here

// cleanup is required:
lua_pop(state, nResults); // pop all return values from the stack
lua_pushvalue(state, 1);  // re-add the Copy of the callback

the0ne and others added 3 commits October 2, 2019 15:08
sample code for required cleanup (see bottom lines)

lua_State *state = luaS_callback_state(callback_variable);
int top = lua_gettop(state);

luaS_callback_call_return(callback_variable, 0, 2);

int nResults = lua_gettop(state) - top;
lua_pop(state, 1); // first remove the Copy of the callback

// query+use variables here

// cleanup is required:
lua_pop(state, nResults); // pop all return values from the stack
lua_pushvalue(state, 1);  // re-add the Copy of the callback
Copy link
Collaborator Author

@the0ne the0ne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated formatting

@the0ne
Copy link
Collaborator Author

the0ne commented Jan 9, 2020

@jolivepetrus this is now again ready to be merged

@the0ne the0ne merged commit 2a44a53 into whitecatboard:master May 16, 2022
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

Successfully merging this pull request may close these issues.

None yet

1 participant