redirecting output of expression evalutation to new report channel

actorid
Marc Zinnschlag 14 years ago
parent 125319c441
commit 861dc6a16e

@ -125,6 +125,11 @@ namespace
code.push_back (Compiler::Generator::segment3 (0, buttons));
}
void opReport (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (58));
}
void opFetchLocalShort (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (21));
@ -516,6 +521,14 @@ namespace Compiler
opMessageBox (code, buttons);
}
void report (CodeContainer& code, Literals& literals, const std::string& message)
{
int index = literals.addString (message);
opPushInt (code, index);
opReport (code);
}
void fetchLocal (CodeContainer& code, char localType, int localIndex)
{
opPushInt (code, localIndex);

@ -81,6 +81,8 @@ namespace Compiler
void message (CodeContainer& code, Literals& literals, const std::string& message,
int buttons);
void report (CodeContainer& code, Literals& literals, const std::string& message);
void fetchLocal (CodeContainer& code, char localType, int localIndex);
void jump (CodeContainer& code, int offset);

@ -30,12 +30,12 @@ namespace Compiler
{
case 'l':
Generator::message (mCode, mLiterals, "%g", 0);
Generator::report (mCode, mLiterals, "%g");
break;
case 'f':
Generator::message (mCode, mLiterals, "%f", 0);
Generator::report (mCode, mLiterals, "%f");
break;
default:

@ -117,5 +117,9 @@ op 55: explicit reference = stack[0]; pop; disable explicit reference
op 56: explicit reference = stack[0]; pop; push 1, if explicit reference is disabled, 0 else
op 57: explicit reference = stack[0]; pop;
replace stack[0] with distance between explicit reference and a reference of ID stack[0]
opcodes 58-33554431 unused
op 58: report string literal index in stack[0];
additional arguments (if any) in stack[n]..stack[1];
n is determined according to the message string
all arguments are removed from stack
opcodes 59-33554431 unused
opcodes 33554432-67108863 reserved for extensions

@ -95,6 +95,7 @@ namespace Interpreter
interpreter.installSegment5 (54, new OpEnableExplicit);
interpreter.installSegment5 (55, new OpDisableExplicit);
interpreter.installSegment5 (56, new OpGetDisabledExplicit);
interpreter.installSegment5 (58, new OpReport);
// script control
interpreter.installSegment5 (46, new OpScriptRunning);
@ -106,4 +107,3 @@ namespace Interpreter
interpreter.installSegment5 (57, new OpGetDistanceExplicit);
}
}

@ -13,30 +13,8 @@
namespace Interpreter
{
class OpMessageBox : public Opcode1
{
public:
virtual void execute (Runtime& runtime, unsigned int arg0)
{
// message
int index = runtime[0].mInteger;
runtime.pop();
std::string message = runtime.getStringLiteral (index);
// buttons
std::vector<std::string> buttons;
for (std::size_t i=0; i<arg0; ++i)
inline std::string formatMessage (const std::string& message, Runtime& runtime)
{
int index = runtime[0].mInteger;
runtime.pop();
buttons.push_back (runtime.getStringLiteral (index));
}
std::reverse (buttons.begin(), buttons.end());
// additional parameters
std::string formattedMessage;
for (std::size_t i=0; i<message.size(); ++i)
@ -92,10 +70,57 @@ namespace Interpreter
}
}
return formattedMessage;
}
class OpMessageBox : public Opcode1
{
public:
virtual void execute (Runtime& runtime, unsigned int arg0)
{
// message
int index = runtime[0].mInteger;
runtime.pop();
std::string message = runtime.getStringLiteral (index);
// buttons
std::vector<std::string> buttons;
for (std::size_t i=0; i<arg0; ++i)
{
int index = runtime[0].mInteger;
runtime.pop();
buttons.push_back (runtime.getStringLiteral (index));
}
std::reverse (buttons.begin(), buttons.end());
// handle additional parameters
std::string formattedMessage = formatMessage (message, runtime);
runtime.getContext().messageBox (formattedMessage, buttons);
}
};
class OpReport : public Opcode0
{
public:
virtual void execute (Runtime& runtime)
{
// message
int index = runtime[0].mInteger;
runtime.pop();
std::string message = runtime.getStringLiteral (index);
// handle additional parameters
std::string formattedMessage = formatMessage (message, runtime);
runtime.getContext().report (formattedMessage);
}
};
class OpMenuMode : public Opcode0
{
public:

Loading…
Cancel
Save