So I've been working on creating my lua script class interface, and I ran into an interesting crash-inducing problem.
lua_State* SCRIPT::runInit()
{
log->debugData("Running init function");
lua_getglobal(L, "init");
int er = lua_pcall(L, 0, 0, 0);
if(er != 0)
{
log->logData("Pcall error", er);
log->logData("Failed to run init function", lua_tostring(L, -1));
return L;
}
log->debugData("Ran init function");
return L;
}
When I run this, it should call the "init" function. If it succeeds, er should equal 0, thus bypassing the if statement and going right to "log->debugData("Ran init function");"
Here's the init function in the lua file:
function init()
MainScene:SLog("Init DOES in fact exist...")
MainScene:addMesh("sibenik/sibenik.obj", 0, 0, 0, 0, 0, 0, 1, 1, 1)
end
However, when I DO run this, here's the output directly from the log file:
DEBUG: Running init function
Init DOES in fact exist...
Loading mesh : sibenik/sibenik.obj
DEBUG: Loaded mesh
Pcall error : 0
Then it errors on the second log->logData() due to the empty lua_tostring(L, -1).
Note that the Pcall error is returning 0... This means that it shouldn't have gone into the if statement at all, however, it does anyway...
Is it a problem with my compiler?