Lua and returning a function value
In C++, I wrote a test function like this
int Test(lua_State *L)
{
lua_pushnumber(L,1);
return 0;
}
However when I write the following code in Lua,
done = 0;
a = 0;
while done == 0 do
a = Test();
if a == 1 then
done = 1;
end
io.write("Blah ");
end
this loop repeats forever. All I want to do is have the Test() function return 1. What am I doing wrong?
Thanks in advance!
-- Brandon
A C function which is registered as a Lua function should indicate in its return value how many results it is returning on the stack. By returning 0, you indicate no return values; a is thus set to nil.
Quote:Original post by BlackDragon777
So should I put lua_call(L,0,1); in front of that function? That doesn't work for me...
I think he meant you should return 1, not 0.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement