LuaHelpers::RunExpressionI, LuaHelpers::RunExpressionS

This commit is contained in:
Glenn Maynard
2005-06-16 06:37:45 +00:00
parent cb3f10aabb
commit dd3b227562
4 changed files with 12 additions and 9 deletions
+8 -3
View File
@@ -341,15 +341,19 @@ float LuaHelpers::RunExpressionF( const CString &str )
return result;
}
int LuaManager::RunExpressionI( const CString &str )
int LuaHelpers::RunExpressionI( const CString &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) )
{
LUA->Release(L);
return false;
}
/* Don't accept a function as a return value. */
if( lua_isfunction( L, -1 ) )
@@ -358,6 +362,7 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
sOut = lua_tostring( L, -1 );
lua_pop( L, 1 );
LUA->Release(L);
return true;
}
@@ -370,7 +375,7 @@ bool LuaManager::RunAtExpressionS( CString &sStr )
sStr.erase( 0, 1 );
CString sOut;
RunExpressionS( sStr, sOut );
LuaHelpers::RunExpressionS( sStr, sOut );
sStr = sOut;
return true;
}
+2 -4
View File
@@ -59,10 +59,6 @@ public:
/* Reset the environment, freeing any globals left over by previously executed scripts. */
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. */
bool RunAtExpressionS( CString &sStr );
@@ -105,6 +101,8 @@ namespace LuaHelpers
/* Run an expression in the global environment, returning the given type. */
bool RunExpressionB( const CString &str );
float RunExpressionF( const CString &str );
int RunExpressionI( const CString &str );
bool RunExpressionS( const CString &str, CString &sOut );
template<class T>
void ReadArrayFromTable( vector<T> &aOut, lua_State *L )
+1 -1
View File
@@ -30,7 +30,7 @@ void ScoreDisplayAliveTime::LoadFromNode( const CString& sDir, const XNode* pNod
CString sPlayerNumber;
bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber );
ASSERT( b );
m_PlayerNumber = (PlayerNumber)LUA->RunExpressionI(sPlayerNumber);
m_PlayerNumber = (PlayerNumber) LuaHelpers::RunExpressionI(sPlayerNumber);
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ void ScoreDisplayCalories::LoadFromNode( const CString& sDir, const XNode* pNode
CString sPlayerNumber;
bool b = pNode->GetAttrValue( "PlayerNumber", sPlayerNumber );
ASSERT( b );
m_PlayerNumber = (PlayerNumber)LUA->RunExpressionI(sPlayerNumber);
m_PlayerNumber = (PlayerNumber) LuaHelpers::RunExpressionI(sPlayerNumber);
}
m_sMessageOnStep = ssprintf("StepP%d",m_PlayerNumber+1);