Command/LuaManager: add legacy command parsing

Only enabled when compiling via CompileXNodeTree.
This commit is contained in:
Devin J. Pohly
2014-02-20 10:59:49 -05:00
parent c9ac7e7a53
commit a9d5931533
9 changed files with 41 additions and 15 deletions
+1 -1
View File
@@ -307,7 +307,7 @@ bool ActorUtil::GetAttrPath( const XNode *pNode, const RString &sName, RString &
apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName ) apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName )
{ {
Lua *L = LUA->Get(); Lua *L = LUA->Get();
LuaHelpers::ParseCommandList( L, sCommands, sName ); LuaHelpers::ParseCommandList( L, sCommands, sName, false );
LuaReference *pRet = new LuaReference; LuaReference *pRet = new LuaReference;
pRet->SetFromStack( L ); pRet->SetFromStack( L );
LUA->Release( L ); LUA->Release( L );
+6 -3
View File
@@ -87,10 +87,13 @@ RString Commands::GetOriginalCommandString() const
return s; return s;
} }
void ParseCommands( const RString &sCommands, Commands &vCommandsOut ) void ParseCommands( const RString &sCommands, Commands &vCommandsOut, bool bLegacy )
{ {
vector<RString> vsCommands; vector<RString> vsCommands;
SplitWithQuotes( sCommands, ';', vsCommands, true ); // do ignore empty if( bLegacy )
split( sCommands, ";", vsCommands, true );
else
SplitWithQuotes( sCommands, ';', vsCommands, true ); // do ignore empty
vCommandsOut.v.resize( vsCommands.size() ); vCommandsOut.v.resize( vsCommands.size() );
for( unsigned i=0; i<vsCommands.size(); i++ ) for( unsigned i=0; i<vsCommands.size(); i++ )
@@ -103,7 +106,7 @@ void ParseCommands( const RString &sCommands, Commands &vCommandsOut )
Commands ParseCommands( const RString &sCommands ) Commands ParseCommands( const RString &sCommands )
{ {
Commands vCommands; Commands vCommands;
ParseCommands( sCommands, vCommands ); ParseCommands( sCommands, vCommands, false );
return vCommands; return vCommands;
} }
+1 -1
View File
@@ -37,7 +37,7 @@ public:
// string. sCommand list is a list of commands separated by ';'. // string. sCommand list is a list of commands separated by ';'.
// TODO: This is expensive to do during the game. Eventually, move all calls to // TODO: This is expensive to do during the game. Eventually, move all calls to
// ParseCommands to happen during load, then execute from the parsed Command structures. // ParseCommands to happen during load, then execute from the parsed Command structures.
void ParseCommands( const RString &sCmds, Commands &vCmdsOut ); void ParseCommands( const RString &sCmds, Commands &vCmdsOut, bool bLegacy );
Commands ParseCommands( const RString &sCmds ); Commands ParseCommands( const RString &sCmds );
#endif #endif
+27 -5
View File
@@ -838,7 +838,7 @@ bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RStrin
return true; return true;
} }
void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RString &sName ) void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RString &sName, bool bLegacy )
{ {
RString sLuaFunction; RString sLuaFunction;
if( sCommands.size() > 0 && sCommands[0] == '\033' ) if( sCommands.size() > 0 && sCommands[0] == '\033' )
@@ -854,18 +854,35 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri
else else
{ {
Commands cmds; Commands cmds;
ParseCommands( sCommands, cmds ); ParseCommands( sCommands, cmds, bLegacy );
// Convert cmds to a Lua function // Convert cmds to a Lua function
ostringstream s; ostringstream s;
s << "return function(self)\n"; s << "return function(self)\n";
if( bLegacy )
s << "\tparent = self:GetParent();\n";
FOREACH_CONST( Command, cmds.v, c ) FOREACH_CONST( Command, cmds.v, c )
{ {
const Command& cmd = (*c); const Command& cmd = (*c);
RString local_sName = cmd.GetName(); RString sCmdName = cmd.GetName();
s << "\tself:" << local_sName << "("; if( bLegacy )
sCmdName.MakeLower();
s << "\tself:" << sCmdName << "(";
bool bFirstParamIsString = bLegacy && (
sCmdName == "horizalign" ||
sCmdName == "vertalign" ||
sCmdName == "effectclock" ||
sCmdName == "blend" ||
sCmdName == "ztestmode" ||
sCmdName == "cullmode" ||
sCmdName == "playcommand" ||
sCmdName == "queuecommand" ||
sCmdName == "queuemessage" ||
sCmdName == "settext");
for( unsigned i=1; i<cmd.m_vsArgs.size(); i++ ) for( unsigned i=1; i<cmd.m_vsArgs.size(); i++ )
{ {
@@ -875,7 +892,12 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri
if( sArg[0] == '+' ) if( sArg[0] == '+' )
sArg.erase( sArg.begin() ); sArg.erase( sArg.begin() );
if( sArg[0] == '#' ) // HTML color if( i==1 && bFirstParamIsString ) // string literal, legacy only
{
sArg.Replace( "'", "\\'" ); // escape quote
s << "'" << sArg << "'";
}
else if( sArg[0] == '#' ) // HTML color
{ {
RageColor col; // in case FromString fails RageColor col; // in case FromString fails
col.FromString( sArg ); col.FromString( sArg );
+1 -1
View File
@@ -88,7 +88,7 @@ namespace LuaHelpers
// Read the table at the top of the stack back into a vector. // Read the table at the top of the stack back into a vector.
void ReadArrayFromTableB( Lua *L, vector<bool> &aOut ); void ReadArrayFromTableB( Lua *L, vector<bool> &aOut );
void ParseCommandList( lua_State *L, const RString &sCommands, const RString &sName ); void ParseCommandList( lua_State *L, const RString &sCommands, const RString &sName, bool bLegacy );
XNode *GetLuaInformation(); XNode *GetLuaInformation();
+1 -1
View File
@@ -214,7 +214,7 @@ void OptionsList::Load( RString sType, PlayerNumber pn )
RString sRowCommands = LINE(sLineName); RString sRowCommands = LINE(sLineName);
Commands cmds; Commands cmds;
ParseCommands( sRowCommands, cmds ); ParseCommands( sRowCommands, cmds, false );
OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds ); OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds );
if( pHand == NULL ) if( pHand == NULL )
+1 -1
View File
@@ -54,7 +54,7 @@ void ScreenOptionsMaster::Init()
RString sRowCommands = LINE(sLineName); RString sRowCommands = LINE(sLineName);
Commands cmds; Commands cmds;
ParseCommands( sRowCommands, cmds ); ParseCommands( sRowCommands, cmds, false );
OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds ); OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds );
if( pHand == NULL ) if( pHand == NULL )
+1 -1
View File
@@ -1030,7 +1030,7 @@ void ThemeManager::PushMetric( Lua *L, const RString &sMetricsGroup, const RStri
RString sName = ssprintf( "%s::%s", sMetricsGroup.c_str(), sValueName.c_str() ); RString sName = ssprintf( "%s::%s", sMetricsGroup.c_str(), sValueName.c_str() );
if( EndsWith(sValueName, "Command") ) if( EndsWith(sValueName, "Command") )
{ {
LuaHelpers::ParseCommandList( L, sValue, sName ); LuaHelpers::ParseCommandList( L, sValue, sName, false );
} }
else else
{ {
+2 -1
View File
@@ -580,7 +580,8 @@ namespace
if( EndsWith(sName, "Command") ) if( EndsWith(sName, "Command") )
{ {
LuaHelpers::ParseCommandList( L, sExpression, sFile ); // Use legacy parsing
LuaHelpers::ParseCommandList( L, sExpression, sFile, true );
} }
else if( sExpression.size() > 0 && sExpression[0] == '@' ) else if( sExpression.size() > 0 && sExpression[0] == '@' )
{ {