From 71bed49f80f0dbde357e93e93f35d90d6bb6e3f9 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 4 Jul 2012 09:08:40 -0300 Subject: [PATCH] Fixed issue #15 that caused lua stack to grow indefinitely --- src/framework/luascript/luaobject.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/framework/luascript/luaobject.h b/src/framework/luascript/luaobject.h index 825e64bc..ce974474 100644 --- a/src/framework/luascript/luaobject.h +++ b/src/framework/luascript/luaobject.h @@ -37,9 +37,12 @@ public: /// if any lua error occurs, it will be reported to stdout and return 0 results /// @return the number of results template - int callLuaField(const std::string& field, const T&... args); + int luaCallField(const std::string& field, const T&... args); + template R callLuaField(const std::string& field, const T&... args); + template + void callLuaField(const std::string& field, const T&... args); /// Returns true if the lua field exists bool hasLuaField(const std::string& field); @@ -87,7 +90,7 @@ private: #include "luainterface.h" template -int LuaObject::callLuaField(const std::string& field, const T&... args) { +int LuaObject::luaCallField(const std::string& field, const T&... args) { // note that the field must be retrieved from this object lua value // to force using the __index metamethod of it's metatable // so cannot use LuaObject::getField here @@ -109,7 +112,7 @@ int LuaObject::callLuaField(const std::string& field, const T&... args) { template R LuaObject::callLuaField(const std::string& field, const T&... args) { R result; - int rets = callLuaField(field, args...); + int rets = luaCallField(field, args...); if(rets > 0) { assert(rets == 1); result = g_lua.polymorphicPop(); @@ -118,6 +121,13 @@ R LuaObject::callLuaField(const std::string& field, const T&... args) { return result; } +template +void LuaObject::callLuaField(const std::string& field, const T&... args) { + int rets = luaCallField(field, args...); + if(rets > 0) + g_lua.pop(rets); +} + template void LuaObject::setLuaField(const std::string& key, const T& value) { g_lua.polymorphicPush(value);