mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 15:32:33 +00:00
* added access to id, parent, angle, damage, thrust, flags in polyobj_t
* #polyobj now returns the index id for the polyobj in PolyObjects * Polyobj_GetForNum is implemented in Lua as PolyObjects.GetForNum()
This commit is contained in:
parent
60b49b5ecd
commit
33c96ab1aa
1 changed files with 59 additions and 3 deletions
|
@ -19,9 +19,21 @@
|
||||||
|
|
||||||
enum polyobj_e {
|
enum polyobj_e {
|
||||||
polyobj_valid = 0,
|
polyobj_valid = 0,
|
||||||
|
polyobj_id,
|
||||||
|
polyobj_parent,
|
||||||
|
polyobj_angle,
|
||||||
|
polyobj_damage,
|
||||||
|
polyobj_thrust,
|
||||||
|
polyobj_flags
|
||||||
};
|
};
|
||||||
static const char *const polyobj_opt[] = {
|
static const char *const polyobj_opt[] = {
|
||||||
"valid",
|
"valid",
|
||||||
|
"id",
|
||||||
|
"parent",
|
||||||
|
"angle",
|
||||||
|
"damage",
|
||||||
|
"thrust",
|
||||||
|
"flags",
|
||||||
NULL};
|
NULL};
|
||||||
|
|
||||||
static int polyobj_get(lua_State *L)
|
static int polyobj_get(lua_State *L)
|
||||||
|
@ -42,15 +54,42 @@ static int polyobj_get(lua_State *L)
|
||||||
case polyobj_valid:
|
case polyobj_valid:
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
break;
|
break;
|
||||||
|
case polyobj_id:
|
||||||
|
lua_pushinteger(L, polyobj->id);
|
||||||
|
break;
|
||||||
|
case polyobj_parent:
|
||||||
|
lua_pushinteger(L, polyobj->parent);
|
||||||
|
break;
|
||||||
|
case polyobj_angle:
|
||||||
|
lua_pushangle(L, polyobj->angle);
|
||||||
|
break;
|
||||||
|
case polyobj_damage:
|
||||||
|
lua_pushinteger(L, polyobj->damage);
|
||||||
|
break;
|
||||||
|
case polyobj_thrust:
|
||||||
|
lua_pushfixed(L, polyobj->thrust);
|
||||||
|
break;
|
||||||
|
case polyobj_flags:
|
||||||
|
lua_pushinteger(L, polyobj->flags);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
};
|
}
|
||||||
|
|
||||||
static int polyobj_set(lua_State *L)
|
static int polyobj_set(lua_State *L)
|
||||||
{
|
{
|
||||||
return luaL_error(L, LUA_QL("polyobj_t") " struct cannot be edited by Lua."); // this is just temporary
|
return luaL_error(L, LUA_QL("polyobj_t") " struct cannot be edited by Lua."); // this is just temporary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int polyobj_num(lua_State *L)
|
||||||
|
{
|
||||||
|
polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
|
||||||
|
if (!polyobj)
|
||||||
|
return luaL_error(L, "accessed polyobj_t doesn't exist anymore.");
|
||||||
|
lua_pushinteger(L, polyobj-PolyObjects);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int lib_iteratePolyObjects(lua_State *L)
|
static int lib_iteratePolyObjects(lua_State *L)
|
||||||
{
|
{
|
||||||
INT32 i = -1;
|
INT32 i = -1;
|
||||||
|
@ -72,6 +111,17 @@ static int lib_iteratePolyObjects(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lib_PolyObject_getfornum(lua_State *L)
|
||||||
|
{
|
||||||
|
INT32 id = (INT32)luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
if (!numPolyObjects)
|
||||||
|
return 0; // if there's no PolyObjects then bail out here
|
||||||
|
|
||||||
|
LUA_PushUserdata(L, Polyobj_GetForNum(id), META_POLYOBJ);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int lib_getPolyObject(lua_State *L)
|
static int lib_getPolyObject(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *field;
|
const char *field;
|
||||||
|
@ -94,6 +144,12 @@ static int lib_getPolyObject(lua_State *L)
|
||||||
lua_pushcfunction(L, lib_iteratePolyObjects);
|
lua_pushcfunction(L, lib_iteratePolyObjects);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
// find PolyObject by ID
|
||||||
|
else if (fastcmp(field,"GetForNum")) // name could probably be better
|
||||||
|
{
|
||||||
|
lua_pushcfunction(L, lib_PolyObject_getfornum);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +168,8 @@ int LUA_PolyObjLib(lua_State *L)
|
||||||
lua_pushcfunction(L, polyobj_set);
|
lua_pushcfunction(L, polyobj_set);
|
||||||
lua_setfield(L, -2, "__newindex");
|
lua_setfield(L, -2, "__newindex");
|
||||||
|
|
||||||
//lua_pushcfunction(L, polyobj_num);
|
lua_pushcfunction(L, polyobj_num);
|
||||||
//lua_setfield(L, -2, "__len");
|
lua_setfield(L, -2, "__len");
|
||||||
lua_pop(L,1);
|
lua_pop(L,1);
|
||||||
|
|
||||||
lua_newuserdata(L, 0);
|
lua_newuserdata(L, 0);
|
||||||
|
|
Loading…
Reference in a new issue