LuaHelpers::RunExpressionF
This commit is contained in:
@@ -53,12 +53,12 @@ void ActorFrame::LoadFromNode( const CString& sDir, const XNode* pNode )
|
|||||||
if( pNode->GetAttrValue( "VanishX", s ) )
|
if( pNode->GetAttrValue( "VanishX", s ) )
|
||||||
{
|
{
|
||||||
LUA->PrepareExpression( s );
|
LUA->PrepareExpression( s );
|
||||||
m_fVanishX = LUA->RunExpressionF( s );
|
m_fVanishX = LuaHelpers::RunExpressionF( s );
|
||||||
}
|
}
|
||||||
if( pNode->GetAttrValue( "VanishY", s ) )
|
if( pNode->GetAttrValue( "VanishY", s ) )
|
||||||
{
|
{
|
||||||
LUA->PrepareExpression( s );
|
LUA->PrepareExpression( s );
|
||||||
m_fVanishY = LUA->RunExpressionF( s );
|
m_fVanishY = LuaHelpers::RunExpressionF( s );
|
||||||
}
|
}
|
||||||
m_bOverrideLighting = pNode->GetAttrValue( "Lighting", m_bLighting );
|
m_bOverrideLighting = pNode->GetAttrValue( "Lighting", m_bLighting );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,19 +41,19 @@ Command::Arg::operator CString ()
|
|||||||
Command::Arg::operator float ()
|
Command::Arg::operator float ()
|
||||||
{
|
{
|
||||||
LUA->PrepareExpression( s ); // strip invalid chars
|
LUA->PrepareExpression( s ); // strip invalid chars
|
||||||
return LUA->RunExpressionF( s );
|
return LuaHelpers::RunExpressionF( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Arg::operator int ()
|
Command::Arg::operator int ()
|
||||||
{
|
{
|
||||||
LUA->PrepareExpression( s ); // strip invalid chars
|
LUA->PrepareExpression( s ); // strip invalid chars
|
||||||
return (int)LUA->RunExpressionF( s );
|
return (int) LuaHelpers::RunExpressionF( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Arg::operator bool ()
|
Command::Arg::operator bool ()
|
||||||
{
|
{
|
||||||
LUA->PrepareExpression( s ); // strip invalid chars
|
LUA->PrepareExpression( s ); // strip invalid chars
|
||||||
return LUA->RunExpressionF( s ) != 0.0f;
|
return LuaHelpers::RunExpressionF( s ) != 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::Load( const CString &sCommand )
|
void Command::Load( const CString &sCommand )
|
||||||
|
|||||||
@@ -321,10 +321,14 @@ bool LuaHelpers::RunExpressionB( const CString &str )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float LuaManager::RunExpressionF( const CString &str )
|
float LuaHelpers::RunExpressionF( const CString &str )
|
||||||
{
|
{
|
||||||
|
Lua *L = LUA->Get();
|
||||||
if( !LuaHelpers::RunScript(L, "return " + str, "", 1) )
|
if( !LuaHelpers::RunScript(L, "return " + str, "", 1) )
|
||||||
|
{
|
||||||
|
LUA->Release(L);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* 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 ) )
|
||||||
@@ -333,12 +337,13 @@ float LuaManager::RunExpressionF( const CString &str )
|
|||||||
float result = (float) lua_tonumber( L, -1 );
|
float result = (float) lua_tonumber( L, -1 );
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
|
|
||||||
|
LUA->Release(L);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaManager::RunExpressionI( const CString &str )
|
int LuaManager::RunExpressionI( const CString &str )
|
||||||
{
|
{
|
||||||
return (int)RunExpressionF(str);
|
return (int) LuaHelpers::RunExpressionF(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
bool LuaManager::RunExpressionS( const CString &str, CString &sOut )
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ public:
|
|||||||
void ResetState();
|
void ResetState();
|
||||||
|
|
||||||
/* Run an expression in the global environment, returning the given type. */
|
/* Run an expression in the global environment, returning the given type. */
|
||||||
float RunExpressionF( const CString &str );
|
|
||||||
int RunExpressionI( const CString &str );
|
int RunExpressionI( const CString &str );
|
||||||
bool RunExpressionS( const CString &str, CString &sOut );
|
bool RunExpressionS( const CString &str, CString &sOut );
|
||||||
|
|
||||||
@@ -105,6 +104,7 @@ 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 );
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void ReadArrayFromTable( vector<T> &aOut, lua_State *L )
|
void ReadArrayFromTable( vector<T> &aOut, lua_State *L )
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void RollingNumbers::LoadFromNode( const CString& sDir, const XNode* pNode )
|
|||||||
CString sTargetNumber;
|
CString sTargetNumber;
|
||||||
if( pNode->GetAttrValue( "TargetNumber", sTargetNumber ) )
|
if( pNode->GetAttrValue( "TargetNumber", sTargetNumber ) )
|
||||||
{
|
{
|
||||||
float fTargetNumber = LUA->RunExpressionF(sTargetNumber);
|
float fTargetNumber = LuaHelpers::RunExpressionF(sTargetNumber);
|
||||||
SetTargetNumber( fTargetNumber );
|
SetTargetNumber( fTargetNumber );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -719,7 +719,7 @@ float ThemeManager::GetMetricF( const CString &sClassName, const CString &sValue
|
|||||||
|
|
||||||
LUA->PrepareExpression( sValue );
|
LUA->PrepareExpression( sValue );
|
||||||
|
|
||||||
return LUA->RunExpressionF( sValue );
|
return LuaHelpers::RunExpressionF( sValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// #include "LuaManager.h"
|
// #include "LuaManager.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user