lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Recently ran into this issue, and it's prevented me from continuing development on my engine.

Let's say I do this in a script:

x = 3

And in C/C++, I do this to retrieve the value:

lua_getglobal(m_luaState, "x")
g_console->WriteLine("x: %d", lua_tonumber(m_luaState, -1));

The output is then this:

x: -16

The problem seems to be using lua_tonumber. If I use lua_tointeger, the correct value is returned. However, I use tolua++ to give Lua access to some of my C/C++ types, and I'm encountering this issue with these usertypes. I believe this is because tolua uses lua_tonumber underneath.

Why is lua_tonumber behaving this way (i.e., returning seemingly random values)?

Thanks,

Eddie Ringle