LuaHelpers::RunExpressionI, LuaHelpers::RunExpressionS
This commit is contained in:
@@ -341,15 +341,19 @@ float LuaHelpers::RunExpressionF( const CString &str )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaManager::RunExpressionI( const CString &str )
|
int LuaHelpers::RunExpressionI( const CString &str )
|
||||||
{
|
{
|
||||||
return (int) LuaHelpers::RunExpressionF(str);
|
return (int) LuaHelpers::RunExpressionF(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
bool LuaHelpers::RunExpressionS( const CString &str, CString &sOut )
|
||||||
{
|
{
|
||||||
|
Lua *L = LUA->Get();
|
||||||
if( !LuaHelpers::RunScript(L, "return " + str, "", 1) )
|
if( !LuaHelpers::RunScript(L, "return " + str, "", 1) )
|
||||||
|
{
|
||||||
|
LUA->Release(L);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Don't accept a function as a return value. */
|
/* Don't accept a function as a return value. */
|
||||||
if( lua_isfunction( L, -1 ) )
|
if( lua_isfunction( L, -1 ) )
|
||||||
@@ -358,6 +362,7 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
|||||||
sOut = lua_tostring( L, -1 );
|
sOut = lua_tostring( L, -1 );
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
|
|
||||||
|
LUA->Release(L);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +375,7 @@ bool LuaManager::RunAtExpressionS( CString &sStr )
|
|||||||
sStr.erase( 0, 1 );
|
sStr.erase( 0, 1 );
|
||||||
|
|
||||||
CString sOut;
|
CString sOut;
|
||||||
RunExpressionS( sStr, sOut );
|
LuaHelpers::RunExpressionS( sStr, sOut );
|
||||||
sStr = sOut;
|
sStr = sOut;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,10 +59,6 @@ public:
|
|||||||
/* Reset the environment, freeing any globals left over by previously executed scripts. */
|
/* Reset the environment, freeing any globals left over by previously executed scripts. */
|
||||||
void ResetState();
|
void ResetState();
|
||||||
|
|
||||||
/* Run an expression in the global environment, returning the given type. */
|
|
||||||
int RunExpressionI( const CString &str );
|
|
||||||
bool RunExpressionS( const CString &str, CString &sOut );
|
|
||||||
|
|
||||||
/* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */
|
/* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */
|
||||||
bool RunAtExpressionS( CString &sStr );
|
bool RunAtExpressionS( CString &sStr );
|
||||||
|
|
||||||
@@ -105,6 +101,8 @@ namespace LuaHelpers
|
|||||||
/* Run an expression in the global environment, returning the given type. */
|
/* Run an expression in the global environment, returning the given type. */
|
||||||
bool RunExpressionB( const CString &str );
|
bool RunExpressionB( const CString &str );
|
||||||
float RunExpressionF( const CString &str );
|
float RunExpressionF( const CString &str );
|
||||||
|
int RunExpressionI( const CString &str );
|
||||||
|
bool RunExpressionS( const CString &str, CString &sOut );
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void ReadArrayFromTable( vector<T> &aOut, lua_State *L )
|
void ReadArrayFromTable( vector<T> &aOut, lua_State *L )
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void ScoreDisplayAliveTime::LoadFromNode( const CString& sDir, const XNode* pNod
|
|||||||
CString sPlayerNumber;
|
CString sPlayerNumber;
|
||||||
bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber );
|
bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber );
|
||||||
ASSERT( b );
|
ASSERT( b );
|
||||||
m_PlayerNumber = (PlayerNumber)LUA->RunExpressionI(sPlayerNumber);
|
m_PlayerNumber = (PlayerNumber) LuaHelpers::RunExpressionI(sPlayerNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ void ScoreDisplayCalories::LoadFromNode( const CString& sDir, const XNode* pNode
|
|||||||
CString sPlayerNumber;
|
CString sPlayerNumber;
|
||||||
bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber );
|
bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber );
|
||||||
ASSERT( b );
|
ASSERT( b );
|
||||||
m_PlayerNumber = (PlayerNumber)LUA->RunExpressionI(sPlayerNumber);
|
m_PlayerNumber = (PlayerNumber) LuaHelpers::RunExpressionI(sPlayerNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sMessageOnStep = ssprintf("StepP%d",m_PlayerNumber+1);
|
m_sMessageOnStep = ssprintf("StepP%d",m_PlayerNumber+1);
|
||||||
|
|||||||
Reference in New Issue
Block a user