Skip to content

Commit

Permalink
ACTIONSCRIPT: Add support for static functions to avm
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Sep 30, 2019
1 parent 0d785e9 commit 279fdb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/aurora/actionscript/avm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ Variable AVM::getVariable(const Common::UString &name) {
}
}

Variable AVM::callFunction(const Common::UString &name, const std::vector<Variable> &arguments) {
std::map<Common::UString, StaticFunction>::const_iterator iter = _functions.find(name);

if (iter == _functions.end()) {
warning("Function %s does not exist", name.c_str());
return Variable();
}

return (*iter).second(arguments);
}

Variable AVM::createNewObject(const Common::UString &name, std::vector<Variable> arguments) {
Variable variable = getVariable(name);

Expand Down
7 changes: 7 additions & 0 deletions src/aurora/actionscript/avm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ typedef boost::function<Variable(const Common::UString &, const Common::UString
/** Function for registering classes for widgets. */
typedef boost::function<void (const Common::UString &, ObjectPtr)> RegisterClassFunction;

/** Prototype for ActionScript static functions. */
typedef boost::function<Variable(std::vector<Variable>)> StaticFunction;

/** The Action script virtual machine (AVM). */
class AVM {
public:
Expand Down Expand Up @@ -80,6 +83,9 @@ class AVM {
void setVariable(const Common::UString &name, Variable value);
Variable getVariable(const Common::UString &name);

/** Call a specific static function. */
Variable callFunction(const Common::UString &name, const std::vector<Variable> &arguments);

Variable createNewObject(const Common::UString &name,
std::vector<Variable> arguments = std::vector<Variable>());

Expand All @@ -99,6 +105,7 @@ class AVM {

std::vector<std::stack<Variable>> _registers;
std::map<Common::UString, Variable> _variables;
std::map<Common::UString, StaticFunction> _functions;

bool _stopFlag;
Variable _returnValue;
Expand Down

0 comments on commit 279fdb0

Please sign in to comment.