added ag::object::getObject() helper method, stub getPosition() and setPosition() methods

git-svn-id: svn://anubis/anaglym/trunk@42 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-01 03:00:59 +00:00
parent 95c13516ef
commit 99a8835954
2 changed files with 50 additions and 10 deletions

54
ag.cc
View File

@ -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)
{
int id = lua_tointeger(L, -1);
Engine::Object * obj = g_engine->getObject(id);
Engine::Object * obj = getObject(L, -1);
if (obj != NULL)
{
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;
}
}
}

2
ag.h
View File

@ -21,6 +21,8 @@ namespace ag
namespace object
{
int draw(lua_State * L);
int setPosition(lua_State * L);
int getPosition(lua_State * L);
}
}