Created
January 5, 2012 17:50
-
-
Save hoelzro/1566337 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return { | |
myfunc = function() | |
print 'in foo.myfunc' | |
end | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <lua.h> | |
#include <lauxlib.h> | |
#include <stdio.h> | |
static int test_func(lua_State *L) | |
{ | |
printf("calling test func\n"); | |
lua_getfield(L, lua_upvalueindex(1), "myfunc"); // foo.myfunc | |
lua_call(L, 0, 0); | |
return 0; | |
} | |
int luaopen_test(lua_State *L) | |
{ | |
lua_getglobal(L, "require"); | |
lua_pushliteral(L, "foo"); | |
lua_call(L, 1, 1); | |
lua_newtable(L); | |
lua_pushvalue(L, -2); | |
lua_pushcclosure(L, test_func, 1); | |
lua_setfield(L, -2, "test_func"); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment