I have a C++ dll application that is called from a Lua environment embedded in an executable. I need the dll "main" thread to spawn a thread to do it's thing, and let the main thread die to keep executing the Lua script that launched the dll. If I use join() the main thread doesn't return to Lua, if I don't the main thread terminates and kills the son. Is it even possible? Thanks for helping this noob :)
EDIT: Looks like detach() is what I'm looking for
void startThread() {
initCommunication();
}
extern "C" __declspec(dllexport) int luaopen_myDLL(lua_State *L){
// register Lua functions
static const luaL_Reg functs [] = {
{"registerOffsetMap", cpp_registerOffsetMap},
{"registerLuaFile", cpp_registerLuaFile},
...
{NULL,NULL}
};
luaL_register(L,"myDLL", functs);
LuaGlobal = L;
if (active) {
return 0;
}
// run installed modules
...
boost::thread thrd(startThread);
thrd.detach();
return 0;
}
A Lua script calls require "myDLL" and runs the function luaopen_myDLL. That registers some functions in the dll so I can call them from Lua, and then should run the initComunication() function on it's own thread so the original Lua script can keep running.
Detach doesn't seem to work.