Skip to content

Commit

Permalink
fixed Go function callback to remove the userdata representing the fu…
Browse files Browse the repository at this point in the history
…nction from the stack before calling the actual function (to match C behavior)

added calling go function w/ argument to basic example
  • Loading branch information
afitz committed Sep 26, 2010
1 parent cfdb851 commit 75cad79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions example/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ func test(L *lua51.State) int {
return 0;
}

func test2(L *lua51.State) int {
arg := lua51.CheckInteger(L,-1);
argfrombottom := lua51.CheckInteger(L,1);
fmt.Print("test2 arg: ");
fmt.Println(arg);
fmt.Print("from bottom: ");
fmt.Println(argfrombottom);
return 0;
}

func main() {
var L *lua51.State;

Expand All @@ -23,6 +33,10 @@ func main() {
lua51.PushGoFunction(L, test);
lua51.PushGoFunction(L, test);

lua51.PushGoFunction(L, test2);
lua51.PushInteger(L,42);
lua51.Call(L,1,0);


lua51.Call(L,0,0);
lua51.Call(L,0,0);
Expand Down
2 changes: 2 additions & 0 deletions lua51/golua.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ int callback_function(lua_State* L)
{
unsigned int *fid = clua_checkgofunction(L,1);
GoInterface* gi = clua_getgostate(L);
//remove the go function from the stack (to present same behavior as lua_CFunctions)
lua_remove(L,1);
return golua_callgofunction(*gi,*fid);
}

Expand Down

0 comments on commit 75cad79

Please sign in to comment.