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 )
{
Lua *L = LUA->Get();
LuaHelpers::ParseCommandList( L, sCommands, sName );
LuaHelpers::ParseCommandList( L, sCommands, sName, false );
LuaReference *pRet = new LuaReference;
pRet->SetFromStack( L );
LUA->Release( L );
+6 -3
View File
@@ -87,10 +87,13 @@ RString Commands::GetOriginalCommandString() const
return s;
}
void ParseCommands( const RString &sCommands, Commands &vCommandsOut )
void ParseCommands( const RString &sCommands, Commands &vCommandsOut, bool bLegacy )
{
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() );
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 vCommands;
ParseCommands( sCommands, vCommands );
ParseCommands( sCommands, vCommands, false );
return vCommands;
}
+1 -1
View File
@@ -37,7 +37,7 @@ public:
// string. sCommand list is a list of commands separated by ';'.
// 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.
void ParseCommands( const RString &sCmds, Commands &vCmdsOut );
void ParseCommands( const RString &sCmds, Commands &vCmdsOut, bool bLegacy );
Commands ParseCommands( const RString &sCmds );
#endif
+27 -5
View File
@@ -838,7 +838,7 @@ bool LuaHelpers::RunExpression( Lua *L, const RString &sExpression, const RStrin
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;
if( sCommands.size() > 0 && sCommands[0] == '\033' )
@@ -854,18 +854,35 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri
else
{
Commands cmds;
ParseCommands( sCommands, cmds );
ParseCommands( sCommands, cmds, bLegacy );
// Convert cmds to a Lua function
ostringstream s;
s << "return function(self)\n";
if( bLegacy )
s << "\tparent = self:GetParent();\n";
FOREACH_CONST( Command, cmds.v, c )
{
const Command& cmd = (*c);
RString local_sName = cmd.GetName();
s << "\tself:" << local_sName << "(";
RString sCmdName = cmd.GetName();
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++ )
{
@@ -875,7 +892,12 @@ void LuaHelpers::ParseCommandList( Lua *L, const RString &sCommands, const RStri
if( sArg[0] == '+' )
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
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.
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();
+1 -1
View File
@@ -214,7 +214,7 @@ void OptionsList::Load( RString sType, PlayerNumber pn )
RString sRowCommands = LINE(sLineName);
Commands cmds;
ParseCommands( sRowCommands, cmds );
ParseCommands( sRowCommands, cmds, false );
OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds );
if( pHand == NULL )
+1 -1
View File
@@ -54,7 +54,7 @@ void ScreenOptionsMaster::Init()
RString sRowCommands = LINE(sLineName);
Commands cmds;
ParseCommands( sRowCommands, cmds );
ParseCommands( sRowCommands, cmds, false );
OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds );
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() );
if( EndsWith(sValueName, "Command") )
{
LuaHelpers::ParseCommandList( L, sValue, sName );
LuaHelpers::ParseCommandList( L, sValue, sName, false );
}
else
{
+2 -1
View File
@@ -580,7 +580,8 @@ namespace
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] == '@' )
{