Lua で深くネストされたテーブルを作成しようとしています。16 レベルを超えてネストすると、プログラムがクラッシュします。
以下のサンプル プログラムでは、DEPTH を 17 ではなく 16 に変更しても、プログラムはクラッシュしません。テーブルの最大の深さがあると言っているリソースを見つけることができず、非常に低いものは奇妙に思えます。クラッシュは lua_close() の呼び出し内にあります。
C API を使用して Lua でテーブルを作成する方法を誤解していますか、それとも実際には最大深度がありますか?
#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 i = 0;
L = luaL_newstate();
assert(NULL!=L);
luaL_openlibs(L);
// create the root table
lua_newtable(L);
// push DEPTH levels deep onto the table
for (i=0; i<DEPTH; i++)
{
lua_pushstring(L, "subtable");
lua_newtable(L);
}
// nest the DEPTH levels
for (i=0; i<DEPTH; i++)
{
lua_settable(L, -3);
}
lua_close(L);
return 0;
}