Skip to content

Instantly share code, notes, and snippets.

@hoelzro
Created January 5, 2012 17:50
Show Gist options
  • Save hoelzro/1566337 to your computer and use it in GitHub Desktop.
Save hoelzro/1566337 to your computer and use it in GitHub Desktop.
return {
myfunc = function()
print 'in foo.myfunc'
end
}
#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