Lua doesnt pass numbers back?
I've just integrated Lua with a c++ app I'm developing for PDAs, but whenever a lua script tries to return a numeral, on the c++ side of things, all I get is zero, every time.
On the other hand I can receive strings with no problem whatsoever...
Does any know where under the hood I should look to fix this?
Hi,
Can you give us the version # of Lua you're using, any wrapper you're using, etc...?
After executing your function call, what do you call to retrieve your numeral?
Do you call lua_tointeger or lua_tonumber (double) right after your function call?
Cheers
Can you give us the version # of Lua you're using, any wrapper you're using, etc...?
After executing your function call, what do you call to retrieve your numeral?
Do you call lua_tointeger or lua_tonumber (double) right after your function call?
Cheers
From lua.h:
I just do a simple:
Quote:#define LUA_VERSION "Lua 5.0"
#define LUA_COPYRIGHT "Copyright (C) 1994-2003 Tecgraf, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
I just do a simple:
Quote:
if(lua_isnumber(L, 1))
{
int v = lua_tonumber(L, 1);
}
lua_tonumber() returns a double but you're storing it to an int; is the number you're returning from the Lua script less than one? It'd be a silly mistake, true, but that's the only thing that stands out to me from that little example.
If not, post more code (C-side and Lua).
If not, post more code (C-side and Lua).
Things that pop up in my mind... as jpetrie pointed out you store a double in an int.
If that's a real copy paste of your code, are you sure the right variable gets assigned? as you seem to declare an int v then exit this scope... is that "int" a mistake?
If you're using VC++, what does the Auto tab read as a return value to lua_tonumber after you've stepped over it?
Hope this helps
Eric
If that's a real copy paste of your code, are you sure the right variable gets assigned? as you seem to declare an int v then exit this scope... is that "int" a mistake?
If you're using VC++, what does the Auto tab read as a return value to lua_tonumber after you've stepped over it?
Hope this helps
Eric
Are you defining your function as something like:
If so are you calling it via:
There are some good intro LUA tutorials at gamedevgeek.com.
Hope that helps!
function add(firstNumber, secondNumber) return firstNumber + secondNumber;end
If so are you calling it via:
lua_getglobal(LuaStatePtr, "add");lua_pushnumber(LuaStatePtr, firstNumber);lua_pushnumber(LuaStatePtr, secondNumber);lua_call(LuaStatePtr, 2 /*2 arguments*/, 1 /*1 return value*/);int nSum = (int)lua_tointeger(LuaStatePtr, -1);
There are some good intro LUA tutorials at gamedevgeek.com.
Hope that helps!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement