remove unused stuff
simplify ActorCommands I thought about getting rid of m_sLuaFunction; it's not needed anymore, and takes up memory (probably more memory than the function itself), but I use it a lot to identify floating references when I don't know what I'm looking at. Store it generically in LuaReference.
This commit is contained in:
@@ -9,15 +9,16 @@
|
||||
|
||||
ActorCommands::ActorCommands( const RString &sCommands )
|
||||
{
|
||||
RString sLuaFunction;
|
||||
if( sCommands.size() > 0 && sCommands[0] == '\033' )
|
||||
{
|
||||
/* This is a compiled Lua chunk. Just pass it on directly. */
|
||||
m_sLuaFunction = sCommands;
|
||||
sLuaFunction = sCommands;
|
||||
}
|
||||
else if( sCommands.size() > 0 && sCommands[0] == '%' )
|
||||
{
|
||||
m_sLuaFunction = "return ";
|
||||
m_sLuaFunction.append( sCommands.begin()+1, sCommands.end() );
|
||||
sLuaFunction = "return ";
|
||||
sLuaFunction.append( sCommands.begin()+1, sCommands.end() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -83,27 +84,24 @@ ActorCommands::ActorCommands( const RString &sCommands )
|
||||
|
||||
s << "end\n";
|
||||
|
||||
m_sLuaFunction = s.str();
|
||||
sLuaFunction = s.str();
|
||||
}
|
||||
|
||||
Register();
|
||||
|
||||
ASSERT_M( !this->IsNil(), m_sLuaFunction.c_str() );
|
||||
}
|
||||
|
||||
void ActorCommands::Register()
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
|
||||
RString sError;
|
||||
if( !LuaHelpers::RunScript( L, m_sLuaFunction, "in", sError, 1 ) )
|
||||
if( !LuaHelpers::RunScript( L, sLuaFunction, "in", sError, 1 ) )
|
||||
{
|
||||
FAIL_M( ssprintf("Compiling \"%s\": %s", m_sLuaFunction.c_str(), sError.c_str()) );
|
||||
FAIL_M( ssprintf("Compiling \"%s\": %s", sLuaFunction.c_str(), sError.c_str()) );
|
||||
}
|
||||
|
||||
/* The function is now on the stack. */
|
||||
this->SetFromStack( L );
|
||||
LUA->Release( L );
|
||||
|
||||
ASSERT_M( !this->IsNil(), sLuaFunction.c_str() );
|
||||
|
||||
SetName( sLuaFunction );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,10 +11,6 @@ class ActorCommands: public LuaReference
|
||||
{
|
||||
public:
|
||||
ActorCommands( const RString &sCommands );
|
||||
|
||||
private:
|
||||
void Register();
|
||||
RString m_sLuaFunction;
|
||||
};
|
||||
|
||||
typedef AutoPtrCopyOnWrite<LuaReference> apActorCommands;
|
||||
|
||||
@@ -121,6 +121,12 @@ int LuaReference::GetLuaType() const
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/* This is used only for debugging. */
|
||||
void LuaReference::SetName( const RString &sName )
|
||||
{
|
||||
m_sName = sName;
|
||||
}
|
||||
|
||||
void LuaReference::Unregister()
|
||||
{
|
||||
if( LUA == NULL )
|
||||
@@ -132,28 +138,14 @@ void LuaReference::Unregister()
|
||||
m_iReference = LUA_NOREF;
|
||||
}
|
||||
|
||||
void LuaReference::ReRegister()
|
||||
{
|
||||
/* When this is called, the Lua state has been wiped. Don't try to unregister our
|
||||
* old function reference, since it's already gone (and the number may point
|
||||
* somewhere else). */
|
||||
m_iReference = LUA_NOREF;
|
||||
|
||||
Register();
|
||||
}
|
||||
|
||||
|
||||
void LuaExpression::SetFromExpression( const RString &sExpression )
|
||||
{
|
||||
m_sExpression = "return " + sExpression;
|
||||
Register();
|
||||
}
|
||||
RString sFullExpression = "return " + sExpression;
|
||||
SetName( sFullExpression );
|
||||
|
||||
void LuaExpression::Register()
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
|
||||
if( !LuaHelpers::RunScript(L, m_sExpression, "expression", 1) )
|
||||
if( !LuaHelpers::RunScript(L, sFullExpression, "expression", 1) )
|
||||
{
|
||||
this->SetFromNil();
|
||||
LUA->Release( L );
|
||||
@@ -210,24 +202,6 @@ void LuaData::LoadFromString( const RString &s )
|
||||
LUA->Release( L );
|
||||
}
|
||||
|
||||
void LuaData::BeforeReset()
|
||||
{
|
||||
/* If we're unset, Register() should leave us unset, not set us to LUA_REFNIL. */
|
||||
m_bWasSet = IsSet();
|
||||
|
||||
if( m_bWasSet )
|
||||
m_sSerializedData = Serialize();
|
||||
}
|
||||
|
||||
void LuaData::Register()
|
||||
{
|
||||
if( !m_bWasSet )
|
||||
return;
|
||||
|
||||
LoadFromString( m_sSerializedData );
|
||||
m_sSerializedData.erase( m_sSerializedData.begin(), m_sSerializedData.end() );
|
||||
}
|
||||
|
||||
LuaTable::LuaTable()
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
|
||||
@@ -35,19 +35,15 @@ public:
|
||||
/* Return the referenced type, or LUA_TNONE if not set. */
|
||||
int GetLuaType() const;
|
||||
|
||||
protected:
|
||||
/* If this object needs to store state to recreate itself, overload this. */
|
||||
virtual void BeforeReset() { }
|
||||
|
||||
/* If this object is able to recreate itself, overload this, and ReRegisterAll
|
||||
* will work; the reference will still exist after a theme change. If not
|
||||
* implemented, the reference will be unset after ReRegister. */
|
||||
virtual void Register() { }
|
||||
void SetName( const RString &sName );
|
||||
RString GetName() const { return m_sName; }
|
||||
|
||||
private:
|
||||
void Unregister();
|
||||
void ReRegister();
|
||||
int m_iReference;
|
||||
|
||||
/* This string can identify the reference. This is only used for debugging. */
|
||||
RString m_sName;
|
||||
};
|
||||
|
||||
/* Evaluate an expression that returns an object; store the object in a reference.
|
||||
@@ -57,12 +53,6 @@ class LuaExpression: public LuaReference
|
||||
public:
|
||||
LuaExpression( const RString &sExpression = "" ) { if( sExpression != "" ) SetFromExpression( sExpression ); }
|
||||
void SetFromExpression( const RString &sExpression );
|
||||
|
||||
protected:
|
||||
virtual void Register();
|
||||
|
||||
private:
|
||||
RString m_sExpression;
|
||||
};
|
||||
|
||||
/* Reference a trivially restorable Lua object (any object that Serialize can handle).
|
||||
@@ -72,13 +62,6 @@ class LuaData: public LuaReference
|
||||
public:
|
||||
virtual RString Serialize() const;
|
||||
virtual void LoadFromString( const RString &s );
|
||||
|
||||
protected:
|
||||
virtual void BeforeReset();
|
||||
virtual void Register();
|
||||
|
||||
RString m_sSerializedData;
|
||||
bool m_bWasSet;
|
||||
};
|
||||
|
||||
class LuaTable: public LuaData
|
||||
|
||||
Reference in New Issue
Block a user