Added new functions as variables of polyobj_t:

* po.pointInside(po, x, y) as a wrapper for P_PointInsidePolyobj
* po.mobjTouching(po, mo) as a wrapper for P_MobjTouchingPolyobj
* po.mobjInside(po, mo) as a wrapper for P_MobjInsidePolyobj

I can confirm that ":" syntax works with all the above, e.g. po:mobjInside(mo)
This commit is contained in:
Monster Iestyn 2020-09-09 18:09:32 +01:00
parent 5f91833701
commit f86dad2979
1 changed files with 60 additions and 1 deletions

View File

@ -18,6 +18,7 @@
#include "lua_libs.h"
enum polyobj_e {
// properties
polyobj_valid = 0,
polyobj_id,
polyobj_parent,
@ -27,9 +28,14 @@ enum polyobj_e {
polyobj_thrust,
polyobj_flags,
polyobj_translucency,
polyobj_triggertag
polyobj_triggertag,
// special functions
polyobj_pointInside,
polyobj_mobjTouching,
polyobj_mobjInside
};
static const char *const polyobj_opt[] = {
// properties
"valid",
"id",
"parent",
@ -40,8 +46,50 @@ static const char *const polyobj_opt[] = {
"flags",
"translucency",
"triggertag",
// special functions
"pointInside",
"mobjTouching",
"mobjInside",
NULL};
static int lib_polyobj_PointInside(lua_State *L)
{
polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
fixed_t x = luaL_checkfixed(L, 2);
fixed_t y = luaL_checkfixed(L, 3);
INLEVEL
if (!po)
return LUA_ErrInvalid(L, "polyobj_t");
lua_pushboolean(L, P_PointInsidePolyobj(po, x, y));
return 1;
}
static int lib_polyobj_MobjTouching(lua_State *L)
{
polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ));
INLEVEL
if (!po)
return LUA_ErrInvalid(L, "polyobj_t");
if (!mo)
return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_MobjTouchingPolyobj(po, mo));
return 1;
}
static int lib_polyobj_MobjInside(lua_State *L)
{
polyobj_t *po = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ));
INLEVEL
if (!po)
return LUA_ErrInvalid(L, "polyobj_t");
if (!mo)
return LUA_ErrInvalid(L, "mobj_t");
lua_pushboolean(L, P_MobjInsidePolyobj(po, mo));
return 1;
}
static int polyobj_get(lua_State *L)
{
polyobj_t *polyobj = *((polyobj_t **)luaL_checkudata(L, 1, META_POLYOBJ));
@ -57,6 +105,7 @@ static int polyobj_get(lua_State *L)
switch (field)
{
// properties
case polyobj_valid:
lua_pushboolean(L, true);
break;
@ -87,6 +136,16 @@ static int polyobj_get(lua_State *L)
case polyobj_triggertag:
lua_pushinteger(L, polyobj->triggertag);
break;
// special functions
case polyobj_pointInside:
lua_pushcfunction(L, lib_polyobj_PointInside);
break;
case polyobj_mobjTouching:
lua_pushcfunction(L, lib_polyobj_MobjTouching);
break;
case polyobj_mobjInside:
lua_pushcfunction(L, lib_polyobj_MobjInside);
break;
}
return 1;
}