From 83b1c7b2cc01d46d8f904b102681e85c044710a0 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 25 Nov 2008 23:36:07 +0000 Subject: Place external loot chamber for ziggurat levels with jellies. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7625 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/clua.cc | 50 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'crawl-ref/source/clua.cc') diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 2204d17cf1..3be3f4398e 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -658,6 +658,7 @@ void CLua::init_lua() CLua &CLua::get_vm(lua_State *ls) { + lua_stack_cleaner clean(ls); _getregistry(ls, "__clua"); CLua *vm = util_get_userdata(ls, -1); if (!vm) @@ -2516,6 +2517,27 @@ MDEF(hd) PLUARET(number, mons->hit_dice); } +static const char *_monuse_names[] = +{ + "nothing", "eats_items", "open_doors", "starting_equipment", + "weapons_armour", "magic_items" +}; + +static const char *_monuse_to_str(mon_itemuse_type ityp) +{ + ASSERT(ARRAYSZ(_monuse_names) == NUM_MONUSE); + return _monuse_names[ityp]; +} + +MDEF(muse) +{ + if (const monsterentry *me = mons->find_monsterentry()) + { + PLUARET(string, _monuse_to_str(me->gmon_use)); + } + return (0); +} + static int l_mons_do_dismiss(lua_State *ls) { // dismiss is only callable from dlua, not from managed VMs (i.e. @@ -2551,6 +2573,7 @@ static MonsAccessor mons_attrs[] = { "x" , l_mons_x }, { "y" , l_mons_y }, { "hd" , l_mons_hd }, + { "muse", l_mons_muse }, { "dismiss", l_mons_dismiss }, { "experience", l_mons_experience }, }; @@ -2627,6 +2650,12 @@ void clua_push_map(lua_State *ls, map_def *map) *mapref = map; } +void clua_push_coord(lua_State *ls, const coord_def &c) +{ + lua_pushnumber(ls, c.x); + lua_pushnumber(ls, c.y); +} + void clua_push_dgn_event(lua_State *ls, const dgn_event *devent) { const dgn_event **de = @@ -3051,7 +3080,7 @@ lua_shutdown_listener::~lua_shutdown_listener() } lua_datum::lua_datum(CLua &_lua, int stackpos, bool pop) - : need_cleanup(true), lua(_lua) + : lua(_lua), need_cleanup(true) { // Store the datum in the registry indexed by "this". lua_pushvalue(lua, stackpos); @@ -3067,13 +3096,28 @@ lua_datum::lua_datum(CLua &_lua, int stackpos, bool pop) } lua_datum::lua_datum(const lua_datum &o) - : need_cleanup(true), lua(o.lua) + : lua(o.lua), need_cleanup(true) +{ + set_from(o); +} + +void lua_datum::set_from(const lua_datum &o) { lua_pushlightuserdata(lua, this); o.push(); lua_settable(lua, LUA_REGISTRYINDEX); - lua.add_shutdown_listener(this); + need_cleanup = true; +} + +const lua_datum &lua_datum::operator = (const lua_datum &o) +{ + if (this != &o) + { + cleanup(); + set_from(o); + } + return (*this); } void lua_datum::push() const -- cgit v1.2.3-54-g00ecf