Skip to content

Commit

Permalink
ACTIONSCRIPT: Add function class
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Jun 13, 2018
1 parent 8970296 commit c419cb9
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/aurora/actionscript/function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Function objects for ActionScript.
*/

#include "function.h"

namespace Aurora {

namespace ActionScript {

Function::Function(bool preloadThisFlag, bool preloadSuperFlag) : _preloadThisFlag(preloadThisFlag), _preloadSuperFlag(preloadSuperFlag) {
}

bool Function::preloadThisFlag() {
return _preloadThisFlag;
}

bool Function::preloadSuperFlag() {
return _preloadSuperFlag;
}

ScriptedFunction::ScriptedFunction(Common::SeekableReadStream *as, std::vector<Common::UString> constants,
bool preloadThisFlag, bool preloadSuperFlag) :
Function(preloadThisFlag, preloadSuperFlag), _stream(as), _buffer(as) {
_buffer.setConstantPool(constants);
}

ScriptedFunction::~ScriptedFunction() {
delete _stream;
}

Variable ScriptedFunction::operator()(AVM &avm) {
_buffer.run(avm);
return Variable();
}

} // End of namespace ActionScript

} // End of namespace Aurora
76 changes: 76 additions & 0 deletions src/aurora/actionscript/function.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* xoreos - A reimplementation of BioWare's Aurora engine
*
* xoreos is the legal property of its developers, whose names
* can be found in the AUTHORS file distributed with this source
* distribution.
*
* xoreos is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* xoreos is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xoreos. If not, see <http://www.gnu.org/licenses/>.
*/

/** @file
* Function objects for ActionScript.
*/

#ifndef AURORA_ACTIONSCRIPT_FUNCTION_H
#define AURORA_ACTIONSCRIPT_FUNCTION_H

#include <vector>

#include "src/aurora/actionscript/variable.h"
#include "src/aurora/actionscript/asbuffer.h"

namespace Aurora {

namespace ActionScript {

class Function;

typedef boost::shared_ptr<Function> FunctionPtr;

class Function : public Object {
public:
Function(bool preloadThisFlag, bool preloadSuperFlag);

bool preloadThisFlag();
bool preloadSuperFlag();

virtual Variable operator()(AVM &avm) = 0;

private:
bool _preloadThisFlag;
bool _preloadSuperFlag;
};

class ScriptedFunction : public Function {
public:
ScriptedFunction(
Common::SeekableReadStream *as,
std::vector<Common::UString> constantPool,
bool preloadThisFlag,
bool preloadSuperFlag
);
~ScriptedFunction();

Variable operator()(AVM &avm);

private:
Common::SeekableReadStream *_stream;
ASBuffer _buffer;
};

} // End of namespace ActionScript

} // End of namespace Aurora

#endif // AURORA_ACTIONSCRIPT_FUNCTION_H
2 changes: 2 additions & 0 deletions src/aurora/actionscript/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ noinst_LTLIBRARIES += src/aurora/actionscript/libactionscript.la
src_aurora_actionscript_libactionscript_la_SOURCES =

src_aurora_actionscript_libactionscript_la_SOURCES += \
src/aurora/actionscript/function.h \
src/aurora/actionscript/object.h \
src/aurora/actionscript/variable.h \
src/aurora/actionscript/types.h \
$(EMPTY)

src_aurora_actionscript_libactionscript_la_SOURCES += \
src/aurora/actionscript/function.cpp \
src/aurora/actionscript/object.cpp \
src/aurora/actionscript/variable.cpp \
$(EMPTY)

0 comments on commit c419cb9

Please sign in to comment.