diff options
author | Max Horn | 2011-03-21 14:36:25 +0100 |
---|---|---|
committer | Max Horn | 2011-03-21 14:36:25 +0100 |
commit | bf4dc80419b12bb2415d42ee413162bf56019288 (patch) | |
tree | 204318342e856294ccb632fd629d57a08d7f6b05 /engines/sword25/script | |
parent | dd88f39bc7078f96fd06170260bf2ff332b4ca82 (diff) | |
download | scummvm-rg350-bf4dc80419b12bb2415d42ee413162bf56019288.tar.gz scummvm-rg350-bf4dc80419b12bb2415d42ee413162bf56019288.tar.bz2 scummvm-rg350-bf4dc80419b12bb2415d42ee413162bf56019288.zip |
SWORD25: Reduce code duplication; formatting
Diffstat (limited to 'engines/sword25/script')
-rw-r--r-- | engines/sword25/script/luabindhelper.cpp | 21 | ||||
-rw-r--r-- | engines/sword25/script/luabindhelper.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/engines/sword25/script/luabindhelper.cpp b/engines/sword25/script/luabindhelper.cpp index 5ff9708b95..03a1802a04 100644 --- a/engines/sword25/script/luabindhelper.cpp +++ b/engines/sword25/script/luabindhelper.cpp @@ -303,6 +303,27 @@ bool LuaBindhelper::getMetatable(lua_State *L, const Common::String &tableName) return true; } +// Like luaL_checkudata, only without that no error is generated. +void *LuaBindhelper::my_checkudata(lua_State *L, int ud, const char *tname) { + int top = lua_gettop(L); + + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + // lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + LuaBindhelper::getMetatable(L, tname); + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_settop(L, top); + return p; + } + } + } + + lua_settop(L, top); + return NULL; +} + + bool LuaBindhelper::createTable(lua_State *L, const Common::String &tableName) { const char *partBegin = tableName.c_str(); diff --git a/engines/sword25/script/luabindhelper.h b/engines/sword25/script/luabindhelper.h index dc45104d53..94f52743f3 100644 --- a/engines/sword25/script/luabindhelper.h +++ b/engines/sword25/script/luabindhelper.h @@ -110,6 +110,8 @@ public: static bool getMetatable(lua_State *L, const Common::String &tableName); + static void *my_checkudata(lua_State *L, int ud, const char *tname); + private: static bool createTable(lua_State *L, const Common::String &tableName); }; |