filled out ag::pickObjects()

git-svn-id: svn://anubis/anaglym/trunk@254 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-02-21 21:41:52 +00:00
parent 09c46c6799
commit b2feea1324
2 changed files with 44 additions and 2 deletions

45
ag.cc
View File

@ -88,9 +88,34 @@ namespace ag
int argc = lua_gettop(L);
if (argc == 2 && lua_isnumber(L, 1) && lua_isnumber(L, 2))
{
g_engine->pickObjects(lua_tointeger(L, 1), lua_tointeger(L, 2));
lua_newtable(L);
int next_index = 1;
refptr< vector<int> > objects =
g_engine->pickObjects(lua_tointeger(L, 1), lua_tointeger(L, 2));
for (vector<int>::const_iterator it = objects->begin();
it != objects->end();
it++)
{
lua_getfield(L, LUA_GLOBALSINDEX, "ag"); /* pushes 1 */
lua_getfield(L, -1, "_objects"); /* pushes 1 */
lua_pushinteger(L, *it); /* pushes 1 */
lua_gettable(L, -2); /* replace top */
lua_remove(L, -2); /* remove 1 */
lua_remove(L, -1); /* remove 1 */
if (!lua_isnil(L, -1))
{
lua_pushinteger(L, next_index++); /* push key */
lua_pushvalue(L, -2); /* push value */
lua_settable(L, argc + 1); /* pop 2 */
}
lua_pop(L, 1); /* pop 1 */
}
}
return 0;
else
{
lua_pushnil(L);
}
return 1;
}
static void print_val(lua_State * L, int index)
@ -270,6 +295,14 @@ namespace ag
lua_setfield(L, -2, "getAABB");
lua_pushcfunction(L, object::getSize);
lua_setfield(L, -2, "getSize");
/* ag._objects[id] = obj */
lua_getfield(L, LUA_GLOBALSINDEX, "ag"); /* pushes 1 */
lua_getfield(L, -1, "_objects"); /* pushes 1 */
lua_pushinteger(L, id); /* pushes 1 */
lua_pushvalue(L, 1); /* pushes 1 */
lua_settable(L, -3); /* pops 2 */
lua_pop(L, 2); /* pops 2 */
}
static void createLuaAMotor(lua_State * L, int id)
@ -1093,6 +1126,14 @@ namespace ag
{
int id = lua_tointeger(L, -1);
g_engine->removeObject(id);
/* ag._objects[id] = nil */
lua_getfield(L, LUA_GLOBALSINDEX, "ag"); /* pushes 1 */
lua_getfield(L, -1, "_objects"); /* pushes 1 */
lua_pushinteger(L, id); /* pushes 1 */
lua_pushnil(L); /* pushes 1 */
lua_settable(L, -3); /* pops 2 */
lua_pop(L, 2); /* pops 2 */
}
lua_pop(L, 1);
clearLuaTable(L, 1);

1
ag.lua
View File

@ -1,5 +1,6 @@
next = ag.next
type = ag.type
ag._objects = {}
pairs = function(table)
return next, table, nil