mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-24 18:08:44 +00:00
CLuaString will no longer depend on CInterfaceManager.
--HG-- branch : gui-refactoring
This commit is contained in:
parent
1289f028a0
commit
4e3552694a
4 changed files with 15 additions and 65 deletions
|
@ -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
|
||||
{
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue