[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Creating nested tables from C into Lua..
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Sun, 11 Oct 2009 08:35:09 -0300
> { {name="Scooby",age=45,
> type="Dog",someusertype=<userdata>},{name="Shaggy",age=24,
> type="Human",someusertype=<userdata>}}
My lua2c, which is for Lua 4, still works on this piece of code and generates
correct C code for Lua 5.1:
/* This C code was generated by lua2c from the Lua code below.
return { {name="Scooby",age=45,
type="Dog",someusertype="userdata"},{name="Shaggy",age=24,
type="Human",someusertype="userdata"}}
*/
static int MAIN(lua_State *L)
{
lua_newtable(L);
lua_newtable(L);
lua_pushliteral(L,"name");
lua_pushliteral(L,"Scooby");
lua_pushliteral(L,"age");
lua_pushnumber(L,45);
lua_pushliteral(L,"type");
lua_pushliteral(L,"Dog");
lua_pushliteral(L,"someusertype");
lua_pushliteral(L,"userdata");
lua_settable(L,-9);
lua_settable(L,-7);
lua_settable(L,-5);
lua_settable(L,-3);
lua_newtable(L);
lua_pushliteral(L,"name");
lua_pushliteral(L,"Shaggy");
lua_pushliteral(L,"age");
lua_pushnumber(L,24);
lua_pushliteral(L,"type");
lua_pushliteral(L,"Human");
lua_pushliteral(L,"someusertype");
lua_pushliteral(L,"userdata");
lua_settable(L,-9);
lua_settable(L,-7);
lua_settable(L,-5);
lua_settable(L,-3);
lua_rawseti(L,-3,2);
lua_rawseti(L,-2,1);
return 1;
return 0;
}