From f4c70c96a50270950b0886ba7cacab05e8934477 Mon Sep 17 00:00:00 2001 From: "M. Liebmann" Date: Sun, 16 Mar 2014 11:56:48 +0100 Subject: [PATCH] CLuaInstance: Add additional tableLookup for get userdata --- src/gui/luainstance.cpp | 12 ++++++++++++ src/gui/luainstance.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/gui/luainstance.cpp b/src/gui/luainstance.cpp index 3ec4c504d..cc9d2a94d 100644 --- a/src/gui/luainstance.cpp +++ b/src/gui/luainstance.cpp @@ -677,6 +677,18 @@ bool CLuaInstance::tableLookup(lua_State *L, const char *what, int &value) return res; } +bool CLuaInstance::tableLookup(lua_State *L, const char *what, void** value) +{ + bool res = false; + lua_pushstring(L, what); + lua_gettable(L, -2); + res = lua_isuserdata(L, -1); + if (res) + *value = lua_unboxpointer(L, -1); + lua_pop(L, 1); + return res; +} + bool CLuaMenuChangeObserver::changeNotify(lua_State *L, const std::string &luaAction, const std::string &luaId, void *Data) { const char *optionValue = (const char *) Data; diff --git a/src/gui/luainstance.h b/src/gui/luainstance.h index 7e5c31e51..93d66af6e 100644 --- a/src/gui/luainstance.h +++ b/src/gui/luainstance.h @@ -218,6 +218,7 @@ private: static bool tableLookup(lua_State*, const char*, std::string&); static bool tableLookup(lua_State*, const char*, int&); + static bool tableLookup(lua_State*, const char*, void**); }; #endif /* _LUAINSTANCE_H */