[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua_call / lua_pcall inside a C Function - help!
- From: "Jeff" <jeff@...>
- Date: Thu, 4 Sep 2003 17:21:44 +0100
Hi all,
I'm using Lua 5.0, and have compiled the Lua code into my own project.
I've copied this function from a Lua tutorial somewhere, but lua_pcall (or
lua_call) refuses to work:
int luaadd ( int x, int y )
{
int sum;
/* the function name */
lua_getglobal(L, "add");
/* the first argument */
lua_pushnumber(L, x);
/* the second argument */
lua_pushnumber(L, y);
/* call the function with 2
arguments, return 1 result */
lua_pcall(L, 2, 1, 0);
/* get the result */
sum = (int)lua_tonumber(L, 1);
lua_pop(L, 1);
return sum;
}
When I get to lua_pcall, it basically falls over saying: attempt to call a
nil value. I get this in every instance I try to use lua_call or lua_pcall,
does anyone know why?
Thanks in advance,
Jeff.