c++ - Lua module pushing C functions from DllMain -


i've got damn big problem. know lua allows making modules , can load these modules require() function 5.1(previously loadlib).

#define lua extern "c" __declspec(dllexport) int __cdecl  static int l_testfunc(lua_state * l)  {      lua_pushboolean (l, 1); // return true      return 1; }  lua luaopen_mymodule(lua_state *l) {      printf("test2");     lua_pushcfunction(l, l_testfunc);     lua_setglobal(l, "testfunc");      return 1; } 

so in lua using require("mymodule") , works.(luaopen_* entry point then)

but need use standard way(dllmain entry point). tried didn't work. got ideas?

but need use standard way(dllmain entry point). tried didn't work. got ideas?

dllmain going entry point (if defined), can't use load functions because you have no lua state load them there.

when run "require" in lua code, app executing code (e.g. lua.exe) load dll (invoking dllmain), call luaopen_mymodule passing in lua state executed require statement. there's no way dllmain have access state pointer...


...well, no ordinary way. could work out host apps writes memory location of lua state external location accessible dll (registry, file, etc.) before loading dll. dllmain fetch pointer register , it's functions state. not sure why you'd want that, in language c it's technically possible.

this require wrote host, arrange write state somewhere. or have separate module, loaded ordinary way, writes lua_state value, other modules access dllmains.


this smells lot xy problem. care share why want register functions in dllmain?


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -