1

When I'm trying to add 100 tables in Lua c stack, I receive segfault on function end.

Code example:

lua_example.c: http://pastebin.com/GFvLwMY2

Makefile: http://pastebin.com/3EWJiVz7

test.lua: http://pastebin.com/1y22XvzK

Maybe I'm doing it wrong? What setting I should increase to be able to add 100 tables?

local variables limit is 200 by default, registers limit is 254, so I don't get it.

static int lua_example_test( lua_State *L ) {
    for ( int i=0; i<100; i++ ) {
        lua_newtable(L);
    }
    return 100;
}

I've tried lua-5.2.4 and lua-5.3.2, problem occurs in both of them.

marsgpl
  • 552
  • 2
  • 12
  • 1
    See http://www.lua.org/manual/5.3/manual.html#4.2. Instead of `lua_checkstack()`, you often want the variant that raises an error: [`luaL_checkstack()`](http://www.lua.org/manual/5.3/manual.html#luaL_checkstack). – siffiejoe Apr 10 '16 at 17:52
  • 1
    Did you invoke `luaL_checkstack` to make sure Lua C API stack is large enough to store 100 items? – Egor Skriptunoff Apr 10 '16 at 17:53
  • @siffiejoe, Egor Skriptunoff, thanks! After wrapping in lua_checkstack, all works perfectly even with 1000+ tables, it grows the stack, didn't know about it. – marsgpl Apr 10 '16 at 18:45

0 Answers0