Jump to content
  • Advertisement
Sign in to follow this  
jarruda

lua_newtable causing heap corruption?

This topic is 3881 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

I'm trying to pass a table to a function in lua, but whenever I call lua_newtable, it seems to corrupt the heap. Removing the call to lua_newtable (and changing the number of arguments passed to lua_pcall) removes the heap corruption. I'm not even putting anything in the table at this point. Here is my code, I'm praying someone can tell me something I'm obviously doing wrong:
// ... function is pushed
// ... userdata is pushed as 1st argument

lua_pushstring(L, "some string");
lua_newtable(L);

cout << "After pushing table - ";
DumpStack(L);
cout << endl;

if(lua_pcall(L, 3, 0, 0) != 0)
{
  // handle the error
}

cout << "After calling handler - ";
DumpStack(L);
cout << endl;


Output:
After pushing table - Stack dump:
1.      userdata
2.      table
3.      function
4.      userdata
5.      string [some string]
6.      table

After calling handler - Stack dump:
1.      userdata
2.      table
Note I _am_ properly handling pcall errors where I put "// handle the error", I just omitted it for clarity because that code wasn't getting hit.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!