From d7b7e4efbca12694d844eddf8a2800e4682924d8 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 12 Jan 2011 22:05:03 +0000 Subject: [PATCH] Beginnings of a mush.objref() lua function --- game/lua/test.lua | 2 +- src/mushlua.i | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/game/lua/test.lua b/game/lua/test.lua index e493c7c..ead9be9 100644 --- a/game/lua/test.lua +++ b/game/lua/test.lua @@ -1,5 +1,5 @@ -- Test lua script file do -- testval = mush.current_state - notify(1,testval["things"]) + mush.notify(1,mush.objref(2)) end diff --git a/src/mushlua.i b/src/mushlua.i index 191aa71..0e68960 100644 --- a/src/mushlua.i +++ b/src/mushlua.i @@ -9,6 +9,46 @@ extern struct db_stat_info current_state; extern void moveit(dbref what, dbref where, int nomovemsgs); +static int mlua_objref(lua_State *L) { + int nargs; + dbref obj; + long cretime; + + nargs = lua_gettop(L); + + if (nargs < 1 || nargs > 2) { + lua_pushstring(L, "incorrect number of arguments"); + lua_error(L); + } + + if (!lua_isnumber(L, 1)) { + lua_pushstring(L, "object's dbref must be an integer"); + lua_error(L); + } + + obj = lua_tointeger(L, 1); + + if (obj < 0 || obj >= db_top || IsGarbage(obj)) { + lua_pushnil(L); + return 1; + } + + if (nargs == 2) { + if (!lua_isnumber(L, 2)) { + lua_pushstring(L, "object's creation time must be an integer"); + lua_error(L); + } + cretime = lua_tointeger(L, 2); + if (CreTime(obj) != cretime) { + lua_pushnil(L); + return 1; + } + } + + lua_pushinteger(L, obj); /* TODO: a type-safe pointer to the object */ + return 1; +} + static int mlua_notify(lua_State *L) { int nargs; dbref obj; @@ -32,7 +72,8 @@ static int mlua_notify(lua_State *L) { } %} -%native(notify) lua_CFunction mlua_notify(lua_State *L); +%native(objref) int mlua_objref(lua_State *L); +%native(notify) int mlua_notify(lua_State *L); int alias_command(const char *command, const char *alias); int alias_function(const char *function, const char *alias); void twiddle_flag_internal(const char *ns, int thing, const char *flag, int negate); -- 2.30.2