From 99a88359542e91da926efc6acd3e0142790d75a8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 1 Oct 2009 03:00:59 +0000 Subject: [PATCH] added ag::object::getObject() helper method, stub getPosition() and setPosition() methods git-svn-id: svn://anubis/anaglym/trunk@42 99a6e188-d820-4881-8870-2d33a10e2619 --- ag.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---------- ag.h | 2 ++ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/ag.cc b/ag.cc index 50af69d..b3c9a59 100644 --- a/ag.cc +++ b/ag.cc @@ -125,7 +125,11 @@ namespace ag lua_setfield(L, -2, "draw"); if (physpath != "") { - g_engine->getObject(id)->loadPhy(physpath); + Engine::Object * obj = g_engine->getObject(id); + if (obj != NULL) + { + obj->loadPhy(physpath); + } } return 1; } @@ -197,24 +201,58 @@ namespace ag namespace object { + static Engine::Object * getObject(lua_State * L, int index) + { + Engine::Object * ret = NULL; + + lua_getfield(L, index, "id"); + if (lua_type(L, -1) == LUA_TNUMBER) + { + int id = lua_tointeger(L, -1); + ret = g_engine->getObject(id); + } + lua_pop(L, 1); + + return ret; + } + int draw(lua_State * L) { int argc = lua_gettop(L); if (argc == 1 && lua_type(L, -1) == LUA_TTABLE) { - lua_getfield(L, -1, "id"); - if (lua_type(L, -1) == LUA_TNUMBER) + Engine::Object * obj = getObject(L, -1); + if (obj != NULL) { - int id = lua_tointeger(L, -1); - Engine::Object * obj = g_engine->getObject(id); - if (obj != NULL) - { - obj->draw(); - } + obj->draw(); } - lua_pop(L, 1); } return 0; } + + int setPosition(lua_State * L) + { + int argc = lua_gettop(L); + + if (argc == 4) + { + double position[3]; + for (int i = 0; i < 3; i++) + { + int type = lua_type(L, i); + if (type == LUA_TNUMBER || type == LUA_TSTRING) + { + position[i] = lua_tonumber(L, i + 2); + } + } + } + + return 0; + } + + int getPosition(lua_State * L) + { + return 3; + } } } diff --git a/ag.h b/ag.h index e146cd9..fd62469 100644 --- a/ag.h +++ b/ag.h @@ -21,6 +21,8 @@ namespace ag namespace object { int draw(lua_State * L); + int setPosition(lua_State * L); + int getPosition(lua_State * L); } }