Advertisement Jump to content
Sign in to follow this  
BlackDragon777

Lua and returning a function value

This topic is 4874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!