Original Post
Hello, Recently, I've just started to learn about the Lua API, and I have come across a problem. My goal is to call a function "onLoad" in two loaded files. The function exists in both files. For example: =========================== Lua Code: File1.lua: Lua Code: File2.lua: C++: The problem arises when it calls only the callback in File2.lua, the first file to be loaded by the Lua API. I would like the callback to also be called in File1.lua, however, I have no idea of how to accomplish this. I theorize that a lua thread would solve this issue, but still, I would not know where to begin. Does anybody have any suggestions? [Edited by - Morbular on January 23, 2009 7:02:12 PM]
function onLoad( )
output ( "Loaded file one!" ) -- custom function
end
-- More code
function onLoad( )
output ( "Loaded file two!" ) -- custom function
end
void LoadLUA() {
lua_State* L;
L = lua_open();
luaL_openlibs(L);
lua_register(L,"output","Print");
// Load the first file
luaL_dofile(L,"File1.lua");
// Load the second file
luaL_dofile(L,"File2.lua");
// Now, call the callback
lua_getglobal(L,"onLoad");
if(!lua_isfunction(L,-1)) return;
lua_call(L,0,0);
}