From ed3d565dda6f76a9100f5d88494708a884ec74c1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 20 May 2012 00:59:31 +0200 Subject: [PATCH] CLuaString will no longer depend on CInterfaceManager. --- .../client/src/interface_v3/lua_object.cpp | 49 ------------------- .../client/src/interface_v3/lua_object.h | 25 +++++----- code/ryzom/client/src/r2/displayer_lua.cpp | 4 +- code/ryzom/client/src/r2/instance.cpp | 2 +- 4 files changed, 15 insertions(+), 65 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/lua_object.cpp b/code/ryzom/client/src/interface_v3/lua_object.cpp index d2d4da1e1..17b703457 100644 --- a/code/ryzom/client/src/interface_v3/lua_object.cpp +++ b/code/ryzom/client/src/interface_v3/lua_object.cpp @@ -653,52 +653,3 @@ void CLuaEnumeration::next() } } - - -CLuaString::CLuaString(const char *value) -{ - _LuaState = NULL; - nlassert(value); - _Ptr = NULL; - _Str = value; -} - - -inline CLuaState &CLuaString::getLua() const -{ - if( _LuaState ) - return *_LuaState; - CInterfaceManager *im = CInterfaceManager::getInstance(); - nlassert(im); - _LuaState = im->getLuaState(); - nlassert(_LuaState); - return *_LuaState; -} - -inline void CLuaString::build() const -{ - if (_Ptr &&_LuaState) return; - CLuaStackChecker lsc(&getLua()); - getLua().push(_Str); - _Ptr = getLua().toString(); - _InLua.pop(getLua()); -} - -const char *CLuaString::getPtr() const -{ - build(); - return _Ptr; -} - - -void CLuaString::pushOnStack() const -{ - build(); - _InLua.push(); -} - - - - - - diff --git a/code/ryzom/client/src/interface_v3/lua_object.h b/code/ryzom/client/src/interface_v3/lua_object.h index 28d2e73b7..7e2d19370 100644 --- a/code/ryzom/client/src/interface_v3/lua_object.h +++ b/code/ryzom/client/src/interface_v3/lua_object.h @@ -246,42 +246,41 @@ private: class CLuaString { public: - explicit CLuaString(const char *value = ""); - const char *getPtr() const; - void pushOnStack() const; - operator const char *() const { return getPtr(); } + explicit CLuaString(const char *value = "") + { + nlassert( value != NULL ); + _Str = value; + } + const std::string& getStr() const{ return _Str; } private: - const char *_Str; - mutable const char *_Ptr; + std::string _Str; mutable CLuaState::TRefPtr _LuaState; // ref ptr so that statics get rebuilt on lua restart mutable CLuaObject _InLua; - CLuaState &getLua() const; - void build() const; }; inline bool operator==(const char* lh, const CLuaString& rh) { - return std::string(lh) == std::string(rh.getPtr()); + return std::string(lh) == rh.getStr(); } inline bool operator==( const CLuaString& lh, const CLuaString& rh) { - return std::string(lh.getPtr()) == std::string(rh.getPtr()); + return lh.getStr() == rh.getStr(); } inline bool operator==(const CLuaString& lh, const char* rh) { - return std::string(rh) == std::string(lh.getPtr()); + return std::string(rh) == lh.getStr(); } inline bool operator==( const CLuaString& lh, const std::string& rh) { - return std::string(lh.getPtr()) == rh; + return lh.getStr() == rh; } inline bool operator==(const std::string& lh, const CLuaString& rh) { - return lh == std::string(rh.getPtr()); + return lh == rh.getStr(); } class CLuaHashMapTraits diff --git a/code/ryzom/client/src/r2/displayer_lua.cpp b/code/ryzom/client/src/r2/displayer_lua.cpp index cb823c033..540e1ea1f 100644 --- a/code/ryzom/client/src/r2/displayer_lua.cpp +++ b/code/ryzom/client/src/r2/displayer_lua.cpp @@ -76,10 +76,10 @@ void CDisplayerLua::CToLua::executeHandler(const CLuaString &eventName, int numA CLuaStackRestorer lsr(&ls, ls.getTop() - numArgs); // if (!_LuaTable.isValid()) return; // init failed - if (_LuaTable[eventName].isNil()) return; // event not handled + if (_LuaTable[ eventName.getStr().c_str() ].isNil()) return; // event not handled static volatile bool dumpStackWanted = false; if (dumpStackWanted) ls.dumpStack(); - _LuaTable[eventName].push(); + _LuaTable[ eventName.getStr().c_str() ].push(); if (dumpStackWanted) ls.dumpStack(); // put method before its args ls.insert(- numArgs - 1); diff --git a/code/ryzom/client/src/r2/instance.cpp b/code/ryzom/client/src/r2/instance.cpp index d30d2bd9b..c4287928a 100644 --- a/code/ryzom/client/src/r2/instance.cpp +++ b/code/ryzom/client/src/r2/instance.cpp @@ -620,7 +620,7 @@ void CInstance::CToLua::executeHandler(const CLuaString &name, int numArgs) // static volatile bool dumpStackWanted = false; if (dumpStackWanted) ls.dumpStack(); - _Class[name].push(); + _Class[ name.getStr().c_str() ].push(); if (ls.isNil(-1)) return; // not handled if (dumpStackWanted) ls.dumpStack(); // put method before its args