When parsing variables from lua, lua is acting strangely.
C++:
int LuaManager::SetTimer(lua_State *pLua)
{
if (!lua_isstring(pLua, 0)) throw "expected: string";
if (!lua_isnumber(pLua, 1)) throw "expected: number";
std::string callback = lua_tostring(pLua, 0);
double delay = lua_tonumber(pLua, 1);
Timer timer = Timer(callback, delay);
return 0;
}
lua:
SetTimer("Durp", 10);
I get a "First-chance exception at 0x76C44598: Microsoft C++ exception: char at memory location 0x00D7F588" from the line
std::string callback = lua_tostring(pLua, 0);
When I debug the code and press continue when the exception pops up it throws random variables into the variable. The same goes for the double delay
.
However when I say:
std::string callback = lua_tostring(pLua, -2);
double delay = lua_tonumber(pLua, -1);
It will still give the exception but the correct variables are thrown in.