lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Am 13.06.2011 22:30, schrieb Marc Balmer:
Am 13.06.2011 20:53, schrieb Gabriel Lassonde:
This question was probably answered before but I ran into a problem
trying to push many lua values from a c function.

This is a small application that shows the problem.

extern "C"
#include "lua-5.1.4/src/lua.h"
#include "lua-5.1.4/src/lauxlib.h"

void main()
lua_State * state = luaL_newstate();

for(size_t i = 0; i< 50; ++i)
//lua_checkstack(state, 1); // Uncommenting this "fixes" the problem.
lua_pushnumber(state, 7.0);


Upon "lua_close" the program crash (Heap corruption).

I am compiling under windows.

Can anyone help me understand what the problem is?

iirc, the "standard" Lua stack has a depth of 20. You are using 50
entries. You should ensure you have enough space by calling lua_settop.

... checkstack()


Thank you,


Consider joining the Lua Workshop in Switzerland,