summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/clua.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-18 20:09:38 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-18 20:09:38 +0000
commit42c0cf066213e022a8f1f0ea4230b668095c605b (patch)
tree792728ce498a6c6160a9cba6cd49f86ed3c4d887 /crawl-ref/source/clua.cc
parent82cc08db3375be0e6ab3b871f7dde5916ed67c30 (diff)
downloadcrawl-ref-42c0cf066213e022a8f1f0ea4230b668095c605b.tar.gz
crawl-ref-42c0cf066213e022a8f1f0ea4230b668095c605b.zip
Lua marker code is now converted into an anonymous function in the same scope as the rest of the map Lua code so that locals defined in the map Lua are visible to the marker code.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7479 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/clua.cc')
-rw-r--r--crawl-ref/source/clua.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 9fa1a79a9a..7fb7a310a7 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -131,10 +131,15 @@ void CLua::setregistry(const char *name)
lua_settable(state(), LUA_REGISTRYINDEX);
}
+void CLua::_getregistry(lua_State *ls, const char *name)
+{
+ lua_pushstring(ls, name);
+ lua_gettable(ls, LUA_REGISTRYINDEX);
+}
+
void CLua::getregistry(const char *name)
{
- lua_pushstring(state(), name);
- lua_gettable(state(), LUA_REGISTRYINDEX);
+ _getregistry(state(), name);
}
void CLua::save(const char *file)
@@ -639,6 +644,18 @@ void CLua::init_lua()
lua_pushboolean(_state, managed_vm);
setregistry("lua_vm_is_managed");
+
+ lua_pushlightuserdata(_state, this);
+ setregistry("__clua");
+}
+
+CLua &CLua::get_vm(lua_State *ls)
+{
+ _getregistry(ls, "__clua");
+ CLua *vm = util_get_userdata<CLua>(ls, -1);
+ if (!vm)
+ end(1, false, "Failed to find CLua for lua state %p", ls);
+ return (*vm);
}
bool CLua::is_managed_vm(lua_State *ls)