diff --git a/include/extern.h b/include/extern.h index 4c757b4b3..7d6ad328c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1676,6 +1676,7 @@ E int FDECL(l_selection_register, (lua_State *)); /* ### nhlobj.c ### */ #if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET) E void FDECL(nhl_push_obj, (lua_State *, struct obj *)); +E int FDECL(nhl_obj_u_giveobj, (lua_State *)); E int FDECL(l_obj_register, (lua_State *)); #endif diff --git a/src/nhlobj.c b/src/nhlobj.c index 44fcc32f5..1b5f7d82b 100644 --- a/src/nhlobj.c +++ b/src/nhlobj.c @@ -136,6 +136,32 @@ lua_State *L; return 0; } +/* Put object into player's inventory */ +/* u.giveobj(obj.new("rock")); */ +int +nhl_obj_u_giveobj(L) +lua_State *L; +{ + struct _lua_obj *lo = l_obj_check(L, 1); + struct obj *otmp; + int refs; + + if (!lobj_is_ok(lo) || lo->obj->where == OBJ_INVENT) + return 0; + + refs = lo->obj->lua_ref_cnt; + + obj_extract_self(lo->obj); + otmp = addinv(lo->obj); + + if (otmp != lo->obj) { + lo->obj->lua_ref_cnt += refs; + lo->obj = otmp; + } + + return 0; +} + /* Get a table of object class data. */ /* local odata = obj.class(otbl.otyp); */ /* local odata = obj.class(obj.new("rock")); */ @@ -413,7 +439,7 @@ lua_State *L; { struct _lua_obj *lo = l_obj_check(L, 1); - lua_pushboolean(L, lobj_is_ok(lo)); + lua_pushboolean(L, !lobj_is_ok(lo)); return 1; } diff --git a/src/nhlua.c b/src/nhlua.c index a4c7e0473..0e0bc2e81 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -830,6 +830,13 @@ lua_State *L; { "mh", &(u.mh), ANY_INT }, { "mhmax", &(u.mhmax), ANY_INT }, { "mtimedone", &(u.mtimedone), ANY_INT }, + { "dlevel", &(u.uz.dlevel), ANY_SCHAR }, /* actually xchar */ + { "dnum", &(u.uz.dnum), ANY_SCHAR }, /* actually xchar */ + { "uluck", &(u.uluck), ANY_SCHAR }, + { "uhp", &(u.uhp), ANY_INT }, + { "uhpmax", &(u.uhpmax), ANY_INT }, + { "uen", &(u.uen), ANY_INT }, + { "uenmax", &(u.uenmax), ANY_INT }, }; int i; @@ -856,11 +863,35 @@ lua_State *L; return 0; } +static int +nhl_u_clear_inventory(L) +lua_State *L; +{ + while (g.invent) + useupall(g.invent); + return 0; +} + +/* Put object into player's inventory */ +/* u.giveobj(obj.new("rock")); */ +static int +nhl_u_giveobj(L) +lua_State *L; +{ + return nhl_obj_u_giveobj(L); +} + +static const struct luaL_Reg nhl_u_functions[] = { + { "clear_inventory", nhl_u_clear_inventory }, + { "giveobj", nhl_u_giveobj }, +}; + void init_u_data(L) lua_State *L; { lua_newtable(L); + luaL_setfuncs(L, nhl_u_functions, 0); lua_newtable(L); lua_pushcfunction(L, nhl_meta_u_index); lua_setfield(L, -2, "__index");