From c5dc18c954aba6be7fb058e5d5394cd276a81309 Mon Sep 17 00:00:00 2001 From: Mauro Iazzi Date: Tue, 27 May 2008 22:58:58 +0200 Subject: [PATCH] pushing udata does not override metatable with base class added specific functions to take care of qflags --- common/lqt_common.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++-------- common/lqt_common.hpp | 3 +++ 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/common/lqt_common.cpp b/common/lqt_common.cpp index c0124ee..3a983a0 100644 --- a/common/lqt_common.cpp +++ b/common/lqt_common.cpp @@ -311,16 +311,38 @@ void lqtL_unregister (lua_State *L, const void *p) { } void lqtL_passudata (lua_State *L, const void *p, const char *name) { + bool already = false; lqtL_ensurepointer(L, p); // (1) - luaL_newmetatable(L, name); // (2) - lua_setmetatable(L, -2); // (1) + if (lua_getmetatable(L, -1)) { + // (2) + lua_pop(L, 1); // (1) + lua_getfield(L, -1, name); // (2) + already = lua_toboolean(L, -1); // (2) + lua_pop(L, 1); // (1) + } else { + // (1) + } + if (!already) { + luaL_newmetatable(L, name); // (2) + lua_setmetatable(L, -2); // (1) + } return; } void lqtL_pushudata (lua_State *L, const void *p, const char *name) { + bool already = false; lqtL_ensurepointer(L, p); // (1) - luaL_newmetatable(L, name); // (2) - lua_setmetatable(L, -2); // (1) + lua_getmetatable(L, -1); // (2) + if (!lua_isnil(L, -1)) { + lua_pop(L, 1); // (1) + lua_getfield(L, -1, name); // (2) + already = lua_toboolean(L, -1); // (2) + } + lua_pop(L, 1); // (1) + if (!already) { + luaL_newmetatable(L, name); // (2) + lua_setmetatable(L, -2); // (1) + } return; } @@ -376,11 +398,31 @@ bool lqtL_isenum (lua_State *L, int index, const char *name) { int lqtL_toenum (lua_State *L, int index, const char *name) { int ret = -1; - lqtL_getenumtable(L); - lua_pushvalue(L, index); - lua_gettable(L, -2); - ret = lua_tointeger(L, -1); - lua_pop(L, 2); + lqtL_getenumtable(L); // (1) + lua_getfield(L, -1, name); // (2) + if (lua_isnil(L, -1)) { + lua_pop(L, 2); //(0) + return 0; + } + lua_pushvalue(L, index); // (3) + lua_gettable(L, -2); // (3) + ret = lua_tointeger(L, -1); // (3) + lua_pop(L, 3); // (0) return ret; } +int lqtL_getflags (lua_State *L, int index, const char *name) { + return 0; + lqtL_getenumtable(L); + lua_getfield(L, -1, name); + lua_remove(L, -2); +} + +void lqtL_pushflags (lua_State *L, int index, const char *name) { + lua_pushnil(L); + return; +} + + + + diff --git a/common/lqt_common.hpp b/common/lqt_common.hpp index f1623c4..f0e9445 100644 --- a/common/lqt_common.hpp +++ b/common/lqt_common.hpp @@ -108,6 +108,9 @@ extern int * lqtL_tointref (lua_State *, int); extern char ** lqtL_toarguments (lua_State *, int); extern void lqtL_pusharguments (lua_State *, char **); +extern int lqtL_getflags (lua_State *, int, const char *); +extern void lqtL_pushflags (lua_State *, int, const char *); + #endif // __LQT_COMMON_HPP -- 2.11.4.GIT