CLuaString will no longer depend on CInterfaceManager.

--HG--
branch : gui-refactoring
hg/feature/sse2
dfighter1985 13 years ago
parent 1289f028a0
commit 4e3552694a

@ -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();
}

@ -246,42 +246,41 @@ private:
class CLuaString class CLuaString
{ {
public: public:
explicit CLuaString(const char *value = ""); explicit CLuaString(const char *value = "")
const char *getPtr() const; {
void pushOnStack() const; nlassert( value != NULL );
operator const char *() const { return getPtr(); } _Str = value;
}
const std::string& getStr() const{ return _Str; }
private: private:
const char *_Str; std::string _Str;
mutable const char *_Ptr;
mutable CLuaState::TRefPtr _LuaState; // ref ptr so that statics get rebuilt on lua restart mutable CLuaState::TRefPtr _LuaState; // ref ptr so that statics get rebuilt on lua restart
mutable CLuaObject _InLua; mutable CLuaObject _InLua;
CLuaState &getLua() const;
void build() const;
}; };
inline bool operator==(const char* lh, const CLuaString& rh) 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) 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) 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) 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) inline bool operator==(const std::string& lh, const CLuaString& rh)
{ {
return lh == std::string(rh.getPtr()); return lh == rh.getStr();
} }
class CLuaHashMapTraits class CLuaHashMapTraits

@ -76,10 +76,10 @@ void CDisplayerLua::CToLua::executeHandler(const CLuaString &eventName, int numA
CLuaStackRestorer lsr(&ls, ls.getTop() - numArgs); CLuaStackRestorer lsr(&ls, ls.getTop() - numArgs);
// //
if (!_LuaTable.isValid()) return; // init failed 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; static volatile bool dumpStackWanted = false;
if (dumpStackWanted) ls.dumpStack(); if (dumpStackWanted) ls.dumpStack();
_LuaTable[eventName].push(); _LuaTable[ eventName.getStr().c_str() ].push();
if (dumpStackWanted) ls.dumpStack(); if (dumpStackWanted) ls.dumpStack();
// put method before its args // put method before its args
ls.insert(- numArgs - 1); ls.insert(- numArgs - 1);

@ -620,7 +620,7 @@ void CInstance::CToLua::executeHandler(const CLuaString &name, int numArgs)
// //
static volatile bool dumpStackWanted = false; static volatile bool dumpStackWanted = false;
if (dumpStackWanted) ls.dumpStack(); if (dumpStackWanted) ls.dumpStack();
_Class[name].push(); _Class[ name.getStr().c_str() ].push();
if (ls.isNil(-1)) return; // not handled if (ls.isNil(-1)) return; // not handled
if (dumpStackWanted) ls.dumpStack(); if (dumpStackWanted) ls.dumpStack();
// put method before its args // put method before its args

Loading…
Cancel
Save