I have an inquiry about the binding between lua and c languages.
lua usage example)
a[1].b.c[1].d = 1
a[1].b.c[2].d = 2
a[2].b.c[1].d = 3
a[2].b.c[2].d = 4
I am wondering how to create this with lua C api. This is the code I used in C
lua_createtable(L, 2, 0);
lua_pushnumber(L, 1);
{
lua_createtable(L, 0, 1);
{
lua_newtable(L);
lua_pushnumber(L, 1);
{
lua_pushnumber(L, 49);
lua_setfield(L, -2, "d");
lua_settable(L, -3);
}
lua_pushnumber(L, 2);
{
lua_pushstring(L, "old");
lua_setfield(L, -2, "d");
lua_settable(L, -3);
}
lua_setfield(L, -2, "c");
}
lua_setfield(L, -2, "b");
}
lua_pushnumber(L, 2);
{
lua_createtable(L, 0, 1);
{
lua_newtable(L);
lua_pushnumber(L, 1);
{
lua_pushnumber(L, 49);
lua_setfield(L, -2, "d");
lua_settable(L, -3);
}
lua_pushnumber(L, 2);
{
lua_pushstring(L, "old");
lua_setfield(L, -2, "d");
lua_settable(L, -3);
}
lua_setfield(L, -2, "c");
}
lua_setfield(L, -2, "b");
}
lua_setglobal(L, "a");
By the way PANIC: unprotected error in call to Lua API (attempt to index a number value) I got an error like this
Thank you so much for telling me this.