Sign in to follow this  

lua_newtable causing heap corruption?

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

This topic is 3671 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this