A

Size: a a a
A
S
local file = io.open(filename, "rb")
local data = file:read("*all")
file:close()
A
S
lua_newtable(L); // tbl1
lua_pushstring(L, "foo"); // tbl1, "foo"
lua_newtable(L); // tbl1, "foo", tbl2
lua_pushnumber(L, 1); // ..., tbl2, 1
lua_pushstring("bla"); // ..., tbl2, 1, "bla"
lua_rawset(L, -3); // tbl2[1] = "bla"
lua_rawset(L, -3); tbl1["foo"] = tbl2
lua_rawset(L, tbl_index)
— присобачивает к таблице на tbl_index
элементу, -2 элемент как ключ, и -1 как значение.S
S
lua_newtable(L);
lua_pushnumber(L, 1);
lua_newtable(L);
lua_rawset(L, -3); // tbl1[1] = tbl2
lua_pushnumber(L, 2);
lua_newtable(L);
lua_rawset(L, -3); // tbl1[2] = tbl3
S
lua_newtable(L);
lua_pushstring(L, "tbl1"); ключ
lua_newtable(L); таблица-значение
lua_pushstring(L, "a"); ключ
lua_pushnumber(L, 1); значение
lua_rawset(L, -3);
lua_rawset(L, -3);
lua_pushstring(L, "tbl2");
lua_newtable(L);
lua_pushstring(L, "b");
lua_pushnumber(L, 2);
lua_rawset(L, -3);
lua_rawset(L, -3);
S
lua_pushcfunction
как значение.S
S
S
int lua_foo(lua_State * L){
float a = luaL_checknumber(L, 1);
float b = luaL_checknumber(L, 2);
lua_pushnumber(L, a + b);
return 1;
}
...
lua_newtable(L);
lua_pushstring(L, "summ"); //tbl.summ = lua_foo
lua_pushcfunction(L, lua_foo);
lua_rawset(L, -3);
O
int lua_foo(lua_State * L){
float a = luaL_checknumber(L, 1);
float b = luaL_checknumber(L, 2);
lua_pushnumber(L, a + b);
return 1;
}
...
lua_newtable(L);
lua_pushstring(L, "summ"); //tbl.summ = lua_foo
lua_pushcfunction(L, lua_foo);
lua_rawset(L, -3);