Hello,
I have a bit of code that does the following:
lua_pushcfunction( L, luaopen_Stuff);
lua_setglobal( L, "luaopen_Stuff");
lua_getglobal( L, "package"); // package
if( lua_istable( L, -1))
{
lua_getfield( L, -1, "preload"); // package package.preload
if( lua_istable( L, -1))
{
lua_pushcfunction( L, luaopen_Stuff); // package package.preload luaopen_Stuff
lua_setfield( L, -2, "Stuff"); // package package.preload
lua_getglobal( L, "print"); // package package.preload print
lua_setfield( L, -2, "print"); // package package.preload
}
lua_pop( L, 1); // package
}
lua_pop( L, 1); //
int r = luaL_dostring (L,
"print ('print = ', print) \n"
"print ('package.preload.print = ', package.preload.print) \n"
"print ('luaopen_Stuff = ', luaopen_Stuff) \n"
"print ('package.preload.Stuff = ', package.preload.Stuff) \n"
);
As you can see, the C function pointer for 'print' is the same whether obtained from the global 'print' or from package.preload.print. But for some reason, this is not true for my function luaopen_Stuff, which was pushed the same way both times.