Skip to content

Commit

Permalink
ACTIONSCRIPT: Add Object.registerClass function
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Sep 9, 2018
1 parent bd768f5 commit 6692643
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/aurora/actionscript/avm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* Context for executing ActionScript.
*/

#include <boost/bind.hpp>

#include "src/common/error.h"
#include "src/common/util.h"

Expand All @@ -44,6 +46,7 @@ AVM::AVM() {
_variables["_global"] = ObjectPtr(new Object());
_variables["_root"] = ObjectPtr(new Object());
_variables["Object"] = ObjectPtr(new DummyFunction());
_variables["Object"].asObject()->setMember("registerClass", new NativeFunction(boost::bind(&AVM::registerClass, this, _1), false, false, false));
_variables["Object"].asObject()->setMember("prototype", ObjectPtr(new Object()));
_variables["Array"] = ObjectPtr(new DummyFunction());
_variables["Array"].asObject()->setMember("prototype", ObjectPtr(new Array()));
Expand All @@ -55,6 +58,10 @@ AVM::AVM() {
_variables["TextField"].asObject()->setMember("prototype", ObjectPtr(new TextField()));
}

void AVM::setRegisterClassFunction(RegisterClassFunction registerClass) {
_registerClass = registerClass;
}

void AVM::setFSCommandCallback(FSCommandFunction fscommand) {
_fscommand = fscommand;
}
Expand Down Expand Up @@ -154,6 +161,21 @@ Variable AVM::getReturnValue() {
return _returnValue;
}

Variable AVM::registerClass(AVM &avm) {
Variable name = avm.getRegister(1);
Variable object = avm.getRegister(2);

if (!name.isString())
throw Common::Exception("AVM::registerClass(): name is not a string");
if (!object.isObject())
throw Common::Exception("AVM::registerClass(): value is not an object");

if (_registerClass)
_registerClass(name.asString(), object.asObject());

return Variable();
}

} // End of namespace ActionScript

} // End of namespace Aurora
8 changes: 8 additions & 0 deletions src/aurora/actionscript/avm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ namespace ActionScript {
/** Function for receiving fscommand(). */
typedef boost::function<Variable(const Common::UString &, const Common::UString &)> FSCommandFunction;

/** Function for registering classes for widgets. */
typedef boost::function<void (const Common::UString &, ObjectPtr)> RegisterClassFunction;

/** The Action script virtual machine (AVM). */
class AVM {
public:
AVM();

/** Set a callback for the Object.registerClass() function. */
void setRegisterClassFunction(RegisterClassFunction);
/** Set a callback for the fscommand() function. */
void setFSCommandCallback(FSCommandFunction);

Expand Down Expand Up @@ -75,6 +80,9 @@ class AVM {
Variable getReturnValue();

private:
Variable registerClass(AVM &avm);

RegisterClassFunction _registerClass;
FSCommandFunction _fscommand;

std::vector<Variable> _registers;
Expand Down

0 comments on commit 6692643

Please sign in to comment.