summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mapmark.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-18 20:07:42 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-18 20:07:42 +0000
commita06523dd0f46c2536e070e58c9288419bbcbf22e (patch)
tree1c49523bf609b18ee5e6a529e18e34438b62bfad /crawl-ref/source/mapmark.cc
parentff00ffd9da330a94bd282bcc127157672e589a9a (diff)
downloadcrawl-ref-a06523dd0f46c2536e070e58c9288419bbcbf22e.tar.gz
crawl-ref-a06523dd0f46c2536e070e58c9288419bbcbf22e.zip
Added lua_datum to wrap the common task of retaining references to Lua objects in the Lua registry.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7477 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/mapmark.cc')
-rw-r--r--crawl-ref/source/mapmark.cc28
1 files changed, 10 insertions, 18 deletions
diff --git a/crawl-ref/source/mapmark.cc b/crawl-ref/source/mapmark.cc
index 5f0942ef2e..7fadb6330e 100644
--- a/crawl-ref/source/mapmark.cc
+++ b/crawl-ref/source/mapmark.cc
@@ -188,13 +188,6 @@ map_lua_marker::map_lua_marker(const std::string &s, const std::string &,
map_lua_marker::~map_lua_marker()
{
- // Remove the Lua marker table from the registry.
- if (initialised)
- {
- lua_pushlightuserdata(dlua, this);
- lua_pushnil(dlua);
- lua_settable(dlua, LUA_REGISTRYINDEX);
- }
}
map_marker *map_lua_marker::clone() const
@@ -216,22 +209,21 @@ void map_lua_marker::check_register_table()
}
// Got a table. Save it in the registry.
-
- // Key is this.
- lua_pushlightuserdata(dlua, this);
- // Move key before value.
- lua_insert(dlua, -2);
- lua_settable(dlua, LUA_REGISTRYINDEX);
-
+ marker_table.reset(new lua_datum(dlua));
initialised = true;
}
bool map_lua_marker::get_table() const
{
- // First save the unmarshall Lua function.
- lua_pushlightuserdata(dlua, const_cast<map_lua_marker*>(this));
- lua_gettable(dlua, LUA_REGISTRYINDEX);
- return (lua_istable(dlua, -1));
+ if (marker_table.get())
+ {
+ marker_table->push();
+ return (lua_istable(dlua, -1));
+ }
+ else
+ {
+ return (false);
+ }
}
void map_lua_marker::write(writer &outf) const