Lua and returning a function value

Started by
3 comments, last by BlackDragon777 18 years, 7 months ago
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
Advertisement
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.
So should I put lua_call(L,0,1); in front of that function? That doesn't work for me...
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.
Thanks! That did the trick! ;)

-- Brandon Fogerty


GOD Bless you Always!!!!!

This topic is closed to new replies.

Advertisement