move command parsing into LuaHelpers. It's not Actor-specific other
than a few compatibility hacks.
This commit is contained in:
@@ -12,8 +12,6 @@
|
||||
#include "XmlFileUtil.h"
|
||||
#include "LuaManager.h"
|
||||
#include "Foreach.h"
|
||||
#include "Command.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "arch/Dialog/Dialog.h"
|
||||
|
||||
@@ -396,92 +394,10 @@ Actor* ActorUtil::MakeActor( const RString &sPath_, const XNode *pParent, Actor
|
||||
}
|
||||
}
|
||||
|
||||
void ActorUtil::ParseActorCommands( Lua *L, const RString &sCommands, const RString &sName )
|
||||
{
|
||||
RString sLuaFunction;
|
||||
if( sCommands.size() > 0 && sCommands[0] == '\033' )
|
||||
{
|
||||
/* This is a compiled Lua chunk. Just pass it on directly. */
|
||||
sLuaFunction = sCommands;
|
||||
}
|
||||
else if( sCommands.size() > 0 && sCommands[0] == '%' )
|
||||
{
|
||||
sLuaFunction = "return ";
|
||||
sLuaFunction.append( sCommands.begin()+1, sCommands.end() );
|
||||
}
|
||||
else
|
||||
{
|
||||
Commands cmds;
|
||||
ParseCommands( sCommands, cmds );
|
||||
|
||||
//
|
||||
// Convert cmds to a Lua function
|
||||
//
|
||||
ostringstream s;
|
||||
|
||||
s << "return function(self,parent)\n";
|
||||
|
||||
FOREACH_CONST( Command, cmds.v, c )
|
||||
{
|
||||
const Command& cmd = (*c);
|
||||
RString sName = cmd.GetName();
|
||||
TrimLeft( sName );
|
||||
TrimRight( sName );
|
||||
s << "\tself:" << sName << "(";
|
||||
|
||||
bool bFirstParamIsString =
|
||||
sName == "effectclock" ||
|
||||
sName == "playcommand" ||
|
||||
sName == "queuecommand" ||
|
||||
sName == "queuemessage";
|
||||
|
||||
for( unsigned i=1; i<cmd.m_vsArgs.size(); i++ )
|
||||
{
|
||||
RString sArg = cmd.m_vsArgs[i];
|
||||
|
||||
// "+200" -> "200"
|
||||
if( sArg[0] == '+' )
|
||||
sArg.erase( sArg.begin() );
|
||||
|
||||
if( i==1 && bFirstParamIsString ) // string literal
|
||||
{
|
||||
sArg.Replace( "'", "\\'" ); // escape quote
|
||||
s << "'" << sArg << "'";
|
||||
}
|
||||
else if( sArg[0] == '#' ) // HTML color
|
||||
{
|
||||
RageColor c; // in case FromString fails
|
||||
c.FromString( sArg );
|
||||
// c is still valid if FromString fails
|
||||
s << c.r << "," << c.g << "," << c.b << "," << c.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
s << sArg;
|
||||
}
|
||||
|
||||
if( i != cmd.m_vsArgs.size()-1 )
|
||||
s << ",";
|
||||
}
|
||||
s << ")\n";
|
||||
}
|
||||
|
||||
s << "end\n";
|
||||
|
||||
sLuaFunction = s.str();
|
||||
}
|
||||
|
||||
RString sError;
|
||||
if( !LuaHelpers::RunScript( L, sLuaFunction, sName, sError, 1 ) )
|
||||
LOG->Warn( "Compiling \"%s\": %s", sLuaFunction.c_str(), sError.c_str() );
|
||||
|
||||
/* The function is now on the stack. */
|
||||
}
|
||||
|
||||
apActorCommands ActorUtil::ParseActorCommands( const RString &sCommands, const RString &sName )
|
||||
{
|
||||
Lua *L = LUA->Get();
|
||||
ParseActorCommands( L, sCommands, sName );
|
||||
LuaHelpers::ParseCommandList( L, sCommands, sName );
|
||||
LuaReference *pRet = new LuaReference;
|
||||
pRet->SetFromStack( L );
|
||||
LUA->Release( L );
|
||||
|
||||
Reference in New Issue
Block a user