1

how to create nested tables? My approach sadly does not work. I thought that lua_newtable pushes a new table on the stack and if I do lua_settable that should set key value pair, but I was mistaken apparently.

/* 
 * local transform = GetTransform()
 * print("Translation: " .. transform.Translation.x)
 */

lua_newtable(L);
int index = lua_gettop(L);
lua_pushstring(L, "Translation");
{
    lua_newtable(L); // Table inside table

    lua_pushstring(L, "x");
    lua_pushvalue(L, 0);
    lua_settable(L, -3);

    lua_pushstring(L, "y");
    lua_pushvalue(L, 0);
    lua_settable(L, -3);

    lua_pushstring(L, "z");
    lua_pushvalue(L, 0);
    lua_settable(L, -3);
}
lua_settable(L, index);
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
ezyn
  • 11
  • 3

1 Answers1

0

Nevermind, I woke up and noticed that I used lua_pushvalue instead of lua_pushnumber.
Thanks for help :D

ezyn
  • 11
  • 3