added ag::pickOne()
git-svn-id: svn://anubis/anaglym/trunk@310 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
a43935fdd6
commit
bfb0760ef1
72
ag.cc
72
ag.cc
@ -55,6 +55,7 @@ namespace ag
|
|||||||
{ "loadTexture", loadTexture },
|
{ "loadTexture", loadTexture },
|
||||||
{ "next", next },
|
{ "next", next },
|
||||||
{ "pickObjects", pickObjects },
|
{ "pickObjects", pickObjects },
|
||||||
|
{ "pickOne", pickOne },
|
||||||
{ "print", print },
|
{ "print", print },
|
||||||
{ "println", println },
|
{ "println", println },
|
||||||
{ "registerEventHandler", registerEventHandler },
|
{ "registerEventHandler", registerEventHandler },
|
||||||
@ -93,8 +94,11 @@ namespace ag
|
|||||||
int pickObjects(lua_State * L)
|
int pickObjects(lua_State * L)
|
||||||
{
|
{
|
||||||
int argc = lua_gettop(L);
|
int argc = lua_gettop(L);
|
||||||
if (argc == 2 && lua_isnumber(L, 1) && lua_isnumber(L, 2))
|
if (!(argc == 2 && lua_isnumber(L, 1) && lua_isnumber(L, 2)))
|
||||||
{
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int next_index = 1;
|
int next_index = 1;
|
||||||
refptr< vector<Engine::PickedObjectRef> > objects =
|
refptr< vector<Engine::PickedObjectRef> > objects =
|
||||||
@ -110,12 +114,11 @@ namespace ag
|
|||||||
lua_gettable(L, -2); /* {ag,_objects,obj} */
|
lua_gettable(L, -2); /* {ag,_objects,obj} */
|
||||||
lua_remove(L, -3); /* {_objects,obj} */
|
lua_remove(L, -3); /* {_objects,obj} */
|
||||||
lua_remove(L, -2); /* {obj} */
|
lua_remove(L, -2); /* {obj} */
|
||||||
if (!lua_isnil(L, -1))
|
|
||||||
{
|
|
||||||
lua_pushinteger(L, next_index++); /* {obj,index} */
|
lua_pushinteger(L, next_index++); /* {obj,index} */
|
||||||
lua_pushvalue(L, -2); /* {obj,index,obj} */
|
lua_pushvalue(L, -2); /* {obj,index,obj} */
|
||||||
lua_settable(L, argc + 1); /* {obj} */
|
lua_settable(L, argc + 1); /* {obj} */
|
||||||
}
|
|
||||||
lua_pushstring(L, "pick_dist"); /* {obj,"pick_dist"} */
|
lua_pushstring(L, "pick_dist"); /* {obj,"pick_dist"} */
|
||||||
lua_pushnumber(L, (*it)->dist); /* {obj,"pick_dist",dist} */
|
lua_pushnumber(L, (*it)->dist); /* {obj,"pick_dist",dist} */
|
||||||
lua_settable(L, -3); /* {obj} */
|
lua_settable(L, -3); /* {obj} */
|
||||||
@ -123,7 +126,7 @@ namespace ag
|
|||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, i + 1); /* {obj,arr,index} */
|
lua_pushinteger(L, i + 1); /* {obj,arr,index} */
|
||||||
lua_pushnumber(L, (*it)->pos[i]);/* {obj,arr,index,pos_x} */
|
lua_pushnumber(L, (*it)->pos[i]); /* {obj,arr,index,pos_x} */
|
||||||
lua_settable(L, -3); /* {obj,arr} */
|
lua_settable(L, -3); /* {obj,arr} */
|
||||||
}
|
}
|
||||||
lua_pushstring(L, "pick_pos"); /* {obj,arr,"pick_pos"} */
|
lua_pushstring(L, "pick_pos"); /* {obj,arr,"pick_pos"} */
|
||||||
@ -143,11 +146,66 @@ namespace ag
|
|||||||
lua_pop(L, 1); /* {obj} */
|
lua_pop(L, 1); /* {obj} */
|
||||||
lua_pop(L, 1); /* {} */
|
lua_pop(L, 1); /* {} */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
int pickOne(lua_State * L)
|
||||||
{
|
{
|
||||||
lua_pushnil(L);
|
int argc = lua_gettop(L);
|
||||||
|
Engine::Object *obj;
|
||||||
|
Engine::PickedObjectRef por;
|
||||||
|
|
||||||
|
if (!(argc == 3
|
||||||
|
&& lua_isnumber(L, 1)
|
||||||
|
&& lua_isnumber(L, 2)
|
||||||
|
&& lua_istable(L, 3)))
|
||||||
|
goto fail;
|
||||||
|
obj = object::getObject(L, 3);
|
||||||
|
if (obj == NULL)
|
||||||
|
goto fail;
|
||||||
|
por = g_engine->pickOne(lua_tointeger(L, 1), lua_tointeger(L, 2), obj);
|
||||||
|
if (por.isNull())
|
||||||
|
goto fail;
|
||||||
|
lua_getfield(L, LUA_GLOBALSINDEX, "ag");/* {ag} */
|
||||||
|
lua_getfield(L, -1, "_objects"); /* {ag,_objects} */
|
||||||
|
lua_pushinteger(L, por->id); /* {ag,_objects,id} */
|
||||||
|
lua_gettable(L, -2); /* {ag,_objects,obj} */
|
||||||
|
lua_remove(L, -3); /* {_objects,obj} */
|
||||||
|
lua_remove(L, -2); /* {obj} */
|
||||||
|
|
||||||
|
lua_pushstring(L, "pick_dist"); /* {obj,"pick_dist"} */
|
||||||
|
lua_pushnumber(L, por->dist); /* {obj,"pick_dist",dist} */
|
||||||
|
lua_settable(L, -3); /* {obj} */
|
||||||
|
lua_createtable(L, 3, 0); /* {obj,arr} */
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, i + 1); /* {obj,arr,index} */
|
||||||
|
lua_pushnumber(L, por->pos[i]); /* {obj,arr,index,pos_x} */
|
||||||
|
lua_settable(L, -3); /* {obj,arr} */
|
||||||
}
|
}
|
||||||
|
lua_pushstring(L, "pick_pos"); /* {obj,arr,"pick_pos"} */
|
||||||
|
lua_pushvalue(L, -2); /* {obj,arr,"pick_pos",arr} */
|
||||||
|
lua_settable(L, -4); /* {obj,arr} */
|
||||||
|
lua_pop(L, 1); /* {obj} */
|
||||||
|
lua_createtable(L, 3, 0); /* {obj,arr} */
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, i + 1); /* {obj,arr,index} */
|
||||||
|
lua_pushnumber(L, por->normal[i]); /* {obj,arr,index,n} */
|
||||||
|
lua_settable(L, -3); /* {obj,arr} */
|
||||||
|
}
|
||||||
|
lua_pushstring(L, "pick_normal"); /* {obj,arr,"pick_normal"} */
|
||||||
|
lua_pushvalue(L, -2); /* {obj,arr,"pick_normal",arr} */
|
||||||
|
lua_settable(L, -4); /* {obj,arr} */
|
||||||
|
lua_pop(L, 1); /* {obj} */
|
||||||
|
lua_pop(L, 1); /* {} */
|
||||||
|
|
||||||
|
lua_pushboolean(L, true);
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
lua_pushboolean(L, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
ag.h
1
ag.h
@ -30,6 +30,7 @@ namespace ag
|
|||||||
int loadTexture(lua_State * L);
|
int loadTexture(lua_State * L);
|
||||||
int next(lua_State * L);
|
int next(lua_State * L);
|
||||||
int pickObjects(lua_State * L);
|
int pickObjects(lua_State * L);
|
||||||
|
int pickOne(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