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,6 +13,66 @@
namespace Interpreter
{
inline std::string formatMessage (const std::string& message, Runtime& runtime)
{
std::string formattedMessage;
for (std::size_t i=0; i<message.size(); ++i)
{
char c = message[i];
if (c!='%')
formattedMessage += c;
else
{
++i;
if (i<message.size())
{
c = message[i];
if (c=='S' || c=='s')
{
int index = runtime[0].mInteger;
runtime.pop();
formattedMessage += runtime.getStringLiteral (index);
}
else if (c=='g' || c=='G')
{
Type_Integer value = runtime[0].mInteger;
runtime.pop();
std::ostringstream out;
out << value;
formattedMessage += out.str();
}
else if (c=='f' || c=='F' || c=='.')
{
while (c!='f' && i<message.size())
{
++i;
}
float value = runtime[0].mFloat;
runtime.pop();
std::ostringstream out;
out << value;
formattedMessage += out.str();
}
else if (c=='%')
formattedMessage += "%";
else
{
formattedMessage += "%";
formattedMessage += c;
}
}
}
}
return formattedMessage;
}
class OpMessageBox : public Opcode1
{
public:
@ -36,63 +96,28 @@ namespace Interpreter
std::reverse (buttons.begin(), buttons.end());
// additional parameters
std::string formattedMessage;
// handle additional parameters
std::string formattedMessage = formatMessage (message, runtime);
for (std::size_t i=0; i<message.size(); ++i)
{
char c = message[i];
runtime.getContext().messageBox (formattedMessage, buttons);
}
};
if (c!='%')
formattedMessage += c;
else
{
++i;
if (i<message.size())
{
c = message[i];
if (c=='S' || c=='s')
{
int index = runtime[0].mInteger;
runtime.pop();
formattedMessage += runtime.getStringLiteral (index);
}
else if (c=='g' || c=='G')
{
Type_Integer value = runtime[0].mInteger;
runtime.pop();
std::ostringstream out;
out << value;
formattedMessage += out.str();
}
else if (c=='f' || c=='F' || c=='.')
{
while (c!='f' && i<message.size())
{
++i;
}
float value = runtime[0].mFloat;
runtime.pop();
std::ostringstream out;
out << value;
formattedMessage += out.str();
}
else if (c=='%')
formattedMessage += "%";
else
{
formattedMessage += "%";
formattedMessage += c;
}
}
}
}
class OpReport : public Opcode0
{
public:
runtime.getContext().messageBox (formattedMessage, buttons);
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);
}
};

Loading…
Cancel
Save