added next() and pairs() top-level Lua functions for traversing tables easily
git-svn-id: svn://anubis/anaglym/trunk@226 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
a7a21a6370
commit
c4f6310c2d
40
ag.cc
40
ag.cc
@ -45,6 +45,7 @@ namespace ag
|
||||
{ "loadModel", loadModel },
|
||||
{ "loadModelStatic", loadModelStatic },
|
||||
{ "loadTexture", loadTexture },
|
||||
{ "next", next },
|
||||
{ "print", print },
|
||||
{ "println", println },
|
||||
{ "registerEventHandler", registerEventHandler },
|
||||
@ -73,6 +74,18 @@ namespace ag
|
||||
{ NULL, NULL }
|
||||
};
|
||||
luaL_register(L, "ag", functions);
|
||||
|
||||
luaL_loadstring(L,
|
||||
"next = ag.next\n"
|
||||
|
||||
"pairs = function(table)\n"
|
||||
" return next, table, nil\n"
|
||||
"end\n"
|
||||
|
||||
"ag.createAMotor = function()\n"
|
||||
"end\n"
|
||||
);
|
||||
int s = lua_pcall(L, 0, 0, 0);
|
||||
}
|
||||
|
||||
static void print_val(lua_State * L, int index)
|
||||
@ -139,6 +152,33 @@ namespace ag
|
||||
return ret;
|
||||
}
|
||||
|
||||
int next(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 || argc == 2)
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pushvalue(L, 2);
|
||||
}
|
||||
if (lua_next(L, 1) == 0)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void createLuaObject(lua_State * L, int id)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
Loading…
x
Reference in New Issue
Block a user