diff options
Diffstat (limited to 'src/scripting/luautil.cpp')
-rw-r--r-- | src/scripting/luautil.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/scripting/luautil.cpp b/src/scripting/luautil.cpp index 217fc60c..0a49e834 100644 --- a/src/scripting/luautil.cpp +++ b/src/scripting/luautil.cpp @@ -29,6 +29,8 @@ #include "utils/logger.h" +#include "scripting/luascript.h" + void raiseScriptError(lua_State *s, const char *format, ...) { @@ -112,6 +114,16 @@ void UserDataCache::insert(lua_State *s, void *object) } +Script *getScript(lua_State *s) +{ + lua_pushlightuserdata(s, (void *)&LuaScript::registryKey); + lua_gettable(s, LUA_REGISTRYINDEX); + Script *script = static_cast<Script *>(lua_touserdata(s, -1)); + lua_pop(s, 1); + return script; +} + + /* Functions below are unsafe, as they assume the script has passed pointers to objects which have not yet been destroyed. If the script never keeps pointers around, there will be no problem. In order to be safe, the engine @@ -241,6 +253,19 @@ NPC *checkNPC(lua_State *s, int p) } +MapComposite *checkCurrentMap(lua_State *s, Script *script /* = 0 */) +{ + if (!script) + script = getScript(s); + + MapComposite *mapComposite = script->getMap(); + if (!mapComposite) + luaL_error(s, "no current map"); + + return mapComposite; +} + + void push(lua_State *s, int val) { lua_pushinteger(s, val); |