38 namespace ActionScript {
87 _currentLength(0), _seeked(0), _script(as) {
252 std::vector<Common::UString> split;
256 for (
size_t i = 1; i < split.size(); ++i) {
257 v = v.
asObject()->getMember(split[i]);
276 warning(
"ActionScript: %s",
"Trace");
318 std::list<Variable> values;
319 for (
int i = 0; i < nArgs.
asNumber(); ++i) {
320 values.push_back(
_stack.top());
343 double numArgs =
_stack.top().asNumber();
346 std::vector<Variable> arguments;
347 for (
int i = 0; i < numArgs; ++i) {
348 arguments.push_back(
_stack.top());
393 if (!
_stack.top().isString())
397 if (!
_stack.top().isObject())
402 std::vector<Common::UString> split;
405 Variable v =
object->getMember(split[0]);
406 for (
size_t i = 1; i < split.size(); ++i) {
407 v = v.
asObject()->getMember(split[i]);
421 object->setMember(name, value);
438 if (
_stack.top().isString())
439 name =
_stack.top().asString();
445 unsigned int numArgs =
_stack.top().asNumber();
448 std::vector<Variable> arguments;
449 for (
unsigned int i = 0; i < numArgs; ++i) {
450 arguments.push_back(
_stack.top());
456 function =
dynamic_cast<Function *
>(
object.get());
458 function =
dynamic_cast<Function *
>(
object->getMember(name).asObject().get());
467 if (function->getPreloadRootFlag()) {
471 if (function->getPreloadThisFlag()) {
478 if (function->getPreloadSuperFlag()) {
483 for (
size_t i = 0; i < arguments.size(); ++i) {
489 _stack.push((*
function)(avm));
498 if (!
_stack.top().isObject())
508 std::vector<Common::UString> slotNames =
object->getSlots();
509 for (
size_t i = 0; i < slotNames.size(); ++i) {
510 _stack.push(slotNames[i]);
522 ObjectPtr scriptObject(
new Object(superClass->getMember(
"prototype").asObject().get()));
523 scriptObject->setMember(
"constructor", superClass);
525 subClass->setMember(
"prototype", scriptObject);
558 for (
int i = 0; i < count; ++i) {
573 bool preloadParentFlag = bitstream.
getBit() != 0;
574 bool preloadRootFlag = bitstream.
getBit() != 0;
575 bool suppressSuperFlag = bitstream.
getBit() != 0;
576 bool preloadSuperFlag = bitstream.
getBit() != 0;
577 bool suppressArgumentsFlag = bitstream.
getBit() != 0;
578 bool preloadArgumentsFlag = bitstream.
getBit() != 0;
579 bool suppressThisFlag = bitstream.
getBit() != 0;
580 bool preloadThisFlag = bitstream.
getBit() != 0;
582 unsigned int reserved = bitstream.
getBits(7);
583 assert(reserved == 0);
585 bool preloadGlobalFlag = bitstream.
getBit() != 0;
587 for (
int i = 0; i < numParams; ++i) {
613 "actionDefineFunction2 \"%s\" %d %d %s %s %s %s %s %s %s %s %s",
614 functionName.
c_str(),
617 preloadParentFlag ?
"true" :
"false",
618 preloadRootFlag ?
"true" :
"false",
619 suppressSuperFlag ?
"true" :
"false",
620 preloadSuperFlag ?
"true" :
"false",
621 suppressArgumentsFlag ?
"true" :
"false",
622 preloadArgumentsFlag ?
"true" :
"false",
623 suppressThisFlag ?
"true" :
"false",
624 preloadThisFlag ?
"true" :
"false",
625 preloadGlobalFlag ?
"true" :
"false" 632 while (length != 0) {
641 length -=
string.size() + 1;
728 assert(reserved == 0);
734 switch (sendVarsMethodId) {
736 sendVarsMethod =
"GET";
739 sendVarsMethod =
"POST";
742 sendVarsMethod =
"None";
755 "actionGetURL2 %s %i %i",
756 sendVarsMethod.
c_str(),
766 for (
int i = 0; i < numParams; ++i) {
778 "actionDefineFunction %s",
801 while (character != 0) {
ASBuffer(Common::SeekableReadStream *as)
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
std::stack< Variable > _stack
Common::SeekableReadStream * _script
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
void setReturnValue(Variable returnValue=Variable())
void debugC(Common::DebugChannel channel, uint32 level, const char *s,...)
void actionStop(AVM &avm)
A class holding an UTF-8 string.
void storeRegister(Variable value, byte index)
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
Utility functions for debug output.
A variable used in the execution context.
"GActionScript", actionscript interpreter
MemoryReadStream * readStream(size_t dataSize)
Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStrea...
void actionDefineFunction()
Variable getVariable(const Common::UString &name)
void fsCommand(const Common::UString &name, const Common::UString &value)
fscommand is used for communicating with the host program.
Implementing the reading stream interfaces for plain memory blocks.
Buffer for handling actionscript byte code.
void actionNewObject(AVM &avm)
uint32 getBit()
Read a bit from the bit stream.
uint32 getBits(size_t n)
Read a multi-bit value from the bit stream.
Variable createNewObject(const Common::UString &name, std::vector< Variable > arguments=std::vector< Variable >())
void actionDefineLocal(AVM &avm)
Exception that provides a stack of explanations.
void actionCallFunction()
Implementation for an actionscript Array class.
void setConstantPool(std::vector< Common::UString > constantPool)
const char * c_str() const
Return the (utf8 encoded) string data.
const Common::UString & asString() const
void actionDefineFunction2()
Function objects for ActionScript.
void actionGetURL(AVM &avm)
bool empty() const
Is the string empty?
FORCEINLINE int16 readSint16LE()
Read a signed 16-bit word stored in little endian (LSB first) order from the stream and return it...
void warning(const char *s,...)
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
void actionToggleQuality()
Seek from the current position of the stream.
FORCEINLINE float readIEEEFloatLE()
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it...
void actionGetURL2(AVM &avm)
void actionGetVariable(AVM &avm)
void actionConstantPool()
void actionPushDuplicate()
An action script variable.
FORCEINLINE double readIEEEDoubleLE()
Read a 64-bit IEEE double stored in little endian (LSB first) order from the stream and return it...
void actionPush(AVM &avm)
uint32 readChar()
Reads the next character from stream and returns it as an unsigned char cast to an uint32...
void actionStoreRegister(AVM &avm)
A template implementing a bit stream for different data memory layouts.
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
void actionCallMethod(AVM &avm)
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
std::vector< Common::UString > _constants
void actionReturn(AVM &avm)
void actionSetVariable(AVM &avm)
boost::shared_ptr< Object > ObjectPtr
Variable getRegister(byte index)
void setVariable(const Common::UString &name, Variable value)
Set a specific variable.
Interface for a seekable & readable data stream.
byte readByte()
Read an unsigned byte from the stream and return it.
Common::UString readString()
The Action script virtual machine (AVM).