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 },
|
{ "loadModel", loadModel },
|
||||||
{ "loadModelStatic", loadModelStatic },
|
{ "loadModelStatic", loadModelStatic },
|
||||||
{ "loadTexture", loadTexture },
|
{ "loadTexture", loadTexture },
|
||||||
|
{ "next", next },
|
||||||
{ "print", print },
|
{ "print", print },
|
||||||
{ "println", println },
|
{ "println", println },
|
||||||
{ "registerEventHandler", registerEventHandler },
|
{ "registerEventHandler", registerEventHandler },
|
||||||
@ -73,6 +74,18 @@ namespace ag
|
|||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
luaL_register(L, "ag", functions);
|
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)
|
static void print_val(lua_State * L, int index)
|
||||||
@ -139,6 +152,33 @@ namespace ag
|
|||||||
return ret;
|
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)
|
static void createLuaObject(lua_State * L, int id)
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
1
ag.h
1
ag.h
@ -24,6 +24,7 @@ namespace ag
|
|||||||
int loadModel(lua_State * L);
|
int loadModel(lua_State * L);
|
||||||
int loadModelStatic(lua_State * L);
|
int loadModelStatic(lua_State * L);
|
||||||
int loadTexture(lua_State * L);
|
int loadTexture(lua_State * L);
|
||||||
|
int next(lua_State * L);
|
||||||
int print(lua_State * L);
|
int print(lua_State * L);
|
||||||
int println(lua_State * L);
|
int println(lua_State * L);
|
||||||
int registerEventHandler(lua_State * L);
|
int registerEventHandler(lua_State * L);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user