i'm trying make nested table in lua. when nest past 16 levels program crashes.
in example program below, when change depth 16 instead of 17 program not crash. can't find resources there maximum table depth, , 1 low seems odd. crash within call lua_close().
am misunderstanding how build table in lua using c api, or there in fact maximum depth?
#include <assert.h> #include "lua.h" #include "lauxlib.h" #include "lualib.h" #define depth 17 int main(int argc, char* argv[]) { lua_state *l = null; size_t = 0; l = lual_newstate(); assert(null!=l); lual_openlibs(l); // create root table lua_newtable(l); // push depth levels deep onto table (i=0; i<depth; i++) { lua_pushstring(l, "subtable"); lua_newtable(l); } // nest depth levels (i=0; i<depth; i++) { lua_settable(l, -3); } lua_close(l); return 0; }
you need increase stack lua_checkstack
or lual_checkstack
allow 2*depth
slots.
Comments
Post a Comment