diff --git a/Makefile b/Makefile index c7bd6bf6d..89e66ca6b 100644 --- a/Makefile +++ b/Makefile @@ -869,7 +869,9 @@ EXT_MINISCRIPT_SRCS = \ ext/miniscript/src/miniscript/utilities/Properties.cpp \ ext/miniscript/src/miniscript/utilities/SHA256.cpp \ ext/miniscript/src/miniscript/utilities/StringTools.cpp \ - ext/miniscript/src/miniscript/utilities/StringTokenizer.cpp + ext/miniscript/src/miniscript/utilities/StringTokenizer.cpp \ + ext/miniscript/src/miniscript/utilities/UTF8StringTools.cpp \ + ext/miniscript/src/miniscript/utilities/UTF8StringTokenizer.cpp OPENGL2_RENDERER_LIB_SRCS = \ src/tdme/engine/subsystems/renderer/EngineGL2Renderer.cpp \ diff --git a/Makefile.nmake b/Makefile.nmake index e5e773359..05bd84a00 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -737,7 +737,9 @@ EXT_MINISCRIPT_SRCS = \ ext/miniscript/src/miniscript/utilities/Properties.cpp \ ext/miniscript/src/miniscript/utilities/SHA256.cpp \ ext/miniscript/src/miniscript/utilities/StringTools.cpp \ - ext/miniscript/src/miniscript/utilities/StringTokenizer.cpp + ext/miniscript/src/miniscript/utilities/StringTokenizer.cpp \ + ext/miniscript/src/miniscript/utilities/UTF8StringTools.cpp \ + ext/miniscript/src/miniscript/utilities/UTF8StringTokenizer.cpp EXT_SRCS = \ $(EXT_TINYXML_SRCS) \ diff --git a/ext/miniscript/src/miniscript/miniscript/ApplicationMethods.cpp b/ext/miniscript/src/miniscript/miniscript/ApplicationMethods.cpp index f1aad40be..34d30b463 100644 --- a/ext/miniscript/src/miniscript/miniscript/ApplicationMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/ApplicationMethods.cpp @@ -40,12 +40,12 @@ void ApplicationMethods::registerMethods(MiniScript* miniScript) { // application { // - class ScriptMethodApplicationExecute: public MiniScript::ScriptMethod { + class MethodApplicationExecute: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodApplicationExecute(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodApplicationExecute(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "command", .optional = false, .reference = false, .nullable = false }, }, @@ -55,9 +55,9 @@ void ApplicationMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "application.execute"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string command; - if (MiniScript::getStringValue(argumentValues, 0, command, false) == true) { + if (MiniScript::getStringValue(arguments, 0, command, false) == true) { returnValue.setValue(ApplicationMethods::execute(command)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -65,6 +65,6 @@ void ApplicationMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodApplicationExecute(miniScript)); + miniScript->registerMethod(new MethodApplicationExecute(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/ArrayMethods.cpp b/ext/miniscript/src/miniscript/miniscript/ArrayMethods.cpp index c921e9722..de5889f79 100644 --- a/ext/miniscript/src/miniscript/miniscript/ArrayMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/ArrayMethods.cpp @@ -16,39 +16,39 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { // array methods { // - class ScriptMethodArray: public MiniScript::ScriptMethod { + class MethodArray: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArray(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArray(MiniScript* miniScript): + MiniScript::Method( {}, MiniScript::TYPE_ARRAY ), miniScript(miniScript) {} const string getMethodName() override { - return "array"; + return "Array"; } bool isVariadic() const override { return true; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setType(MiniScript::TYPE_ARRAY); - for (const auto& argumentValue: argumentValues) { - returnValue.pushArrayEntry(argumentValue); + for (const auto& argument: arguments) { + returnValue.pushArrayEntry(argument); } } }; - miniScript->registerMethod(new ScriptMethodArray(miniScript)); + miniScript->registerMethod(new MethodArray(miniScript)); } { // - class ScriptMethodArrayLength: public MiniScript::ScriptMethod { + class MethodArrayLength: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayLength(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayLength(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = false, .nullable = false } }, @@ -56,27 +56,27 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.length"; + return "Array::length"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 1 || argumentValues[0].getType() != MiniScript::TYPE_ARRAY) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_ARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(static_cast(argumentValues[0].getArraySize())); + returnValue.setValue(static_cast(arguments[0].getArraySize())); } } }; - miniScript->registerMethod(new ScriptMethodArrayLength(miniScript)); + miniScript->registerMethod(new MethodArrayLength(miniScript)); } { // - class ScriptMethodArrayPush: public MiniScript::ScriptMethod { + class MethodArrayPush: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayPush(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayPush(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false } }, @@ -84,33 +84,33 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.push"; + return "Array::push"; } bool isVariadic() const override { return true; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // - if (argumentValues.size() < 1 || argumentValues[0].getType() != MiniScript::TYPE_ARRAY) { + if (arguments.size() < 1 || arguments[0].getType() != MiniScript::TYPE_ARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - for (auto i = 1; i < argumentValues.size(); i++) { - argumentValues[0].pushArrayEntry(argumentValues[i]); + for (auto i = 1; i < arguments.size(); i++) { + arguments[0].pushArrayEntry(arguments[i]); } } } }; - miniScript->registerMethod(new ScriptMethodArrayPush(miniScript)); + miniScript->registerMethod(new MethodArrayPush(miniScript)); } { // - class ScriptMethodArrayGet: public MiniScript::ScriptMethod { + class MethodArrayGet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayGet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayGet(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false } @@ -119,29 +119,29 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.get"; + return "Array::get"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if ((argumentValues.size() <= 1 || argumentValues[0].getType() != MiniScript::TYPE_ARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if ((arguments.size() <= 1 || arguments[0].getType() != MiniScript::TYPE_ARRAY) || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue = argumentValues[0].getArrayEntry(index); + returnValue = arguments[0].getArrayEntry(index); } } }; - miniScript->registerMethod(new ScriptMethodArrayGet(miniScript)); + miniScript->registerMethod(new MethodArrayGet(miniScript)); } { // - class ScriptMethodArraySet: public MiniScript::ScriptMethod { + class MethodArraySet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArraySet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArraySet(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false }, @@ -151,29 +151,29 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.set"; + return "Array::set"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if ((argumentValues.size() <= 2 || argumentValues[0].getType() != MiniScript::TYPE_ARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if ((arguments.size() <= 2 || arguments[0].getType() != MiniScript::TYPE_ARRAY) || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].setArrayEntry(index, argumentValues[2]); + arguments[0].setArrayEntry(index, arguments[2]); } } }; - miniScript->registerMethod(new ScriptMethodArraySet(miniScript)); + miniScript->registerMethod(new MethodArraySet(miniScript)); } { // - class ScriptMethodArrayRemove: public MiniScript::ScriptMethod { + class MethodArrayRemove: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayRemove(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayRemove(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false } @@ -182,29 +182,29 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.remove"; + return "Array::remove"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if ((argumentValues.size() < 2 || argumentValues[0].getType() != MiniScript::TYPE_ARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if ((arguments.size() < 2 || arguments[0].getType() != MiniScript::TYPE_ARRAY) || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].removeArrayEntry(index); + arguments[0].removeArrayEntry(index); } } }; - miniScript->registerMethod(new ScriptMethodArrayRemove(miniScript)); + miniScript->registerMethod(new MethodArrayRemove(miniScript)); } { // - class ScriptMethodArrayRemoveOf: public MiniScript::ScriptMethod { + class MethodArrayRemoveOf: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayRemoveOf(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayRemoveOf(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false }, @@ -214,19 +214,19 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.removeOf"; + return "Array::removeOf"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; int64_t beginIndex = 0; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_ARRAY || - MiniScript::getStringValue(argumentValues, 1, stringValue, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, beginIndex, true) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_ARRAY || + MiniScript::getStringValue(arguments, 1, stringValue, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto& array = argumentValues[0]; + auto& array = arguments[0]; for (auto i = beginIndex; i < array.getArraySize(); i++) { auto arrayValue = array.getArrayEntry(i); if (arrayValue.getValueAsString() == stringValue) { @@ -237,16 +237,16 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodArrayRemoveOf(miniScript)); + miniScript->registerMethod(new MethodArrayRemoveOf(miniScript)); } { // - class ScriptMethodArrayIndexOf: public MiniScript::ScriptMethod { + class MethodArrayIndexOf: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayIndexOf(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayIndexOf(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false }, @@ -256,19 +256,19 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.indexOf"; + return "Array::indexOf"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; int64_t beginIndex = 0; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_ARRAY || - MiniScript::getStringValue(argumentValues, 1, stringValue, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, beginIndex, true) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_ARRAY || + MiniScript::getStringValue(arguments, 1, stringValue, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - const auto& array = argumentValues[0]; + const auto& array = arguments[0]; returnValue.setValue(static_cast(-1)); for (auto i = beginIndex; i < array.getArraySize(); i++) { auto arrayValue = array.getArrayEntry(i); @@ -280,36 +280,36 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodArrayIndexOf(miniScript)); + miniScript->registerMethod(new MethodArrayIndexOf(miniScript)); } { // - class ScriptMethodArraySort: public MiniScript::ScriptMethod { + class MethodArraySort: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArraySort(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArraySort(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false }, - { .type = MiniScript::TYPE_STRING, .name = "function", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_FUNCTION_ASSIGNMENT, .name = "function", .optional = false, .reference = false, .nullable = false }, }, MiniScript::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { - return "array.sort"; + return "Array::sort"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string function; - if (argumentValues.size() != 2 || - argumentValues[0].getType() != MiniScript::TYPE_ARRAY || - MiniScript::getStringValue(argumentValues, 1, function, false) == false) { + if (arguments.size() != 2 || + arguments[0].getType() != MiniScript::TYPE_ARRAY || + MiniScript::getStringValue(arguments, 1, function, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { // - auto arrayPtr = argumentValues[0].getArrayPointer(); + auto arrayPtr = arguments[0].getArrayPointer(); if (arrayPtr != nullptr) { class SortClass { private: @@ -318,11 +318,11 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { public: SortClass(MiniScript* miniScript, const string& function): miniScript(miniScript), function(function) { } - bool operator()(const MiniScript::ScriptVariable* a, const MiniScript::ScriptVariable* b) const { - vector sortArgumentValues { *a, *b }; - span sortArgumentValuesSpan(sortArgumentValues); - MiniScript::ScriptVariable sortReturnValue; - miniScript->call(function, sortArgumentValuesSpan, sortReturnValue); + bool operator()(const MiniScript::Variable* a, const MiniScript::Variable* b) const { + vector sortArguments { MiniScript::Variable::createReferenceVariable(a), MiniScript::Variable::createReferenceVariable(b) }; + span sortArgumentsSpan(sortArguments); + MiniScript::Variable sortReturnValue; + miniScript->call(function, sortArgumentsSpan, sortReturnValue); bool result = false; sortReturnValue.getBooleanValue(result, false); return result; @@ -333,16 +333,16 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodArraySort(miniScript)); + miniScript->registerMethod(new MethodArraySort(miniScript)); } { // - class ScriptMethodArrayReverse: public MiniScript::ScriptMethod { + class MethodArrayReverse: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayReverse(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayReverse(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false } }, @@ -350,32 +350,32 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.reverse"; + return "Array::reverse"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 1 || - argumentValues[0].getType() != MiniScript::TYPE_ARRAY) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 1 || + arguments[0].getType() != MiniScript::TYPE_ARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { // - auto arrayPtr = argumentValues[0].getArrayPointer(); + auto arrayPtr = arguments[0].getArrayPointer(); if (arrayPtr != nullptr) { reverse(arrayPtr->begin(), arrayPtr->end()); } } } }; - miniScript->registerMethod(new ScriptMethodArrayReverse(miniScript)); + miniScript->registerMethod(new MethodArrayReverse(miniScript)); } { // - class ScriptMethodArrayClear: public MiniScript::ScriptMethod { + class MethodArrayClear: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodArrayClear(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodArrayClear(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = true, .nullable = false } }, @@ -383,19 +383,123 @@ void ArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "array.clear"; + return "Array::clear"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - int64_t index; - if ((argumentValues.size() < 2 || argumentValues[0].getType() != MiniScript::TYPE_ARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_ARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].clearArray(); + arguments[0].clearArray(); + } + } + }; + miniScript->registerMethod(new MethodArrayClear(miniScript)); + } + { + // + class MethodArrayForEach: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodArrayForEach(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_FUNCTION_ASSIGNMENT, .name = "function", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "cookie", .optional = true, .reference = true, .nullable = false } + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "Array::forEach"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string function; + if ((arguments.size() != 2 && arguments.size() != 3) || + arguments[0].getType() != MiniScript::TYPE_ARRAY || + MiniScript::getStringValue(arguments, 1, function, false) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto arrayPtr = arguments[0].getArrayPointer(); + if (arrayPtr != nullptr) { + for (auto arrayEntry: *arrayPtr) { + vector functionArguments { MiniScript::Variable::createReferenceVariable(arrayEntry) }; + if (arguments.size() == 3) functionArguments.push_back(arguments[2]); + span functionArgumentsSpan(functionArguments); + MiniScript::Variable functionReturnValue; + miniScript->call(function, functionArgumentsSpan, functionReturnValue); + // exit condition + bool result = false; + functionReturnValue.getBooleanValue(result, false); + if (result == true) break; + } + } + } + } + }; + miniScript->registerMethod(new MethodArrayForEach(miniScript)); + } + { + // + class MethodArrayForRange: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodArrayForRange(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_ARRAY, .name = "array", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_FUNCTION_ASSIGNMENT, .name = "function", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "beginIndex", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "count", .optional = true, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "step", .optional = true, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "cookie", .optional = true, .reference = true, .nullable = false } + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "Array::forRange"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string function; + int64_t beginIndex; + int64_t count = -1ll; + int64_t step = 1ll; + if (arguments.size() < 3 || + arguments.size() > 6 || + arguments[0].getType() != MiniScript::TYPE_ARRAY || + MiniScript::getStringValue(arguments, 1, function, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false || + MiniScript::getIntegerValue(arguments, 3, count, true) == false || + MiniScript::getIntegerValue(arguments, 4, step, true) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto arrayPtr = arguments[0].getArrayPointer(); + if (arrayPtr != nullptr) { + auto counter = 0; + for (auto i = beginIndex; i >= 0 && counter < count && i < arrayPtr->size(); i+= step) { + auto arrayEntry = (*arrayPtr)[i]; + vector functionArguments { MiniScript::Variable::createReferenceVariable(arrayEntry) }; + if (arguments.size() == 6) functionArguments.push_back(arguments[5]); + span functionArgumentsSpan(functionArguments); + MiniScript::Variable functionReturnValue; + miniScript->call(function, functionArgumentsSpan, functionReturnValue); + // exit condition + bool result = false; + functionReturnValue.getBooleanValue(result, false); + if (result == true) break; + // + counter++; + } + } } } }; - miniScript->registerMethod(new ScriptMethodArrayClear(miniScript)); + miniScript->registerMethod(new MethodArrayForRange(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp b/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp index b38008e90..215687696 100644 --- a/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp @@ -18,12 +18,12 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { // base methods { // - class ScriptMethodReturn: public MiniScript::ScriptMethod { + class MethodReturn: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodReturn(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodReturn(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = true, .reference = false, .nullable = false } }, @@ -33,36 +33,36 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "return"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { if (miniScript->isFunctionRunning() == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": no function is being executed, return($value) has no effect"); miniScript->startErrorScript(); } else - if (argumentValues.size() == 0) { + if (arguments.size() == 0) { miniScript->stopRunning(); } else - if (argumentValues.size() == 1) { + if (arguments.size() == 1) { auto& scriptState = miniScript->getScriptState(); - scriptState.returnValue = argumentValues[0]; + scriptState.returnValue = arguments[0]; miniScript->stopRunning(); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); } } }; - miniScript->registerMethod(new ScriptMethodReturn(miniScript)); + miniScript->registerMethod(new MethodReturn(miniScript)); } { // - class ScriptMethodEnd: public MiniScript::ScriptMethod { + class MethodEnd: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodEnd(MiniScript* miniScript): MiniScript::ScriptMethod(), miniScript(miniScript) {} + MethodEnd(MiniScript* miniScript): MiniScript::Method(), miniScript(miniScript) {} const string getMethodName() override { return "end"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { if (miniScript->getScriptState().endTypeStack.empty() == true) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": end without block/forXXX/if"); miniScript->startErrorScript(); @@ -89,16 +89,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodEnd(miniScript)); + miniScript->registerMethod(new MethodEnd(miniScript)); } { // - class ScriptMethodForTime: public MiniScript::ScriptMethod { + class MethodForTime: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodForTime(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodForTime(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "time", .optional = false, .reference = false, .nullable = false } } @@ -107,9 +107,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "forTime"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t time; - if (miniScript->getIntegerValue(argumentValues, 0, time) == false) { + if (miniScript->getIntegerValue(arguments, 0, time) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -133,16 +133,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodForTime(miniScript)); + miniScript->registerMethod(new MethodForTime(miniScript)); } { // - class ScriptMethodForCondition: public MiniScript::ScriptMethod { + class MethodForCondition: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodForCondition(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodForCondition(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "condition", .optional = false, .reference = false, .nullable = false } } @@ -151,9 +151,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "forCondition"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { bool booleanValue; - if (miniScript->getBooleanValue(argumentValues, 0, booleanValue, false) == false) { + if (miniScript->getBooleanValue(arguments, 0, booleanValue, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -168,16 +168,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodForCondition(miniScript)); + miniScript->registerMethod(new MethodForCondition(miniScript)); } { // - class ScriptMethodIfCondition: public MiniScript::ScriptMethod { + class MethodIfCondition: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodIfCondition(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodIfCondition(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "condition", .optional = false, .reference = false, .nullable = false } } @@ -186,9 +186,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "if"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { bool booleanValue; - if (miniScript->getBooleanValue(argumentValues, 0, booleanValue, false) == false) { + if (miniScript->getBooleanValue(arguments, 0, booleanValue, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -203,16 +203,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodIfCondition(miniScript)); + miniScript->registerMethod(new MethodIfCondition(miniScript)); } { // - class ScriptMethodElseIfCondition: public MiniScript::ScriptMethod { + class MethodElseIfCondition: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodElseIfCondition(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodElseIfCondition(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "condition", .optional = false, .reference = false, .nullable = false } } @@ -221,14 +221,14 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "elseif"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { bool booleanValue; - if (miniScript->getBooleanValue(argumentValues, 0, booleanValue, false) == false) { + if (miniScript->getBooleanValue(arguments, 0, booleanValue, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else if (miniScript->getScriptState().conditionStack.empty() == true) { - Console::println("ScriptMethodElseIfCondition::executeMethod(): elseif without if"); + Console::println("MethodElseIfCondition::executeMethod(): elseif without if"); miniScript->startErrorScript(); } else { // @@ -244,21 +244,21 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodElseIfCondition(miniScript)); + miniScript->registerMethod(new MethodElseIfCondition(miniScript)); } { // - class ScriptMethodElse: public MiniScript::ScriptMethod { + class MethodElse: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodElse(MiniScript* miniScript): MiniScript::ScriptMethod(), miniScript(miniScript) {} + MethodElse(MiniScript* miniScript): MiniScript::Method(), miniScript(miniScript) {} const string getMethodName() override { return "else"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { if (miniScript->getScriptState().conditionStack.empty() == true) { - Console::println("ScriptMethodElse::executeMethod(): else without if"); + Console::println("MethodElse::executeMethod(): else without if"); miniScript->startErrorScript(); } else { auto conditionStackElement = miniScript->getScriptState().conditionStack.top(); @@ -269,17 +269,17 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodElse(miniScript)); + miniScript->registerMethod(new MethodElse(miniScript)); } // equality { // - class ScriptMethodEquals: public MiniScript::ScriptMethod { + class MethodEquals: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodEquals(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodEquals(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -290,34 +290,34 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "equals"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 2) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 2) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(true); - for (auto i = 1; i < argumentValues.size(); i++) { - if (argumentValues[0].getValueAsString() != argumentValues[i].getValueAsString()) { + for (auto i = 1; i < arguments.size(); i++) { + if (arguments[0].getValueAsString() != arguments[i].getValueAsString()) { returnValue.setValue(false); break; } } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_EQUALS; } }; - miniScript->registerMethod(new ScriptMethodEquals(miniScript)); + miniScript->registerMethod(new MethodEquals(miniScript)); } { // - class ScriptMethodNotEqual: public MiniScript::ScriptMethod { + class MethodNotEqual: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNotEqual(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNotEqual(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -328,35 +328,35 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "notEqual"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 2) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 2) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(true); - for (auto i = 1; i < argumentValues.size(); i++) { - if (argumentValues[0].getValueAsString() == argumentValues[i].getValueAsString()) { + for (auto i = 1; i < arguments.size(); i++) { + if (arguments[0].getValueAsString() == arguments[i].getValueAsString()) { returnValue.setValue(false); break; } } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_NOTEQUAL; } }; - miniScript->registerMethod(new ScriptMethodNotEqual(miniScript)); + miniScript->registerMethod(new MethodNotEqual(miniScript)); } // int methods { // - class ScriptMethodInt: public MiniScript::ScriptMethod { + class MethodInt: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodInt(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodInt(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "int", .optional = false, .reference = false, .nullable = false } }, @@ -366,9 +366,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "int"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t integerValue; - if (MiniScript::getIntegerValue(argumentValues, 0, integerValue, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, integerValue, false) == true) { returnValue.setValue(integerValue); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -376,17 +376,17 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodInt(miniScript)); + miniScript->registerMethod(new MethodInt(miniScript)); } // float methods { // - class ScriptMethodFloat: public MiniScript::ScriptMethod { + class MethodFloat: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodFloat(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodFloat(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "float", .optional = false, .reference = false, .nullable = false } }, @@ -396,9 +396,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "float"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float floatValue; - if (MiniScript::getFloatValue(argumentValues, 0, floatValue, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, floatValue, false) == true) { returnValue.setValue(floatValue); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -406,17 +406,75 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodFloat(miniScript)); + miniScript->registerMethod(new MethodFloat(miniScript)); + } + { + // + class MethodFloatToIntValue: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodFloatToIntValue(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_FLOAT, .name = "float", .optional = false, .reference = false, .nullable = false } + }, + MiniScript::TYPE_INTEGER + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "float.toIntValue"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + float floatValue; + if (MiniScript::getFloatValue(arguments, 0, floatValue, false) == true) { + returnValue.setValue(static_cast(*((uint32_t*)&floatValue))); + } else { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } + } + }; + miniScript->registerMethod(new MethodFloatToIntValue(miniScript)); + } + { + // + class MethodFloatfromIntValue: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodFloatfromIntValue(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_INTEGER, .name = "int", .optional = false, .reference = false, .nullable = false } + }, + MiniScript::TYPE_FLOAT + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "float.fromIntValue"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + int64_t intValue; + if (MiniScript::getIntegerValue(arguments, 0, intValue, false) == true) { + returnValue.setValue(*((float*)&intValue)); + } else { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } + } + }; + miniScript->registerMethod(new MethodFloatfromIntValue(miniScript)); } // { // - class ScriptMethodGreater: public MiniScript::ScriptMethod { + class MethodGreater: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodGreater(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodGreater(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -426,12 +484,12 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "greater"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_STRING) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_STRING) == true) { string stringValueA; string stringValueB; - if (MiniScript::getStringValue(argumentValues, 0, stringValueA, false) == true && - MiniScript::getStringValue(argumentValues, 1, stringValueB, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValueA, false) == true && + MiniScript::getStringValue(arguments, 1, stringValueB, false) == true) { returnValue.setValue(stringValueA > stringValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -440,8 +498,8 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } else { float floatValueA; float floatValueB; - if (MiniScript::getFloatValue(argumentValues, 0, floatValueA, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValueB, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, floatValueA, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValueB, false) == true) { returnValue.setValue(floatValueA > floatValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -449,20 +507,20 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_GREATER; } }; - miniScript->registerMethod(new ScriptMethodGreater(miniScript)); + miniScript->registerMethod(new MethodGreater(miniScript)); } { // - class ScriptMethodGreaterEquals: public MiniScript::ScriptMethod { + class MethodGreaterEquals: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodGreaterEquals(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodGreaterEquals(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -472,12 +530,12 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "greaterEquals"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_STRING) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_STRING) == true) { string stringValueA; string stringValueB; - if (MiniScript::getStringValue(argumentValues, 0, stringValueA, false) == true && - MiniScript::getStringValue(argumentValues, 1, stringValueB, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValueA, false) == true && + MiniScript::getStringValue(arguments, 1, stringValueB, false) == true) { returnValue.setValue(stringValueA >= stringValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -486,8 +544,8 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } else { float floatValueA; float floatValueB; - if (MiniScript::getFloatValue(argumentValues, 0, floatValueA, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValueB, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, floatValueA, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValueB, false) == true) { returnValue.setValue(floatValueA >= floatValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -495,20 +553,20 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_GREATEREQUALS; } }; - miniScript->registerMethod(new ScriptMethodGreaterEquals(miniScript)); + miniScript->registerMethod(new MethodGreaterEquals(miniScript)); } { // - class ScriptMethodLesser: public MiniScript::ScriptMethod { + class MethodLesser: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodLesser(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodLesser(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -518,12 +576,12 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "lesser"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_STRING) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_STRING) == true) { string stringValueA; string stringValueB; - if (MiniScript::getStringValue(argumentValues, 0, stringValueA, false) == true && - MiniScript::getStringValue(argumentValues, 1, stringValueB, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValueA, false) == true && + MiniScript::getStringValue(arguments, 1, stringValueB, false) == true) { returnValue.setValue(stringValueA < stringValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -532,8 +590,8 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } else { float floatValueA; float floatValueB; - if (MiniScript::getFloatValue(argumentValues, 0, floatValueA, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValueB, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, floatValueA, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValueB, false) == true) { returnValue.setValue(floatValueA < floatValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -541,20 +599,20 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_LESSER; } }; - miniScript->registerMethod(new ScriptMethodLesser(miniScript)); + miniScript->registerMethod(new MethodLesser(miniScript)); } { // - class ScriptMethodLesserEquals: public MiniScript::ScriptMethod { + class MethodLesserEquals: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodLesserEquals(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodLesserEquals(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -564,12 +622,12 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "lesserEquals"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_STRING) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_STRING) == true) { string stringValueA; string stringValueB; - if (MiniScript::getStringValue(argumentValues, 0, stringValueA, false) == true && - MiniScript::getStringValue(argumentValues, 1, stringValueB, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValueA, false) == true && + MiniScript::getStringValue(arguments, 1, stringValueB, false) == true) { returnValue.setValue(stringValueA <= stringValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -578,8 +636,8 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } else { float floatValueA; float floatValueB; - if (MiniScript::getFloatValue(argumentValues, 0, floatValueA, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValueB, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, floatValueA, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValueB, false) == true) { returnValue.setValue(floatValueA <= floatValueB); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -587,21 +645,21 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_LESSEREQUALS; } }; - miniScript->registerMethod(new ScriptMethodLesserEquals(miniScript)); + miniScript->registerMethod(new MethodLesserEquals(miniScript)); } // bool methods { // - class ScriptMethodBool: public MiniScript::ScriptMethod { + class MethodBool: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodBool(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodBool(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "bool", .optional = false, .reference = false, .nullable = false } }, @@ -611,9 +669,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "bool"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { bool boolValue; - if (MiniScript::getBooleanValue(argumentValues, 0, boolValue, false) == true) { + if (MiniScript::getBooleanValue(arguments, 0, boolValue, false) == true) { returnValue.setValue(boolValue); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -622,16 +680,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodBool(miniScript)); + miniScript->registerMethod(new MethodBool(miniScript)); } { // - class ScriptMethodNot: public MiniScript::ScriptMethod { + class MethodNot: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNot(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNot(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "bool", .optional = false, .reference = false, .nullable = false } }, @@ -639,9 +697,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "not"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { bool booleanValue = false; - if (MiniScript::getBooleanValue(argumentValues, 0, booleanValue, false) == true) { + if (MiniScript::getBooleanValue(arguments, 0, booleanValue, false) == true) { returnValue.setValue(!booleanValue); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -649,20 +707,20 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { return; } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_NOT; } }; - miniScript->registerMethod(new ScriptMethodNot(miniScript)); + miniScript->registerMethod(new MethodNot(miniScript)); } { // - class ScriptMethodAnd: public MiniScript::ScriptMethod { + class MethodAnd: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAnd(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodAnd(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_BOOLEAN, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -673,16 +731,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "and"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 2) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 2) { returnValue.setValue(false); Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(true); - for (auto i = 0; i < argumentValues.size(); i++) { + for (auto i = 0; i < arguments.size(); i++) { bool booleanValue; - if (MiniScript::getBooleanValue(argumentValues, i, booleanValue, false) == false) { + if (MiniScript::getBooleanValue(arguments, i, booleanValue, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else @@ -693,20 +751,20 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_AND; } }; - miniScript->registerMethod(new ScriptMethodAnd(miniScript)); + miniScript->registerMethod(new MethodAnd(miniScript)); } { // - class ScriptMethodOr: public MiniScript::ScriptMethod { + class MethodOr: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodOr(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodOr(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BOOLEAN, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_BOOLEAN, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -717,16 +775,16 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "or"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 2) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 2) { returnValue.setValue(false); Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(false); - for (auto i = 0; i < argumentValues.size(); i++) { + for (auto i = 0; i < arguments.size(); i++) { bool booleanValue; - if (MiniScript::getBooleanValue(argumentValues, i, booleanValue, false) == false) { + if (MiniScript::getBooleanValue(arguments, i, booleanValue, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else @@ -737,21 +795,21 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_OR; } }; - miniScript->registerMethod(new ScriptMethodOr(miniScript)); + miniScript->registerMethod(new MethodOr(miniScript)); } // get variable { // - class ScriptMethodGetVariable: public MiniScript::ScriptMethod { + class MethodGetVariable: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodGetVariable(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodGetVariable(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "variable", .optional = false, .reference = false, .nullable = false } }, @@ -761,9 +819,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "getVariable"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string variable; - if (MiniScript::getStringValue(argumentValues, 0, variable, false) == true) { + if (MiniScript::getStringValue(arguments, 0, variable, false) == true) { returnValue = miniScript->getVariable(variable, &statement); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -772,17 +830,17 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } }; - miniScript->registerMethod(new ScriptMethodGetVariable(miniScript)); + miniScript->registerMethod(new MethodGetVariable(miniScript)); } // get variable reference { // - class ScriptMethodGetVariableReference: public MiniScript::ScriptMethod { + class MethodGetVariableReference: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodGetVariableReference(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodGetVariableReference(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "variable", .optional = false, .reference = false, .nullable = false } }, @@ -792,9 +850,9 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "getVariableReference"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string variable; - if (MiniScript::getStringValue(argumentValues, 0, variable, false) == true) { + if (MiniScript::getStringValue(arguments, 0, variable, false) == true) { returnValue = miniScript->getVariable(variable, &statement, true); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -805,17 +863,17 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { return true; } }; - miniScript->registerMethod(new ScriptMethodGetVariableReference(miniScript)); + miniScript->registerMethod(new MethodGetVariableReference(miniScript)); } // set variable { // - class ScriptMethodSetVariable: public MiniScript::ScriptMethod { + class MethodSetVariable: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSetVariable(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSetVariable(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "variable", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = false, .reference = false, .nullable = false } @@ -828,32 +886,32 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "setVariable"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string variable; - if (argumentValues.size() != 2 || - MiniScript::getStringValue(argumentValues, 0, variable, false) == false) { + if (arguments.size() != 2 || + MiniScript::getStringValue(arguments, 0, variable, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - miniScript->setVariable(variable, argumentValues[1], &statement); - returnValue = argumentValues[1]; + miniScript->setVariable(variable, arguments[1], &statement); + returnValue = arguments[1]; } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_SET; } }; - miniScript->registerMethod(new ScriptMethodSetVariable(miniScript)); + miniScript->registerMethod(new MethodSetVariable(miniScript)); } // unset variable { // - class ScriptMethodUnsetVariable: public MiniScript::ScriptMethod { + class MethodUnsetVariable: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodUnsetVariable(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodUnsetVariable(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "variable", .optional = false, .reference = false, .nullable = false } }, @@ -865,10 +923,10 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "unsetVariable"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string variable; - if (argumentValues.size() != 1 || - MiniScript::getStringValue(argumentValues, 0, variable, false) == false) { + if (arguments.size() != 1 || + MiniScript::getStringValue(arguments, 0, variable, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -876,16 +934,52 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodUnsetVariable(miniScript)); + miniScript->registerMethod(new MethodUnsetVariable(miniScript)); + } + // set constant + { + // + class MethodSetConstant: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodSetConstant(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "constant", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = false, .reference = false, .nullable = false } + }, + MiniScript::TYPE_PSEUDO_MIXED + ), + miniScript(miniScript) { + // + } + const string getMethodName() override { + return "setConstant"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string constant; + if (arguments.size() != 2 || + MiniScript::getStringValue(arguments, 0, constant, false) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + MiniScript::setConstant(arguments[1]); + miniScript->setVariable(constant, arguments[1], &statement); + returnValue = arguments[1]; + } + } + }; + miniScript->registerMethod(new MethodSetConstant(miniScript)); } { // - class ScriptMethodIncrement: public MiniScript::ScriptMethod { + class MethodIncrement: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodIncrement(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodIncrement(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "variable", .optional = false, .reference = true, .nullable = false }, }, @@ -895,31 +989,31 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "prefixIncrement"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t value; - if (MiniScript::getIntegerValue(argumentValues, 0, value, false) == false) { + if (MiniScript::getIntegerValue(arguments, 0, value, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { ++value; - argumentValues[0].setValue(value); + arguments[0].setValue(value); returnValue.setValue(value); } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_INCREMENT; } }; - miniScript->registerMethod(new ScriptMethodIncrement(miniScript)); + miniScript->registerMethod(new MethodIncrement(miniScript)); } { // - class ScriptMethodDecrement: public MiniScript::ScriptMethod { + class MethodDecrement: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodDecrement(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodDecrement(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "variable", .optional = false, .reference = true, .nullable = false }, }, @@ -929,32 +1023,32 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "prefixDecrement"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t value; - if (MiniScript::getIntegerValue(argumentValues, 0, value, false) == false) { + if (MiniScript::getIntegerValue(arguments, 0, value, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { --value; - argumentValues[0].setValue(value); + arguments[0].setValue(value); returnValue.setValue(value); } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_DECREMENT; } }; - miniScript->registerMethod(new ScriptMethodDecrement(miniScript)); + miniScript->registerMethod(new MethodDecrement(miniScript)); } // { // - class ScriptMethodBitwiseNot: public MiniScript::ScriptMethod { + class MethodBitwiseNot: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodBitwiseNot(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodBitwiseNot(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "value", .optional = false, .reference = false, .nullable = false }, }, @@ -963,29 +1057,29 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "bitwiseNot"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t value; - if (MiniScript::getIntegerValue(argumentValues, 0, value, false) == false) { + if (MiniScript::getIntegerValue(arguments, 0, value, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(~value); } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_BITWISENOT; } }; - miniScript->registerMethod(new ScriptMethodBitwiseNot(miniScript)); + miniScript->registerMethod(new MethodBitwiseNot(miniScript)); } // { - class ScriptMethodBitwiseAnd: public MiniScript::ScriptMethod { + class MethodBitwiseAnd: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodBitwiseAnd(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodBitwiseAnd(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -995,31 +1089,31 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "bitwiseAnd"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t valueA; int64_t valueB; - if (MiniScript::getIntegerValue(argumentValues, 0, valueA, false) == false || - MiniScript::getIntegerValue(argumentValues, 1, valueB, false) == false) { + if (MiniScript::getIntegerValue(arguments, 0, valueA, false) == false || + MiniScript::getIntegerValue(arguments, 1, valueB, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(valueA & valueB); } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_BITWISEAND; } }; - miniScript->registerMethod(new ScriptMethodBitwiseAnd(miniScript)); + miniScript->registerMethod(new MethodBitwiseAnd(miniScript)); } // { - class ScriptMethodBitwiseOr: public MiniScript::ScriptMethod { + class MethodBitwiseOr: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodBitwiseOr(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodBitwiseOr(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -1029,31 +1123,31 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "bitwiseOr"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t valueA; int64_t valueB; - if (MiniScript::getIntegerValue(argumentValues, 0, valueA, false) == false || - MiniScript::getIntegerValue(argumentValues, 1, valueB, false) == false) { + if (MiniScript::getIntegerValue(arguments, 0, valueA, false) == false || + MiniScript::getIntegerValue(arguments, 1, valueB, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(valueA | valueB); } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_BITWISEOR; } }; - miniScript->registerMethod(new ScriptMethodBitwiseOr(miniScript)); + miniScript->registerMethod(new MethodBitwiseOr(miniScript)); } // { - class ScriptMethodBitwiseXor: public MiniScript::ScriptMethod { + class MethodBitwiseXor: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodBitwiseXor(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodBitwiseXor(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_INTEGER, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -1063,22 +1157,22 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "bitwiseXor"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t valueA; int64_t valueB; - if (MiniScript::getIntegerValue(argumentValues, 0, valueA, false) == false || - MiniScript::getIntegerValue(argumentValues, 1, valueB, false) == false) { + if (MiniScript::getIntegerValue(arguments, 0, valueA, false) == false || + MiniScript::getIntegerValue(arguments, 1, valueB, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { returnValue.setValue(valueA ^ valueB); } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_BITWISEXOR; } }; - miniScript->registerMethod(new ScriptMethodBitwiseXor(miniScript)); + miniScript->registerMethod(new MethodBitwiseXor(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/ByteArrayMethods.cpp b/ext/miniscript/src/miniscript/miniscript/ByteArrayMethods.cpp index 77b2b9084..e2c646470 100644 --- a/ext/miniscript/src/miniscript/miniscript/ByteArrayMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/ByteArrayMethods.cpp @@ -16,27 +16,27 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { // array methods { // - class ScriptMethodByteArray: public MiniScript::ScriptMethod { + class MethodByteArray: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArray(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArray(MiniScript* miniScript): + MiniScript::Method( {}, MiniScript::TYPE_BYTEARRAY ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray"; + return "ByteArray"; } bool isVariadic() const override { return true; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setType(MiniScript::TYPE_BYTEARRAY); uint8_t value; - for (const auto& argumentValue: argumentValues) { - if (argumentValue.getByteValue(miniScript, value, &statement) == true) { + for (const auto& argument: arguments) { + if (argument.getByteValue(miniScript, value, &statement) == true) { returnValue.pushByteArrayEntry(value); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -45,16 +45,16 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodByteArray(miniScript)); + miniScript->registerMethod(new MethodByteArray(miniScript)); } { // - class ScriptMethodByteArrayLength: public MiniScript::ScriptMethod { + class MethodByteArrayLength: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArrayLength(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArrayLength(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = false, .nullable = false } }, @@ -62,27 +62,27 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray.length"; + return "ByteArray::length"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 1 || argumentValues[0].getType() != MiniScript::TYPE_BYTEARRAY) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(static_cast(argumentValues[0].getByteArraySize())); + returnValue.setValue(static_cast(arguments[0].getByteArraySize())); } } }; - miniScript->registerMethod(new ScriptMethodByteArrayLength(miniScript)); + miniScript->registerMethod(new MethodByteArrayLength(miniScript)); } { // - class ScriptMethodByteArrayPush: public MiniScript::ScriptMethod { + class MethodByteArrayPush: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArrayPush(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArrayPush(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = true, .nullable = false } }, @@ -90,36 +90,36 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray.push"; + return "ByteArray::push"; } bool isVariadic() const override { return true; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // - if (argumentValues.size() < 1 || argumentValues[0].getType() != MiniScript::TYPE_BYTEARRAY) { + if (arguments.size() < 1 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { uint8_t value; - for (auto i = 1; i < argumentValues.size(); i++) { - if (argumentValues[i].getByteValue(miniScript, value, &statement) == true) { - argumentValues[0].pushByteArrayEntry(value); + for (auto i = 1; i < arguments.size(); i++) { + if (arguments[i].getByteValue(miniScript, value, &statement) == true) { + arguments[0].pushByteArrayEntry(value); } } } } }; - miniScript->registerMethod(new ScriptMethodByteArrayPush(miniScript)); + miniScript->registerMethod(new MethodByteArrayPush(miniScript)); } { // - class ScriptMethodByteArrayGet: public MiniScript::ScriptMethod { + class MethodByteArrayGet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArrayGet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArrayGet(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false } @@ -128,29 +128,29 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray.get"; + return "ByteArray::get"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if ((argumentValues.size() <= 1 || argumentValues[0].getType() != MiniScript::TYPE_BYTEARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if ((arguments.size() <= 1 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(static_cast(argumentValues[0].getByteArrayEntry(index))); + returnValue.setValue(static_cast(arguments[0].getByteArrayEntry(index))); } } }; - miniScript->registerMethod(new ScriptMethodByteArrayGet(miniScript)); + miniScript->registerMethod(new MethodByteArrayGet(miniScript)); } { // - class ScriptMethodByteArraySet: public MiniScript::ScriptMethod { + class MethodByteArraySet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArraySet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArraySet(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false }, @@ -160,32 +160,32 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray.set"; + return "ByteArray::set"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if ((argumentValues.size() <= 2 || argumentValues[0].getType() != MiniScript::TYPE_BYTEARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if ((arguments.size() <= 2 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { uint8_t value; - if (argumentValues[2].getByteValue(miniScript, value, &statement) == true) { - argumentValues[0].setByteArrayEntry(index, value); + if (arguments[2].getByteValue(miniScript, value, &statement) == true) { + arguments[0].setByteArrayEntry(index, value); } } } }; - miniScript->registerMethod(new ScriptMethodByteArraySet(miniScript)); + miniScript->registerMethod(new MethodByteArraySet(miniScript)); } { // - class ScriptMethodByteArrayRemove: public MiniScript::ScriptMethod { + class MethodByteArrayRemove: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArrayRemove(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArrayRemove(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false } @@ -194,29 +194,103 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray.remove"; + return "ByteArray::remove"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if ((argumentValues.size() < 2 || argumentValues[0].getType() != MiniScript::TYPE_BYTEARRAY) || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if ((arguments.size() < 2 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].removeByteArrayEntry(index); + arguments[0].removeByteArrayEntry(index); } } }; - miniScript->registerMethod(new ScriptMethodByteArrayRemove(miniScript)); + miniScript->registerMethod(new MethodByteArrayRemove(miniScript)); } { // - class ScriptMethodByteArrayClear: public MiniScript::ScriptMethod { + class MethodByteArrayAppend: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodByteArrayClear(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodByteArrayAppend(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = true, .nullable = false }, + { .type = MiniScript::TYPE_BYTEARRAY, .name = "other", .optional = false, .reference = true, .nullable = false }, + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "ByteArray::appendByteArray"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 2 || + arguments[0].getType() != MiniScript::TYPE_BYTEARRAY || + arguments[1].getType() != MiniScript::TYPE_BYTEARRAY) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto byteArrayPtr = arguments[0].getByteArrayPointer(); + auto otherByteArrayPtr = arguments[1].getByteArrayPointer(); + if (byteArrayPtr != nullptr && otherByteArrayPtr != nullptr) { + for (const auto value: *otherByteArrayPtr) byteArrayPtr->push_back(value); + } + } + } + }; + miniScript->registerMethod(new MethodByteArrayAppend(miniScript)); + } + { + // + class MethodByteArrayExtract: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodByteArrayExtract(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = true, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "length", .optional = false, .reference = false, .nullable = false }, + }, + MiniScript::TYPE_BYTEARRAY + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "ByteArray::extractByteArray"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + int64_t index; + int64_t length; + if (arguments.size() != 3 || + arguments[0].getType() != MiniScript::TYPE_BYTEARRAY || + MiniScript::getIntegerValue(arguments, 1, index, false) == false || + MiniScript::getIntegerValue(arguments, 2, length, false) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto byteArrayPtr = arguments[0].getByteArrayPointer(); + if (byteArrayPtr != nullptr) { + returnValue.setType(MiniScript::TYPE_BYTEARRAY); + for (auto i = index; i >= 0 && i < byteArrayPtr->size() && i < index + length; i++) returnValue.pushByteArrayEntry((*byteArrayPtr)[i]); + } + } + } + }; + miniScript->registerMethod(new MethodByteArrayExtract(miniScript)); + } + { + // + class MethodByteArrayClear: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodByteArrayClear(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_BYTEARRAY, .name = "bytearray", .optional = false, .reference = true, .nullable = false } }, @@ -224,18 +298,18 @@ void ByteArrayMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "bytearray.clear"; + return "ByteArray::clear"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t index; - if (argumentValues.size() != 1 || argumentValues[0].getType() != MiniScript::TYPE_BYTEARRAY) { + if (arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].clearByteArray(); + arguments[0].clearByteArray(); } } }; - miniScript->registerMethod(new ScriptMethodByteArrayClear(miniScript)); + miniScript->registerMethod(new MethodByteArrayClear(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/ConsoleMethods.cpp b/ext/miniscript/src/miniscript/miniscript/ConsoleMethods.cpp index c092b5d39..48774ad58 100644 --- a/ext/miniscript/src/miniscript/miniscript/ConsoleMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/ConsoleMethods.cpp @@ -16,17 +16,17 @@ void ConsoleMethods::registerMethods(MiniScript* miniScript) { // console { // - class ScriptMethodConsoleLog: public MiniScript::ScriptMethod { + class MethodConsoleLog: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodConsoleLog(MiniScript* miniScript): MiniScript::ScriptMethod(), miniScript(miniScript) {} + MethodConsoleLog(MiniScript* miniScript): MiniScript::Method(), miniScript(miniScript) {} const string getMethodName() override { return "console.log"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - for (const auto& argumentValue: argumentValues) { - Console::print(argumentValue.getValueAsString()); + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + for (const auto& argument: arguments) { + Console::print(argument.getValueAsString()); } Console::println(); } @@ -34,16 +34,16 @@ void ConsoleMethods::registerMethods(MiniScript* miniScript) { return true; } }; - miniScript->registerMethod(new ScriptMethodConsoleLog(miniScript)); + miniScript->registerMethod(new MethodConsoleLog(miniScript)); } { // - class ScriptMethodConsoleDump: public MiniScript::ScriptMethod { + class MethodConsoleDump: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodConsoleDump(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodConsoleDump(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = false, .reference = false, .nullable = false } } @@ -52,15 +52,15 @@ void ConsoleMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "console.dump"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (argumentValues.size() != 1) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 1) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - Console::println(argumentValues[0].getValueAsString(true)); + Console::println(arguments[0].getValueAsString(true)); } } }; - miniScript->registerMethod(new ScriptMethodConsoleDump(miniScript)); + miniScript->registerMethod(new MethodConsoleDump(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/ContextMethods.cpp b/ext/miniscript/src/miniscript/miniscript/ContextMethods.cpp index 969cac651..a29e114ff 100644 --- a/ext/miniscript/src/miniscript/miniscript/ContextMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/ContextMethods.cpp @@ -16,12 +16,12 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { if (miniScript->getContext() == nullptr) return; { // - class ScriptMethodContextScriptHasCallable: public MiniScript::ScriptMethod { + class MethodContextScriptHasCallable: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodContextScriptHasCallable(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodContextScriptHasCallable(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "scriptId", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } @@ -32,11 +32,11 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "context.script.hasCallable"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string scriptId; string callable; - if (MiniScript::getStringValue(argumentValues, 0, scriptId) == false || - MiniScript::getStringValue(argumentValues, 1, callable) == false) { + if (MiniScript::getStringValue(arguments, 0, scriptId) == false || + MiniScript::getStringValue(arguments, 1, callable) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -45,7 +45,7 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { returnValue.setValue(false); } else { auto scriptIdx = script->getFunctionScriptIdx(callable); - if (scriptIdx == MiniScript::SCRIPTIDX_NONE || script->getScripts()[scriptIdx].callable == false) { + if (scriptIdx == MiniScript::SCRIPTIDX_NONE || script->getScripts()[scriptIdx].callableFunction == false) { returnValue.setValue(false); } else { returnValue.setValue(true); @@ -54,16 +54,16 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodContextScriptHasCallable(miniScript)); + miniScript->registerMethod(new MethodContextScriptHasCallable(miniScript)); } { // - class ScriptMethodContextScriptCall: public MiniScript::ScriptMethod { + class MethodContextScriptCall: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodContextScriptCall(MiniScript* miniScript): - ScriptMethod( + MethodContextScriptCall(MiniScript* miniScript): + Method( { { .type = MiniScript::TYPE_STRING, .name = "scriptId", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } @@ -74,11 +74,11 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "context.script.call"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string scriptId; string callable; - if (MiniScript::getStringValue(argumentValues, 0, scriptId) == false || - MiniScript::getStringValue(argumentValues, 1, callable) == false) { + if (MiniScript::getStringValue(arguments, 0, scriptId) == false || + MiniScript::getStringValue(arguments, 1, callable) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -88,22 +88,22 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { miniScript->startErrorScript(); } else { auto scriptIdx = script->getFunctionScriptIdx(callable); - if (scriptIdx == MiniScript::SCRIPTIDX_NONE || script->getScripts()[scriptIdx].callable == false) { + if (scriptIdx == MiniScript::SCRIPTIDX_NONE || script->getScripts()[scriptIdx].callableFunction == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": callable not found: " + callable); miniScript->startErrorScript(); } else { - #if defined (__APPLE__) - // MACOSX currently does not support initializing span using begin and end iterators, - vector callArgumentValues(argumentValues.size() - 2); - for (auto i = 2; i < argumentValues.size(); i++) callArgumentValues[i - 2] = move(argumentValues[i]); + #if defined (__clang__) + // Clang currently does not support initializing span using begin and end iterators, + vector callArguments(arguments.size() - 2); + for (auto i = 2; i < arguments.size(); i++) callArguments[i - 2] = move(arguments[i]); // call - span callArgumentValuesSpan(callArgumentValues); - script->call(scriptIdx, callArgumentValuesSpan, returnValue); + span callArgumentsSpan(callArguments); + script->call(scriptIdx, callArgumentsSpan, returnValue); // move back arguments - for (auto i = 2; i < argumentValues.size(); i++) argumentValues[i] = move(callArgumentValues[i - 2]); + for (auto i = 2; i < arguments.size(); i++) arguments[i] = move(callArguments[i - 2]); #else - span callArgumentValuesSpan(argumentValues.begin() + 2, argumentValues.end()); - script->call(scriptIdx, callArgumentValuesSpan, returnValue); + span callArgumentsSpan(arguments.begin() + 2, arguments.end()); + script->call(scriptIdx, callArgumentsSpan, returnValue); #endif } } @@ -113,16 +113,16 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { return true; } }; - miniScript->registerMethod(new ScriptMethodContextScriptCall(miniScript)); + miniScript->registerMethod(new MethodContextScriptCall(miniScript)); } { // - class ScriptMethodContextScriptLoadScript: public MiniScript::ScriptMethod { + class MethodContextScriptLoadScript: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodContextScriptLoadScript(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodContextScriptLoadScript(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "scriptId", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, @@ -135,15 +135,15 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "context.script.loadScript"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string scriptId; string pathName; string fileName; bool verbose = false; - if (MiniScript::getStringValue(argumentValues, 0, scriptId) == false || - MiniScript::getStringValue(argumentValues, 1, pathName) == false || - MiniScript::getStringValue(argumentValues, 2, fileName) == false || - MiniScript::getBooleanValue(argumentValues, 3, verbose, true) == false) { + if (MiniScript::getStringValue(arguments, 0, scriptId) == false || + MiniScript::getStringValue(arguments, 1, pathName) == false || + MiniScript::getStringValue(arguments, 2, fileName) == false || + MiniScript::getBooleanValue(arguments, 3, verbose, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -166,16 +166,16 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodContextScriptLoadScript(miniScript)); + miniScript->registerMethod(new MethodContextScriptLoadScript(miniScript)); } { // - class ScriptMethodContextScriptRemoveScript: public MiniScript::ScriptMethod { + class MethodContextScriptRemoveScript: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodContextScriptRemoveScript(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodContextScriptRemoveScript(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "scriptId", .optional = false, .reference = false, .nullable = false } }, @@ -185,9 +185,9 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "context.script.removeScript"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string scriptId; - if (MiniScript::getStringValue(argumentValues, 0, scriptId) == false) { + if (MiniScript::getStringValue(arguments, 0, scriptId) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -195,26 +195,26 @@ void ContextMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodContextScriptRemoveScript(miniScript)); + miniScript->registerMethod(new MethodContextScriptRemoveScript(miniScript)); } { // - class ScriptMethodContextScriptGetScriptIds: public MiniScript::ScriptMethod { + class MethodContextScriptGetScriptIds: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodContextScriptGetScriptIds(MiniScript* miniScript): - MiniScript::ScriptMethod({}, MiniScript::TYPE_ARRAY), + MethodContextScriptGetScriptIds(MiniScript* miniScript): + MiniScript::Method({}, MiniScript::TYPE_ARRAY), miniScript(miniScript) {} const string getMethodName() override { return "context.script.getScriptIds"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { auto scriptIds = miniScript->getContext()->getScriptIds(); returnValue.setType(MiniScript::TYPE_ARRAY); for (const auto& scriptId: scriptIds) returnValue.pushArrayEntry(scriptId); } }; - miniScript->registerMethod(new ScriptMethodContextScriptGetScriptIds(miniScript)); + miniScript->registerMethod(new MethodContextScriptGetScriptIds(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/CryptographyMethods.cpp b/ext/miniscript/src/miniscript/miniscript/CryptographyMethods.cpp index a7f830f1b..b6c2d7cc8 100644 --- a/ext/miniscript/src/miniscript/miniscript/CryptographyMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/CryptographyMethods.cpp @@ -22,12 +22,12 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { // base64 { // - class ScriptMethodCryptographyBase64Encode: public MiniScript::ScriptMethod { + class MethodCryptographyBase64Encode: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodCryptographyBase64Encode(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodCryptographyBase64Encode(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false }, }, @@ -37,9 +37,9 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "cryptography.base64.encode"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string value; - if (MiniScript::getStringValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getStringValue(arguments, 0, value, false) == true) { returnValue.setValue(Base64::encode(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -47,16 +47,16 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodCryptographyBase64Encode(miniScript)); + miniScript->registerMethod(new MethodCryptographyBase64Encode(miniScript)); } { // - class ScriptMethodCryptographyBase64Decode: public MiniScript::ScriptMethod { + class MethodCryptographyBase64Decode: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodCryptographyBase64Decode(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodCryptographyBase64Decode(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false }, }, @@ -66,9 +66,9 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "cryptography.base64.decode"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string value; - if (MiniScript::getStringValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getStringValue(arguments, 0, value, false) == true) { returnValue.setValue(Base64::decode(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -76,17 +76,17 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodCryptographyBase64Decode(miniScript)); + miniScript->registerMethod(new MethodCryptographyBase64Decode(miniScript)); } // sha256 { // - class ScriptMethodCryptographySHA256Encode: public MiniScript::ScriptMethod { + class MethodCryptographySHA256Encode: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodCryptographySHA256Encode(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodCryptographySHA256Encode(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false }, }, @@ -96,9 +96,9 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "cryptography.sha256.encode"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string value; - if (MiniScript::getStringValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getStringValue(arguments, 0, value, false) == true) { returnValue.setValue(SHA256::encode(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -106,6 +106,6 @@ void CryptographyMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodCryptographySHA256Encode(miniScript)); + miniScript->registerMethod(new MethodCryptographySHA256Encode(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/FileSystemMethods.cpp b/ext/miniscript/src/miniscript/miniscript/FileSystemMethods.cpp index af806d683..106f93e02 100644 --- a/ext/miniscript/src/miniscript/miniscript/FileSystemMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/FileSystemMethods.cpp @@ -20,12 +20,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { // file system methods { // - class ScriptFileSystemComposeFileName: public MiniScript::ScriptMethod { + class ScriptFileSystemComposeFileName: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemComposeFileName(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false } @@ -38,11 +38,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.composeURI"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { returnValue.setValue(FileSystem::composeURI(pathName, fileName)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -54,12 +54,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetFileSize: public MiniScript::ScriptMethod { + class ScriptFileSystemGetFileSize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetFileSize(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false } @@ -73,11 +73,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getFileSize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { try { returnValue.setValue(static_cast(FileSystem::getFileSize(pathName, fileName))); } catch (Exception& exception) { @@ -93,12 +93,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetContentAsString: public MiniScript::ScriptMethod { + class ScriptFileSystemGetContentAsString: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetContentAsString(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false } @@ -112,11 +112,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getContentAsString"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { try { returnValue.setValue(FileSystem::getContentAsString(pathName, fileName)); } catch (Exception& exception) { @@ -132,12 +132,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemSetContentFromString: public MiniScript::ScriptMethod { + class ScriptFileSystemSetContentFromString: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemSetContentFromString(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, @@ -151,13 +151,13 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.setContentFromString"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; string content; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true && - MiniScript::getStringValue(argumentValues, 2, content, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true && + MiniScript::getStringValue(arguments, 2, content, false) == true) { try { FileSystem::setContentFromString(pathName, fileName, content); returnValue.setValue(true); @@ -175,12 +175,97 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetContentAsStringArray: public MiniScript::ScriptMethod { + class ScriptFileSystemGetContent: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + ScriptFileSystemGetContent(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false } + }, + MiniScript::TYPE_BYTEARRAY, + true + ), + miniScript(miniScript) { + // + } + const string getMethodName() override { + return "filesystem.getContent"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string pathName; + string fileName; + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { + try { + vector content; + FileSystem::getContent(pathName, fileName, content); + returnValue.setValue(content); + } catch (Exception& exception) { + Console::println("An error occurred: " + string(exception.what())); + } + } else { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } + } + }; + miniScript->registerMethod(new ScriptFileSystemGetContent(miniScript)); + } + { + // + class ScriptFileSystemSetContent: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + ScriptFileSystemSetContent(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_BYTEARRAY, .name = "content", .optional = false, .reference = false, .nullable = false }, + }, + MiniScript::TYPE_BOOLEAN + ), + miniScript(miniScript) { + // + } + const string getMethodName() override { + return "filesystem.setContent"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string pathName; + string fileName; + if (arguments.size() == 3 && + MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { + try { + auto contentPtr = arguments[2].getByteArrayPointer(); + if (contentPtr == nullptr) throw ExceptionBase("Empty content byte array provided"); + FileSystem::setContent(pathName, fileName, *contentPtr); + returnValue.setValue(true); + } catch (Exception& exception) { + returnValue.setValue(false); + Console::println("An error occurred: " + string(exception.what())); + } + } else { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } + } + }; + miniScript->registerMethod(new ScriptFileSystemSetContent(miniScript)); + } + { + // + class ScriptFileSystemGetContentAsStringArray: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetContentAsStringArray(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, @@ -194,11 +279,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getContentAsStringArray"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { vector contentAsStringArray; try { FileSystem::getContentAsStringArray(pathName, fileName, contentAsStringArray); @@ -220,12 +305,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemSetContentFromStringArray: public MiniScript::ScriptMethod { + class ScriptFileSystemSetContentFromStringArray: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemSetContentFromStringArray(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, @@ -239,15 +324,15 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.setContentFromStringArray"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (argumentValues.size() == 3 && - MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true && - argumentValues[2].getType() == MiniScript::TYPE_ARRAY) { + if (arguments.size() == 3 && + MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true && + arguments[2].getType() == MiniScript::TYPE_ARRAY) { vector contentAsStringArray; - auto arrayPointer = argumentValues[2].getArrayPointer(); + auto arrayPointer = arguments[2].getArrayPointer(); if (arrayPointer != nullptr) for (const auto arrayEntry: *arrayPointer) contentAsStringArray.push_back(arrayEntry->getValueAsString()); try { FileSystem::setContentFromStringArray(pathName, fileName, contentAsStringArray); @@ -266,12 +351,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemIsPath: public MiniScript::ScriptMethod { + class ScriptFileSystemIsPath: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemIsPath(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "uri", .optional = false, .reference = false, .nullable = false }, }, @@ -284,9 +369,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.isPath"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string uri; - if (MiniScript::getStringValue(argumentValues, 0, uri, false) == true) { + if (MiniScript::getStringValue(arguments, 0, uri, false) == true) { try { returnValue.setValue(FileSystem::isPath(uri)); } catch (Exception& exception) { @@ -302,12 +387,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemIsDrive: public MiniScript::ScriptMethod { + class ScriptFileSystemIsDrive: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemIsDrive(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "uri", .optional = false, .reference = false, .nullable = false }, }, @@ -319,9 +404,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.isDrive"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string uri; - if (MiniScript::getStringValue(argumentValues, 0, uri, false) == true) { + if (MiniScript::getStringValue(arguments, 0, uri, false) == true) { returnValue.setValue(FileSystem::isDrive(uri)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -332,12 +417,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { miniScript->registerMethod(new ScriptFileSystemIsDrive(miniScript)); } { - class ScriptFileSystemFileExists: public MiniScript::ScriptMethod { + class ScriptFileSystemFileExists: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemFileExists(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "uri", .optional = false, .reference = false, .nullable = false }, }, @@ -350,9 +435,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.exists"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string uri; - if (MiniScript::getStringValue(argumentValues, 0, uri, false) == true) { + if (MiniScript::getStringValue(arguments, 0, uri, false) == true) { try { returnValue.setValue(FileSystem::exists(uri)); } catch (Exception& exception) { @@ -368,12 +453,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetCanonicalPath: public MiniScript::ScriptMethod { + class ScriptFileSystemGetCanonicalPath: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetCanonicalPath(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false } @@ -387,11 +472,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getCanonicalURI"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { try { returnValue.setValue(FileSystem::getCanonicalURI(pathName, fileName)); } catch (Exception& exception) { @@ -407,12 +492,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetCurrentWorkingPathName: public MiniScript::ScriptMethod { + class ScriptFileSystemGetCurrentWorkingPathName: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetCurrentWorkingPathName(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( {}, MiniScript::TYPE_STRING, true @@ -423,7 +508,7 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getCurrentWorkingPathName"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { try { returnValue.setValue(FileSystem::getCurrentWorkingPathName()); } catch (Exception& exception) { @@ -435,12 +520,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemChangePath: public MiniScript::ScriptMethod { + class ScriptFileSystemChangePath: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemChangePath(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, }, @@ -452,9 +537,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.changePath"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true) { try { FileSystem::changePath(pathName); returnValue.setValue(true); @@ -472,12 +557,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetFileName: public MiniScript::ScriptMethod { + class ScriptFileSystemGetFileName: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetFileName(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "uri", .optional = false, .reference = false, .nullable = false } }, @@ -489,9 +574,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getFileName"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string uri; - if (MiniScript::getStringValue(argumentValues, 0, uri, false) == true) { + if (MiniScript::getStringValue(arguments, 0, uri, false) == true) { returnValue.setValue(FileSystem::getFileName(uri)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -503,12 +588,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemGetPathName: public MiniScript::ScriptMethod { + class ScriptFileSystemGetPathName: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemGetPathName(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "uri", .optional = false, .reference = false, .nullable = false } }, @@ -520,9 +605,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.getPathName"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string uri; - if (MiniScript::getStringValue(argumentValues, 0, uri, false) == true) { + if (MiniScript::getStringValue(arguments, 0, uri, false) == true) { returnValue.setValue(FileSystem::getPathName(uri)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -534,12 +619,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemRemoveFileExtension: public MiniScript::ScriptMethod { + class ScriptFileSystemRemoveFileExtension: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemRemoveFileExtension(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false } }, @@ -551,9 +636,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.removeFileExtension"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string fileName; - if (MiniScript::getStringValue(argumentValues, 0, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, fileName, false) == true) { returnValue.setValue(FileSystem::removeFileExtension(fileName)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -565,12 +650,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemRemoveFile: public MiniScript::ScriptMethod { + class ScriptFileSystemRemoveFile: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemRemoveFile(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, @@ -583,11 +668,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.removeFile"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; string fileName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getStringValue(arguments, 1, fileName, false) == true) { try { FileSystem::removeFile(pathName, fileName); returnValue.setValue(true); @@ -605,12 +690,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemCreatePath: public MiniScript::ScriptMethod { + class ScriptFileSystemCreatePath: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemCreatePath(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, }, @@ -622,9 +707,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.createPath"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true) { try { FileSystem::createPath(pathName); returnValue.setValue(true); @@ -642,12 +727,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemRemovePath: public MiniScript::ScriptMethod { + class ScriptFileSystemRemovePath: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemRemovePath(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "recursive", .optional = false, .reference = false, .nullable = false }, @@ -660,11 +745,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.removePath"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; bool recursive; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true && - MiniScript::getBooleanValue(argumentValues, 1, recursive, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true && + MiniScript::getBooleanValue(arguments, 1, recursive, false) == true) { try { FileSystem::removePath(pathName, recursive); returnValue.setValue(true); @@ -682,12 +767,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemRename: public MiniScript::ScriptMethod { + class ScriptFileSystemRename: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemRename(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "fileNameFrom", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "fileNameTo", .optional = false, .reference = false, .nullable = false }, @@ -700,11 +785,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.rename"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string fileNameFrom; string fileNameTo; - if (MiniScript::getStringValue(argumentValues, 0, fileNameFrom, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileNameTo, false) == true) { + if (MiniScript::getStringValue(arguments, 0, fileNameFrom, false) == true && + MiniScript::getStringValue(arguments, 1, fileNameTo, false) == true) { try { FileSystem::rename(fileNameFrom, fileNameTo); returnValue.setValue(true); @@ -722,12 +807,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemMove: public MiniScript::ScriptMethod { + class ScriptFileSystemMove: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemMove(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "uriFrom", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "uriTo", .optional = false, .reference = false, .nullable = false }, @@ -740,11 +825,11 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.move"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string fileNameFrom; string fileNameTo; - if (MiniScript::getStringValue(argumentValues, 0, fileNameFrom, false) == true && - MiniScript::getStringValue(argumentValues, 1, fileNameTo, false) == true) { + if (MiniScript::getStringValue(arguments, 0, fileNameFrom, false) == true && + MiniScript::getStringValue(arguments, 1, fileNameTo, false) == true) { try { FileSystem::rename(fileNameFrom, fileNameTo); returnValue.setValue(true); @@ -762,12 +847,12 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { } { // - class ScriptFileSystemList: public MiniScript::ScriptMethod { + class ScriptFileSystemList: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptFileSystemList(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, }, @@ -780,9 +865,9 @@ void FileSystemMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "filesystem.list"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string pathName; - if (MiniScript::getStringValue(argumentValues, 0, pathName, false) == true) { + if (MiniScript::getStringValue(arguments, 0, pathName, false) == true) { try { vector files; FileSystem::list(pathName, files); diff --git a/ext/miniscript/src/miniscript/miniscript/JSONMethods.cpp b/ext/miniscript/src/miniscript/miniscript/JSONMethods.cpp index 0f0369cb8..4badc819f 100644 --- a/ext/miniscript/src/miniscript/miniscript/JSONMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/JSONMethods.cpp @@ -18,12 +18,12 @@ void JSONMethods::registerMethods(MiniScript* miniScript) { // json { // - class ScriptMethodJSONSerialize: public MiniScript::ScriptMethod { + class MethodJSONSerialize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodJSONSerialize(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodJSONSerialize(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = false, .reference = false, .nullable = false }, }, @@ -33,26 +33,26 @@ void JSONMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "json.serialize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // - if (argumentValues.size() != 1) { + if (arguments.size() != 1) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(argumentValues[0].getValueAsString(false, true)); + returnValue.setValue(arguments[0].getValueAsString(false, true)); } } }; - miniScript->registerMethod(new ScriptMethodJSONSerialize(miniScript)); + miniScript->registerMethod(new MethodJSONSerialize(miniScript)); } { // - class ScriptMethodJSONDeserialize: public MiniScript::ScriptMethod { + class MethodJSONDeserialize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodJSONDeserialize(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodJSONDeserialize(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "json", .optional = false, .reference = false, .nullable = false }, }, @@ -62,9 +62,9 @@ void JSONMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "json.deserialize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string json; - if (MiniScript::getStringValue(argumentValues, 0, json, false) == false) { + if (MiniScript::getStringValue(arguments, 0, json, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -80,6 +80,6 @@ void JSONMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodJSONDeserialize(miniScript)); + miniScript->registerMethod(new MethodJSONDeserialize(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/MapMethods.cpp b/ext/miniscript/src/miniscript/miniscript/MapMethods.cpp index 2058750a7..baab8b268 100644 --- a/ext/miniscript/src/miniscript/miniscript/MapMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/MapMethods.cpp @@ -16,33 +16,33 @@ void MapMethods::registerMethods(MiniScript* miniScript) { // map { // - class ScriptMethodMap: public MiniScript::ScriptMethod { + class MethodMap: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMap(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMap(MiniScript* miniScript): + MiniScript::Method( {}, MiniScript::TYPE_MAP ), miniScript(miniScript) {} const string getMethodName() override { - return "map"; + return "Map"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setType(MiniScript::TYPE_MAP); } }; - miniScript->registerMethod(new ScriptMethodMap(miniScript)); + miniScript->registerMethod(new MethodMap(miniScript)); } { // - class ScriptMethodMapSet: public MiniScript::ScriptMethod { + class MethodMapSet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMapSet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMapSet(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false }, @@ -52,31 +52,31 @@ void MapMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "map.set"; + return "Map::set"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() != 3 || - argumentValues[0].getType() != MiniScript::TYPE_MAP || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() != 3 || + arguments[0].getType() != MiniScript::TYPE_MAP || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].setMapEntry(key, argumentValues[2]); + arguments[0].setMapEntry(key, arguments[2]); } } }; - miniScript->registerMethod(new ScriptMethodMapSet(miniScript)); + miniScript->registerMethod(new MethodMapSet(miniScript)); } { // - class ScriptMethodMapHas: public MiniScript::ScriptMethod { + class MethodMapHas: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMapHas(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMapHas(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false } @@ -85,31 +85,31 @@ void MapMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "map.has"; + return "Map::has"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_MAP || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_MAP || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(argumentValues[0].hasMapEntry(key)); + returnValue.setValue(arguments[0].hasMapEntry(key)); } } }; - miniScript->registerMethod(new ScriptMethodMapHas(miniScript)); + miniScript->registerMethod(new MethodMapHas(miniScript)); } { // - class ScriptMethodMapGet: public MiniScript::ScriptMethod { + class MethodMapGet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMapGet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMapGet(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false } @@ -118,31 +118,31 @@ void MapMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "map.get"; + return "Map::get"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_MAP || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_MAP || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue = argumentValues[0].getMapEntry(key); + returnValue = arguments[0].getMapEntry(key); } } }; - miniScript->registerMethod(new ScriptMethodMapGet(miniScript)); + miniScript->registerMethod(new MethodMapGet(miniScript)); } { // - class ScriptMethodMapRemove: public MiniScript::ScriptMethod { + class MethodMapRemove: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMapRemove(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMapRemove(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false } @@ -151,31 +151,31 @@ void MapMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "map.remove"; + return "Map::remove"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_MAP || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_MAP || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].removeMapEntry(key); + arguments[0].removeMapEntry(key); } } }; - miniScript->registerMethod(new ScriptMethodMapRemove(miniScript)); + miniScript->registerMethod(new MethodMapRemove(miniScript)); } { // - class ScriptMethodMapGetKeys: public MiniScript::ScriptMethod { + class MethodMapGetKeys: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMapGetKeys(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMapGetKeys(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = false, .nullable = false }, }, @@ -183,16 +183,16 @@ void MapMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "map.getKeys"; + return "Map::getKeys"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // - if (argumentValues.size() != 1 || - argumentValues[0].getType() != MiniScript::TYPE_MAP) { + if (arguments.size() != 1 || + arguments[0].getType() != MiniScript::TYPE_MAP) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto keys = argumentValues[0].getMapKeys(); + auto keys = arguments[0].getMapKeys(); returnValue.setType(MiniScript::TYPE_ARRAY); for (const auto& key: keys) { returnValue.pushArrayEntry(key); @@ -200,16 +200,16 @@ void MapMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodMapGetKeys(miniScript)); + miniScript->registerMethod(new MethodMapGetKeys(miniScript)); } { // - class ScriptMethodMapGetValues: public MiniScript::ScriptMethod { + class MethodMapGetValues: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMapGetValues(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMapGetValues(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = false, .nullable = false }, }, @@ -217,16 +217,16 @@ void MapMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "map.getValues"; + return "Map::getValues"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // - if (argumentValues.size() != 1 || - argumentValues[0].getType() != MiniScript::TYPE_MAP) { + if (arguments.size() != 1 || + arguments[0].getType() != MiniScript::TYPE_MAP) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto values = argumentValues[0].getMapValues(); + auto values = arguments[0].getMapValues(); returnValue.setType(MiniScript::TYPE_ARRAY); for (const auto value: values) { returnValue.pushArrayEntry(*value); @@ -234,6 +234,80 @@ void MapMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodMapGetValues(miniScript)); + miniScript->registerMethod(new MethodMapGetValues(miniScript)); + } + { + // + class MethodMapClear: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodMapClear(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = true, .nullable = false } + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "Map::clear"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_MAP) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + arguments[0].clearMap(); + } + } + }; + miniScript->registerMethod(new MethodMapClear(miniScript)); + } + { + // + class MethodMapForEach: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodMapForEach(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_MAP, .name = "map", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_FUNCTION_ASSIGNMENT, .name = "function", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "cookie", .optional = true, .reference = true, .nullable = false } + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "Map::forEach"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string function; + if ((arguments.size() != 2 && arguments.size() != 3) || + arguments[0].getType() != MiniScript::TYPE_MAP || + MiniScript::getStringValue(arguments, 1, function, false) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto mapPtr = arguments[0].getMapPointer(); + if (mapPtr != nullptr) { + for (const auto& [mapKey, mapValue]: *mapPtr) { + vector functionArguments { MiniScript::Variable(mapKey), MiniScript::Variable::createReferenceVariable(mapValue) }; + if (arguments.size() == 3) functionArguments.push_back(arguments[2]); + span functionArgumentsSpan(functionArguments); + MiniScript::Variable functionReturnValue; + miniScript->call(function, functionArgumentsSpan, functionReturnValue); + // exit condition + bool result = false; + functionReturnValue.getBooleanValue(result, false); + if (result == true) break; + } + } + } + } + }; + miniScript->registerMethod(new MethodMapForEach(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/MathMethods.cpp b/ext/miniscript/src/miniscript/miniscript/MathMethods.cpp index 24ae2ab1e..facac523b 100644 --- a/ext/miniscript/src/miniscript/miniscript/MathMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/MathMethods.cpp @@ -14,20 +14,20 @@ using miniscript::math::Math; using miniscript::miniscript::MiniScript; using miniscript::utilities::Console; -void MathMethods::registerDataType(MiniScript::ScriptDataType* scriptDataType) { - scriptDataTypes.push_back(scriptDataType); +void MathMethods::registerDataType(MiniScript::DataType* dataType) { + dataTypes.push_back(dataType); } void MathMethods::registerMethods() { // operator methods { // - class ScriptMethodAdd: public MiniScript::ScriptMethod { + class MethodAdd: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAdd(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodAdd(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false } @@ -38,23 +38,23 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "add"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - miniScript->getMathMethods()->add(argumentValues, returnValue, statement); + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + miniScript->getMathMethods()->add(arguments, returnValue, statement); } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_ADDITION; } }; - miniScript->registerMethod(new ScriptMethodAdd(miniScript)); + miniScript->registerMethod(new MethodAdd(miniScript)); } { // - class ScriptMethodSub: public MiniScript::ScriptMethod { + class MethodSub: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSub(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSub(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false } @@ -65,23 +65,23 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "sub"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - miniScript->getMathMethods()->sub(argumentValues, returnValue, statement); + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + miniScript->getMathMethods()->sub(arguments, returnValue, statement); } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_SUBTRACTION; } }; - miniScript->registerMethod(new ScriptMethodSub(miniScript)); + miniScript->registerMethod(new MethodSub(miniScript)); } { // - class ScriptMethodMul: public MiniScript::ScriptMethod { + class MethodMul: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMul(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodMul(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false } @@ -92,23 +92,23 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "mul"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - miniScript->getMathMethods()->mul(argumentValues, returnValue, statement); + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + miniScript->getMathMethods()->mul(arguments, returnValue, statement); } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_MULTIPLICATION; } }; - miniScript->registerMethod(new ScriptMethodMul(miniScript)); + miniScript->registerMethod(new MethodMul(miniScript)); } { // - class ScriptMethodDiv: public MiniScript::ScriptMethod { + class MethodDiv: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodDiv(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodDiv(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "a", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "b", .optional = false, .reference = false } @@ -119,22 +119,22 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "div"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - miniScript->getMathMethods()->div(argumentValues, returnValue, statement); + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + miniScript->getMathMethods()->div(arguments, returnValue, statement); } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_DIVISION; } }; - miniScript->registerMethod(new ScriptMethodDiv(miniScript)); + miniScript->registerMethod(new MethodDiv(miniScript)); } { // - class ScriptMethodMod: public MiniScript::ScriptMethod { + class MethodMod: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMod(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodMod(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "range", .optional = false, .reference = false }, @@ -144,12 +144,12 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "mod"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_INTEGER) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_INTEGER) == true) { int64_t value; int64_t range; - if (MiniScript::getIntegerValue(argumentValues, 0, value, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, range, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, value, false) == true && + MiniScript::getIntegerValue(arguments, 1, range, false) == true) { returnValue.setValue(Math::mod(value, range)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -158,8 +158,8 @@ void MathMethods::registerMethods() { } else { float value; float range; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true && - MiniScript::getFloatValue(argumentValues, 1, range, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true && + MiniScript::getFloatValue(arguments, 1, range, false) == true) { returnValue.setValue(Math::mod(value, range)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -167,84 +167,84 @@ void MathMethods::registerMethods() { } } } - MiniScript::ScriptOperator getOperator() const override { + MiniScript::Operator getOperator() const override { return MiniScript::OPERATOR_MODULO; } }; - miniScript->registerMethod(new ScriptMethodMod(miniScript)); + miniScript->registerMethod(new MethodMod(miniScript)); } // constants { // - class ScriptMethodPi: public MiniScript::ScriptMethod { + class MethodPI: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodPi(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} + MethodPI(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "math.PI"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setValue(Math::PI); } }; - miniScript->registerMethod(new ScriptMethodPi(miniScript)); + miniScript->registerMethod(new MethodPI(miniScript)); } { // - class ScriptMethodEpsilon: public MiniScript::ScriptMethod { + class MethodEPSILON: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodEpsilon(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} + MethodEPSILON(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "math.EPSILON"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setValue(Math::EPSILON); } }; - miniScript->registerMethod(new ScriptMethodEpsilon(miniScript)); + miniScript->registerMethod(new MethodEPSILON(miniScript)); } { // - class ScriptMethodDEG2RAD: public MiniScript::ScriptMethod { + class MethodDEG2RAD: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodDEG2RAD(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} + MethodDEG2RAD(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "math.DEG2RAD"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setValue(Math::DEG2RAD); } }; - miniScript->registerMethod(new ScriptMethodDEG2RAD(miniScript)); + miniScript->registerMethod(new MethodDEG2RAD(miniScript)); } { // - class ScriptMethodG: public MiniScript::ScriptMethod { + class MethodG: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodG(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} + MethodG(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "math.G"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setValue(Math::G); } }; - miniScript->registerMethod(new ScriptMethodG(miniScript)); + miniScript->registerMethod(new MethodG(miniScript)); } { // - class ScriptMethodAcos: public MiniScript::ScriptMethod { + class MethodAcos: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAcos(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodAcos(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, }, @@ -252,9 +252,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.acos"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float x; - if (MiniScript::getFloatValue(argumentValues, 0, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, x, false) == true) { returnValue.setValue(Math::acos(x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -262,15 +262,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodAcos(miniScript)); + miniScript->registerMethod(new MethodAcos(miniScript)); } { // - class ScriptMethodAsin: public MiniScript::ScriptMethod { + class MethodAsin: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAsin(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodAsin(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, }, @@ -278,9 +278,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.asin"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float x; - if (MiniScript::getFloatValue(argumentValues, 0, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, x, false) == true) { returnValue.setValue(Math::asin(x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -288,15 +288,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodAsin(miniScript)); + miniScript->registerMethod(new MethodAsin(miniScript)); } { // - class ScriptMethodAtan: public MiniScript::ScriptMethod { + class MethodAtan: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAtan(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodAtan(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, }, @@ -304,9 +304,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.atan"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float x; - if (MiniScript::getFloatValue(argumentValues, 0, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, x, false) == true) { returnValue.setValue(Math::atan(x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -314,15 +314,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodAtan(miniScript)); + miniScript->registerMethod(new MethodAtan(miniScript)); } { // - class ScriptMethodAtan2: public MiniScript::ScriptMethod { + class MethodAtan2: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAtan2(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodAtan2(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "y", .optional = false, .reference = false }, { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, @@ -331,11 +331,11 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.atan2"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float y; float x; - if (MiniScript::getFloatValue(argumentValues, 0, y, false) == true && - MiniScript::getFloatValue(argumentValues, 1, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, y, false) == true && + MiniScript::getFloatValue(arguments, 1, x, false) == true) { returnValue.setValue(Math::atan2(y, x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -343,15 +343,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodAtan2(miniScript)); + miniScript->registerMethod(new MethodAtan2(miniScript)); } { // - class ScriptMethodTan: public MiniScript::ScriptMethod { + class MethodTan: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodTan(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodTan(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, }, @@ -359,9 +359,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.tan"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float x; - if (MiniScript::getFloatValue(argumentValues, 0, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, x, false) == true) { returnValue.setValue(Math::tan(x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -369,15 +369,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodTan(miniScript)); + miniScript->registerMethod(new MethodTan(miniScript)); } { // - class ScriptMethodCos: public MiniScript::ScriptMethod { + class MethodCos: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodCos(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodCos(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, }, @@ -385,9 +385,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.cos"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float x; - if (MiniScript::getFloatValue(argumentValues, 0, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, x, false) == true) { returnValue.setValue(Math::cos(x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -395,15 +395,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodCos(miniScript)); + miniScript->registerMethod(new MethodCos(miniScript)); } { // - class ScriptMethodSin: public MiniScript::ScriptMethod { + class MethodSin: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSin(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodSin(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "x", .optional = false, .reference = false }, }, @@ -411,9 +411,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.sin"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float x; - if (MiniScript::getFloatValue(argumentValues, 0, x, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, x, false) == true) { returnValue.setValue(Math::sin(x)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -421,15 +421,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodSin(miniScript)); + miniScript->registerMethod(new MethodSin(miniScript)); } { // - class ScriptMethodFloor: public MiniScript::ScriptMethod { + class MethodFloor: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodFloor(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodFloor(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false }, }, @@ -437,9 +437,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.floor"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float value; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true) { returnValue.setValue(Math::floor(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -447,15 +447,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodFloor(miniScript)); + miniScript->registerMethod(new MethodFloor(miniScript)); } { // - class ScriptMethodCeil: public MiniScript::ScriptMethod { + class MethodCeil: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodCeil(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodCeil(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false }, }, @@ -463,9 +463,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.ceil"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float value; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true) { returnValue.setValue(Math::ceil(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -473,15 +473,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodCeil(miniScript)); + miniScript->registerMethod(new MethodCeil(miniScript)); } { // - class ScriptMethodRound: public MiniScript::ScriptMethod { + class MethodRound: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodRound(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodRound(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false }, }, @@ -489,9 +489,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.round"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float value; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true) { returnValue.setValue(Math::round(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -499,15 +499,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodRound(miniScript)); + miniScript->registerMethod(new MethodRound(miniScript)); } { // - class ScriptMethodSqrt: public MiniScript::ScriptMethod { + class MethodSqrt: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSqrt(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodSqrt(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false }, }, @@ -515,9 +515,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.sqrt"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float value; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true) { returnValue.setValue(Math::sqrt(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -525,31 +525,31 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodSqrt(miniScript)); + miniScript->registerMethod(new MethodSqrt(miniScript)); } { // - class ScriptMethodRandom: public MiniScript::ScriptMethod { + class MethodRandom: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodRandom(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} + MethodRandom(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "math.random"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setValue(Math::random()); } }; - miniScript->registerMethod(new ScriptMethodRandom(miniScript)); + miniScript->registerMethod(new MethodRandom(miniScript)); } { // - class ScriptMethodExp: public MiniScript::ScriptMethod { + class MethodExp: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodExp(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodExp(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "power", .optional = false, .reference = false }, }, @@ -557,9 +557,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.exp"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float power; - if (MiniScript::getFloatValue(argumentValues, 0, power, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, power, false) == true) { returnValue.setValue(Math::exp(power)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -567,15 +567,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodExp(miniScript)); + miniScript->registerMethod(new MethodExp(miniScript)); } { // - class ScriptMethodLog: public MiniScript::ScriptMethod { + class MethodLog: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodLog(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodLog(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_FLOAT, .name = "value", .optional = false, .reference = false }, }, @@ -583,9 +583,9 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.log"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float value; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true) { returnValue.setValue(Math::log(value)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -593,15 +593,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodLog(miniScript)); + miniScript->registerMethod(new MethodLog(miniScript)); } { // - class ScriptMethodSign: public MiniScript::ScriptMethod { + class MethodSign: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSign(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodSign(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, }, @@ -610,13 +610,13 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.sign"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValue; float floatValue; - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && MiniScript::getFloatValue(argumentValues, 0, floatValue, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && MiniScript::getFloatValue(arguments, 0, floatValue, false) == true) { returnValue.setValue(Math::sign(floatValue)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValue, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValue, false) == true) { returnValue.setValue(Math::sign(intValue)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -624,15 +624,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodSign(miniScript)); + miniScript->registerMethod(new MethodSign(miniScript)); } { // - class ScriptMethodSquare: public MiniScript::ScriptMethod { + class MethodSquare: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSquare(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodSquare(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, }, @@ -641,13 +641,13 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.square"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValue; float floatValue; - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && MiniScript::getFloatValue(argumentValues, 0, floatValue, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && MiniScript::getFloatValue(arguments, 0, floatValue, false) == true) { returnValue.setValue(Math::square(floatValue)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValue, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValue, false) == true) { returnValue.setValue(Math::square(intValue)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -655,15 +655,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodSquare(miniScript)); + miniScript->registerMethod(new MethodSquare(miniScript)); } { // - class ScriptMethodMin: public MiniScript::ScriptMethod { + class MethodMin: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMin(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodMin(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value1", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value2", .optional = false, .reference = false }, @@ -673,22 +673,22 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.min"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValue1; int64_t intValue2; float floatValue1; float floatValue2; - if (argumentValues.size() != 2) { + if (arguments.size() != 2) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && - MiniScript::getFloatValue(argumentValues, 0, floatValue1, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValue2, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && + MiniScript::getFloatValue(arguments, 0, floatValue1, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValue2, false) == true) { returnValue.setValue(Math::min(floatValue1, floatValue2)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValue1, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, intValue2, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValue1, false) == true && + MiniScript::getIntegerValue(arguments, 1, intValue2, false) == true) { returnValue.setValue(Math::min(intValue1, intValue2)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -696,15 +696,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodMin(miniScript)); + miniScript->registerMethod(new MethodMin(miniScript)); } { // - class ScriptMethodMax: public MiniScript::ScriptMethod { + class MethodMax: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMax(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodMax(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value1", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value2", .optional = false, .reference = false }, @@ -714,22 +714,22 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.max"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValue1; int64_t intValue2; float floatValue1; float floatValue2; - if (argumentValues.size() != 2) { + if (arguments.size() != 2) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && - MiniScript::getFloatValue(argumentValues, 0, floatValue1, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValue2, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && + MiniScript::getFloatValue(arguments, 0, floatValue1, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValue2, false) == true) { returnValue.setValue(Math::max(floatValue1, floatValue2)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValue1, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, intValue2, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValue1, false) == true && + MiniScript::getIntegerValue(arguments, 1, intValue2, false) == true) { returnValue.setValue(Math::max(intValue1, intValue2)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -737,15 +737,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodMax(miniScript)); + miniScript->registerMethod(new MethodMax(miniScript)); } { // - class ScriptMethodAbs: public MiniScript::ScriptMethod { + class MethodAbs: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAbs(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodAbs(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, }, @@ -754,13 +754,13 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.abs"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValue; float floatValue; - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && MiniScript::getFloatValue(argumentValues, 0, floatValue, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && MiniScript::getFloatValue(arguments, 0, floatValue, false) == true) { returnValue.setValue(Math::abs(floatValue)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValue, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValue, false) == true) { returnValue.setValue(Math::abs(intValue)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -768,15 +768,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodAbs(miniScript)); + miniScript->registerMethod(new MethodAbs(miniScript)); } { // - class ScriptMethodClamp: public MiniScript::ScriptMethod { + class MethodClamp: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodClamp(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodClamp(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "min", .optional = false, .reference = false }, @@ -787,26 +787,26 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.clamp"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValueA; int64_t intValueB; int64_t intValueC; float floatValueA; float floatValueB; float floatValueC; - if (argumentValues.size() != 3) { + if (arguments.size() != 3) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && - MiniScript::getFloatValue(argumentValues, 0, floatValueA, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValueB, false) == true && - MiniScript::getFloatValue(argumentValues, 2, floatValueC, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && + MiniScript::getFloatValue(arguments, 0, floatValueA, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValueB, false) == true && + MiniScript::getFloatValue(arguments, 2, floatValueC, false) == true) { returnValue.setValue(Math::clamp(floatValueA, floatValueB, floatValueC)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValueA, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, intValueB, false) == true && - MiniScript::getIntegerValue(argumentValues, 2, intValueC, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValueA, false) == true && + MiniScript::getIntegerValue(arguments, 1, intValueB, false) == true && + MiniScript::getIntegerValue(arguments, 2, intValueC, false) == true) { returnValue.setValue(Math::clamp(intValueA, intValueB, intValueC)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -814,15 +814,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodClamp(miniScript)); + miniScript->registerMethod(new MethodClamp(miniScript)); } { // - class ScriptMethodPow: public MiniScript::ScriptMethod { + class MethodPow: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodPow(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodPow(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "base", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "power", .optional = false, .reference = false }, @@ -832,22 +832,22 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.pow"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t intValueBase; int64_t intValuePower; float floatValueBase; float floatValuePower; - if (argumentValues.size() != 2) { + if (arguments.size() != 2) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true && - MiniScript::getFloatValue(argumentValues, 0, floatValueBase, false) == true && - MiniScript::getFloatValue(argumentValues, 1, floatValuePower, false) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true && + MiniScript::getFloatValue(arguments, 0, floatValueBase, false) == true && + MiniScript::getFloatValue(arguments, 1, floatValuePower, false) == true) { returnValue.setValue(Math::pow(floatValueBase, floatValuePower)); } else - if (MiniScript::getIntegerValue(argumentValues, 0, intValueBase, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, intValuePower, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, intValueBase, false) == true && + MiniScript::getIntegerValue(arguments, 1, intValuePower, false) == true) { returnValue.setValue(static_cast(Math::pow(intValueBase, intValuePower))); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -855,15 +855,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodPow(miniScript)); + miniScript->registerMethod(new MethodPow(miniScript)); } { // - class ScriptMethodMod: public MiniScript::ScriptMethod { + class MethodMod: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodMod(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodMod(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "range", .optional = false, .reference = false }, @@ -873,12 +873,12 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.mod"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_INTEGER) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_INTEGER) == true) { int64_t value; int64_t range; - if (MiniScript::getIntegerValue(argumentValues, 0, value, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, range, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, value, false) == true && + MiniScript::getIntegerValue(arguments, 1, range, false) == true) { returnValue.setValue(Math::mod(value, range)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -887,8 +887,8 @@ void MathMethods::registerMethods() { } else { float value; float range; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true && - MiniScript::getFloatValue(argumentValues, 1, range, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true && + MiniScript::getFloatValue(arguments, 1, range, false) == true) { returnValue.setValue(Math::mod(value, range)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -897,15 +897,15 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodMod(miniScript)); + miniScript->registerMethod(new MethodMod(miniScript)); } { // - class ScriptMethodAbsMod: public MiniScript::ScriptMethod { + class MethodAbsMod: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodAbsMod(MiniScript* miniScript): MiniScript::ScriptMethod( + MethodAbsMod(MiniScript* miniScript): MiniScript::Method( { { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "value", .optional = false, .reference = false }, { .type = MiniScript::TYPE_PSEUDO_NUMBER, .name = "range", .optional = false, .reference = false }, @@ -915,12 +915,12 @@ void MathMethods::registerMethods() { const string getMethodName() override { return "math.absmod"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_INTEGER) == true) { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if (MiniScript::hasType(arguments, MiniScript::TYPE_INTEGER) == true) { int64_t value; int64_t range; - if (MiniScript::getIntegerValue(argumentValues, 0, value, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, range, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, value, false) == true && + MiniScript::getIntegerValue(arguments, 1, range, false) == true) { returnValue.setValue(Math::absmod(value, range)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -929,8 +929,8 @@ void MathMethods::registerMethods() { } else { float value; float range; - if (MiniScript::getFloatValue(argumentValues, 0, value, false) == true && - MiniScript::getFloatValue(argumentValues, 1, range, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, value, false) == true && + MiniScript::getFloatValue(arguments, 1, range, false) == true) { returnValue.setValue(Math::absmod(value, range)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -939,27 +939,27 @@ void MathMethods::registerMethods() { } } }; - miniScript->registerMethod(new ScriptMethodAbsMod(miniScript)); + miniScript->registerMethod(new MethodAbsMod(miniScript)); } } -void MathMethods::mul(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) { - if (argumentValues.size() != 2) { +void MathMethods::mul(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) { + if (arguments.size() != 2) { Console::println("mul(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation("mul")); miniScript->startErrorScript(); // return; } // custom data types - for (const auto scriptDataType: scriptDataTypes) { - if (scriptDataType->mul(miniScript, argumentValues, returnValue, statement) == true) return; + for (const auto dataType: dataTypes) { + if (dataType->mul(miniScript, arguments, returnValue, statement) == true) return; } // float - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true) { float a; float b; - if (MiniScript::getFloatValue(argumentValues, 0, a, false) == true && - MiniScript::getFloatValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, a, false) == true && + MiniScript::getFloatValue(arguments, 1, b, false) == true) { returnValue.setValue(a * b); // return; @@ -973,8 +973,8 @@ void MathMethods::mul(const span& argumentValues, Mi // int int64_t a; int64_t b; - if (MiniScript::getIntegerValue(argumentValues, 0, a, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, a, false) == true && + MiniScript::getIntegerValue(arguments, 1, b, false) == true) { returnValue.setValue(a * b); // return; @@ -987,23 +987,23 @@ void MathMethods::mul(const span& argumentValues, Mi } } -void MathMethods::div(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) { - if (argumentValues.size() != 2) { +void MathMethods::div(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) { + if (arguments.size() != 2) { Console::println("div(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation("div")); miniScript->startErrorScript(); // return; } // custom data types - for (const auto scriptDataType: scriptDataTypes) { - if (scriptDataType->div(miniScript, argumentValues, returnValue, statement) == true) return; + for (const auto dataType: dataTypes) { + if (dataType->div(miniScript, arguments, returnValue, statement) == true) return; } // float - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true) { float a; float b; - if (MiniScript::getFloatValue(argumentValues, 0, a, false) == true && - MiniScript::getFloatValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, a, false) == true && + MiniScript::getFloatValue(arguments, 1, b, false) == true) { returnValue.setValue(a / b); // return; @@ -1017,8 +1017,8 @@ void MathMethods::div(const span& argumentValues, Mi // int int64_t a; int64_t b; - if (MiniScript::getIntegerValue(argumentValues, 0, a, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, a, false) == true && + MiniScript::getIntegerValue(arguments, 1, b, false) == true) { returnValue.setValue(a / b); // return; @@ -1031,32 +1031,32 @@ void MathMethods::div(const span& argumentValues, Mi } } -void MathMethods::add(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) { - if (argumentValues.size() != 2) { +void MathMethods::add(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) { + if (arguments.size() != 2) { Console::println(miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation("add")); miniScript->startErrorScript(); return; } // string concatenation - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_STRING) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_STRING) == true) { string result; - for (auto i = 0; i < argumentValues.size(); i++) { - result+= argumentValues[i].getValueAsString(); + for (auto i = 0; i < arguments.size(); i++) { + result+= arguments[i].getValueAsString(); } returnValue.setValue(result); // return; } // custom data types - for (const auto scriptDataType: scriptDataTypes) { - if (scriptDataType->add(miniScript, argumentValues, returnValue, statement) == true) return; + for (const auto dataType: dataTypes) { + if (dataType->add(miniScript, arguments, returnValue, statement) == true) return; } // float - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true) { float a; float b; - if (MiniScript::getFloatValue(argumentValues, 0, a, false) == true && - MiniScript::getFloatValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, a, false) == true && + MiniScript::getFloatValue(arguments, 1, b, false) == true) { returnValue.setValue(a + b); // return; @@ -1070,8 +1070,8 @@ void MathMethods::add(const span& argumentValues, Mi // int int64_t a; int64_t b; - if (MiniScript::getIntegerValue(argumentValues, 0, a, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, a, false) == true && + MiniScript::getIntegerValue(arguments, 1, b, false) == true) { returnValue.setValue(a + b); // return; @@ -1085,23 +1085,23 @@ void MathMethods::add(const span& argumentValues, Mi } -void MathMethods::sub(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) { - if (argumentValues.size() != 2) { +void MathMethods::sub(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) { + if (arguments.size() != 2) { Console::println("sub(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation("sub")); miniScript->startErrorScript(); // return; } // custom data types - for (const auto scriptDataType: scriptDataTypes) { - if (scriptDataType->sub(miniScript, argumentValues, returnValue, statement) == true) return; + for (const auto dataType: dataTypes) { + if (dataType->sub(miniScript, arguments, returnValue, statement) == true) return; } // float - if (MiniScript::hasType(argumentValues, MiniScript::TYPE_FLOAT) == true) { + if (MiniScript::hasType(arguments, MiniScript::TYPE_FLOAT) == true) { float a; float b; - if (MiniScript::getFloatValue(argumentValues, 0, a, false) == true && - MiniScript::getFloatValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getFloatValue(arguments, 0, a, false) == true && + MiniScript::getFloatValue(arguments, 1, b, false) == true) { returnValue.setValue(a - b); // return; @@ -1115,8 +1115,8 @@ void MathMethods::sub(const span& argumentValues, Mi // int int64_t a; int64_t b; - if (MiniScript::getIntegerValue(argumentValues, 0, a, false) == true && - MiniScript::getIntegerValue(argumentValues, 1, b, false) == true) { + if (MiniScript::getIntegerValue(arguments, 0, a, false) == true && + MiniScript::getIntegerValue(arguments, 1, b, false) == true) { returnValue.setValue(a - b); // return; diff --git a/ext/miniscript/src/miniscript/miniscript/MathMethods.h b/ext/miniscript/src/miniscript/miniscript/MathMethods.h index 3fe6d1a19..df45135c6 100644 --- a/ext/miniscript/src/miniscript/miniscript/MathMethods.h +++ b/ext/miniscript/src/miniscript/miniscript/MathMethods.h @@ -22,10 +22,10 @@ class miniscript::miniscript::MathMethods { MathMethods(MiniScript* miniScript): miniScript(miniScript) {} /** - * Register script data type - * @param scriptDataType script data type + * Register data type + * @param dataType data type */ - void registerDataType(MiniScript::ScriptDataType* scriptDataType); + void registerDataType(MiniScript::DataType* dataType); /** * Register methods @@ -34,38 +34,38 @@ class miniscript::miniscript::MathMethods { /** * Multiply - * @param argumentValues argument values + * @param arguments argument values * @param returnValue return value * @param statement statement */ - void mul(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement); + void mul(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement); /** * Division - * @param argumentValues argument values + * @param arguments argument values * @param returnValue return value * @param statement statement */ - void div(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement); + void div(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement); /** * Addition - * @param argumentValues argument values + * @param arguments argument values * @param returnValue return value * @param statement statement */ - void add(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement); + void add(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement); /** * Subtraction - * @param argumentValues argument values + * @param arguments argument values * @param returnValue return value * @param statement statement */ - void sub(const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement); + void sub(const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement); private: MiniScript* miniScript; - vector scriptDataTypes; + vector dataTypes; }; diff --git a/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp b/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp index 2c9dd62f9..b8769dbe4 100644 --- a/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp +++ b/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp @@ -96,19 +96,26 @@ using miniscript::utilities::SHA256; using miniscript::utilities::Time; const string MiniScript::OPERATOR_CHARS = "+-!~/%<>=&^|"; -vector MiniScript::scriptDataTypes; +vector MiniScript::dataTypes; const string MiniScript::METHOD_SCRIPTCALL = "script.call"; const string MiniScript::METHOD_ENABLENAMEDCONDITION = "script.enableNamedCondition"; const string MiniScript::METHOD_DISABLENAMEDCONDITION = "script.disableNamedCondition"; -const string MiniScript::ScriptVariable::CLASSNAME_NONE = ""; -const string MiniScript::ScriptVariable::CLASSNAME_STRING = "string"; -const string MiniScript::ScriptVariable::CLASSNAME_BYTEARRAY = "bytearray"; -const string MiniScript::ScriptVariable::CLASSNAME_ARRAY = "array"; -const string MiniScript::ScriptVariable::CLASSNAME_MAP = "map"; -const string MiniScript::ScriptVariable::CLASSNAME_SET = "set"; +const string MiniScript::Variable::TYPENAME_NONE = ""; +const string MiniScript::Variable::TYPENAME_NULL = "Null"; +const string MiniScript::Variable::TYPENAME_BOOLEAN = "Boolean"; +const string MiniScript::Variable::TYPENAME_INTEGER = "Integer"; +const string MiniScript::Variable::TYPENAME_FLOAT = "Float"; +const string MiniScript::Variable::TYPENAME_FUNCTION = "Function"; +const string MiniScript::Variable::TYPENAME_NUMBER = "Number"; +const string MiniScript::Variable::TYPENAME_MIXED = "Mixed"; +const string MiniScript::Variable::TYPENAME_STRING = "String"; +const string MiniScript::Variable::TYPENAME_BYTEARRAY = "ByteArray"; +const string MiniScript::Variable::TYPENAME_ARRAY = "Array"; +const string MiniScript::Variable::TYPENAME_MAP = "Map"; +const string MiniScript::Variable::TYPENAME_SET = "Set"; -const vector MiniScript::ScriptMethod::CONTEXTFUNCTIONS_ALL = {}; +const vector MiniScript::Method::CONTEXTFUNCTIONS_ALL = {}; const string MiniScript::getBaseClass() { @@ -133,7 +140,8 @@ const vector MiniScript::getTranspilationUnits() { "src/miniscript/miniscript/SetMethods.cpp", "src/miniscript/miniscript/StringMethods.cpp", "src/miniscript/miniscript/TimeMethods.cpp", - "src/miniscript/miniscript/XMLMethods.cpp" + "src/miniscript/miniscript/XMLMethods.cpp", + "src/miniscript/miniscript/MiniScript.cpp" }; } @@ -143,38 +151,38 @@ MiniScript::MiniScript() { } MiniScript::~MiniScript() { - for (const auto& [scriptMethodId, scriptMethod]: scriptMethods) delete scriptMethod; - for (const auto& [scriptStateMachineStateId, scriptStateMachineState]: scriptStateMachineStates) delete scriptStateMachineState; + for (const auto& [methodName, method]: this->methods) delete method; + for (const auto& [stateMachineStateId, stateMachineState]: this->stateMachineStates) delete stateMachineState; while (scriptStateStack.empty() == false) popScriptState(); } -void MiniScript::registerStateMachineState(ScriptStateMachineState* state) { - auto scriptStateMachineStateIt = scriptStateMachineStates.find(state->getId()); - if (scriptStateMachineStateIt != scriptStateMachineStates.end()) { +void MiniScript::registerStateMachineState(StateMachineState* state) { + auto stateMachineStateIt = stateMachineStates.find(state->getId()); + if (stateMachineStateIt != stateMachineStates.end()) { Console::println("MiniScript::registerStateMachineState(): " + scriptFileName + ": state with id + " + to_string(state->getId()) + ", name " + state->getName() + " already registered."); return; } - scriptStateMachineStates[state->getId()] = state; + stateMachineStates[state->getId()] = state; } void MiniScript::initializeNative() { } -void MiniScript::registerMethod(ScriptMethod* scriptMethod) { - auto scriptMethodsIt = scriptMethods.find(scriptMethod->getMethodName()); - if (scriptMethodsIt != scriptMethods.end()) { - Console::println("MiniScript::registerMethod(): " + scriptFileName + ": method with name " + scriptMethod->getMethodName() + " already registered."); +void MiniScript::registerMethod(Method* method) { + auto methodsIt = methods.find(method->getMethodName()); + if (methodsIt != methods.end()) { + Console::println("MiniScript::registerMethod(): " + scriptFileName + ": method with name " + method->getMethodName() + " already registered."); return; } - scriptMethods[scriptMethod->getMethodName()] = scriptMethod; + methods[method->getMethodName()] = method; } -void MiniScript::registerDataType(ScriptDataType* scriptDataType) { - scriptDataType->setType(TYPE_PSEUDO_CUSTOM_DATATYPES + scriptDataTypes.size()); - scriptDataTypes.push_back(scriptDataType); +void MiniScript::registerDataType(DataType* dataType) { + dataType->setType(TYPE_PSEUDO_CUSTOM_DATATYPES + dataTypes.size()); + dataTypes.push_back(dataType); } -void MiniScript::executeScriptLine() { +void MiniScript::executeNextStatement() { auto& scriptState = getScriptState(); if (scriptState.scriptIdx == SCRIPTIDX_NONE || scriptState.statementIdx == STATEMENTIDX_NONE || scriptState.running == false) return; // @@ -191,7 +199,7 @@ void MiniScript::executeScriptLine() { if (VERBOSE == true) Console::println("MiniScript::executeScriptLine(): " + getStatementInformation(statement)); // - auto returnValue = executeScriptStatement(syntaxTree, statement); + auto returnValue = executeStatement(syntaxTree, statement); // scriptState.statementIdx++; @@ -202,8 +210,7 @@ void MiniScript::executeScriptLine() { } } -bool MiniScript::parseScriptStatement(const string_view& executableStatement, string_view& methodName, vector& arguments, const ScriptStatement& statement, string& accessObjectMemberStatement) { - // TODO: improve me! +bool MiniScript::parseStatement(const string_view& executableStatement, string_view& methodName, vector& arguments, const Statement& statement, string& accessObjectMemberStatement) { if (VERBOSE == true) Console::println("MiniScript::parseScriptStatement(): " + getStatementInformation(statement) + ": '" + string(executableStatement) + "'"); string_view objectMemberAccessObject; string_view objectMemberAccessMethod; @@ -223,6 +230,7 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st // for (auto i = executableStatementStartIdx; i < executableStatement.size(); i++) { auto c = executableStatement[i]; + // quotes if (squareBracketCount == 0 && curlyBracketCount == 0 && ((c == '"' || c == '\'') && lc != '\\')) { if (bracketCount == 1) { if (quote == '\0') { @@ -246,6 +254,7 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } } } else + // quotes end if (quote != '\0') { if (bracketCount == 1) { quotedArgumentEnd = i; @@ -257,17 +266,18 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } } } else { - // TODO: guess I need to check here too for balance of [ and ] also + // no quotes, handle ( if (c == '(') { bracketCount++; if (bracketCount > 1) { if (argumentStart == string::npos) { - argumentStart = i + 1; + argumentStart = i; } else { argumentEnd = i; } } } else + // ) if (c == ')') { bracketCount--; if (bracketCount == 0) { @@ -287,12 +297,13 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } } else { if (argumentStart == string::npos) { - argumentStart = i + 1; + argumentStart = i; } else { argumentEnd = i; } } } else + // [ if (c == '[' && curlyBracketCount == 0) { if (squareBracketCount == 0) { if (argumentStart == string::npos) { @@ -303,6 +314,7 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } squareBracketCount++; } else + // ] if (c == ']' && curlyBracketCount == 0) { squareBracketCount--; if (squareBracketCount == 0) { @@ -313,6 +325,7 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } } } else + // { if (c == '{') { if (curlyBracketCount == 0) { if (argumentStart == string::npos) { @@ -323,6 +336,7 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } curlyBracketCount++; } else + // } if (c == '}') { curlyBracketCount--; if (curlyBracketCount == 0) { @@ -333,6 +347,7 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st } } } else + // , if (squareBracketCount == 0 && curlyBracketCount == 0) { if (c == ',') { if (bracketCount == 1) { @@ -374,11 +389,11 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st // lc = c; } - // + // extract method name if (methodStart != string::npos && methodEnd != string::npos) { methodName = StringTools::viewTrim(string_view(&executableStatement[methodStart], methodEnd - methodStart + 1)); } - // + // handle object member access and generate internal.script.evaluateMemberAccess call if (objectMemberAccess == true) { // construct executable statement and arguments string_view evaluateMemberAccessMethodName; @@ -463,27 +478,28 @@ bool MiniScript::parseScriptStatement(const string_view& executableStatement, st return true; } -MiniScript::ScriptVariable MiniScript::executeScriptStatement(const ScriptSyntaxTreeNode& syntaxTree, const ScriptStatement& statement) { +MiniScript::Variable MiniScript::executeStatement(const SyntaxTreeNode& syntaxTree, const Statement& statement) { if (VERBOSE == true) Console::println("MiniScript::executeScriptStatement(): " + getStatementInformation(statement) + "': " + syntaxTree.value.getValueAsString() + "(" + getArgumentsAsString(syntaxTree.arguments) + ")"); // return on literal or empty syntaxTree - if (syntaxTree.type != ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && syntaxTree.type != ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION) { + if (syntaxTree.type != SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && + syntaxTree.type != SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION) { return initializeVariable(syntaxTree.value); } // - vector argumentValues; - ScriptVariable returnValue; + vector arguments; + Variable returnValue; // construct argument values for (const auto& argument: syntaxTree.arguments) { switch (argument.type) { - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { - argumentValues.push_back(initializeVariable(argument.value)); + arguments.push_back(initializeVariable(argument.value)); break; } - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { - argumentValues.push_back(executeScriptStatement(argument, statement)); + arguments.push_back(executeStatement(argument, statement)); break; } default: @@ -495,32 +511,26 @@ MiniScript::ScriptVariable MiniScript::executeScriptStatement(const ScriptSyntax Console::println("MiniScript::executeScriptStatement(): '" + getStatementInformation(statement) + ": " + syntaxTree.value.getValueAsString() + "(" + getArgumentsAsString(syntaxTree.arguments) + ")"); } // try first user functions - if (syntaxTree.method == nullptr) { - auto method = syntaxTree.value.getValueAsString(); - auto scriptFunctionsIt = scriptFunctions.find(method); - if (scriptFunctionsIt != scriptFunctions.end()) { - auto scriptIdx = scriptFunctionsIt->second; - // call - span argumentValuesSpan(argumentValues); - call(scriptIdx, argumentValuesSpan, returnValue); - // - return returnValue; - } else { - Console::println(getStatementInformation(statement) + ": unknown function '" + string(syntaxTree.value.getValueAsString()) + "'"); - startErrorScript(); - } - } else { + if (syntaxTree.type == SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION) { + auto scriptIdx = syntaxTree.getFunctionScriptIdx(); + // call + span argumentsSpan(arguments); + call(scriptIdx, argumentsSpan, returnValue); + // + return returnValue; + } else + if (syntaxTree.type == SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD) { // try methods next - auto scriptMethod = syntaxTree.method; + auto method = syntaxTree.getMethod(); // validate arguments { auto argumentIdx = 0; - for (const auto& argumentType: scriptMethod->getArgumentTypes()) { + for (const auto& argumentType: method->getArgumentTypes()) { auto argumentOk = true; // nullable and NULL argument if (argumentType.nullable == true && - argumentIdx >= 0 && argumentIdx < argumentValues.size() && - argumentValues[argumentIdx].getType() == TYPE_NULL) { + argumentIdx >= 0 && argumentIdx < arguments.size() && + arguments[argumentIdx].getType() == TYPE_NULL) { argumentOk = true; } else { // otherwise check the argument @@ -530,25 +540,25 @@ MiniScript::ScriptVariable MiniScript::executeScriptStatement(const ScriptSyntax case TYPE_BOOLEAN: { bool booleanValue; - argumentOk = getBooleanValue(argumentValues, argumentIdx, booleanValue, argumentType.optional); + argumentOk = getBooleanValue(arguments, argumentIdx, booleanValue, argumentType.optional); } break; case TYPE_INTEGER: { int64_t integerValue; - argumentOk = getIntegerValue(argumentValues, argumentIdx, integerValue, argumentType.optional); + argumentOk = getIntegerValue(arguments, argumentIdx, integerValue, argumentType.optional); } break; case TYPE_FLOAT: { float floatValue; - argumentOk = getFloatValue(argumentValues, argumentIdx, floatValue, argumentType.optional); + argumentOk = getFloatValue(arguments, argumentIdx, floatValue, argumentType.optional); } break; case TYPE_PSEUDO_NUMBER: { float floatValue; - argumentOk = getFloatValue(argumentValues, argumentIdx, floatValue, argumentType.optional); + argumentOk = getFloatValue(arguments, argumentIdx, floatValue, argumentType.optional); break; } case TYPE_PSEUDO_MIXED: @@ -559,48 +569,48 @@ MiniScript::ScriptVariable MiniScript::executeScriptStatement(const ScriptSyntax case TYPE_STRING: { string stringValue; - argumentOk = getStringValue(argumentValues, argumentIdx, stringValue, argumentType.optional); + argumentOk = getStringValue(arguments, argumentIdx, stringValue, argumentType.optional); } break; case TYPE_BYTEARRAY: { argumentOk = - argumentIdx < 0 || argumentIdx >= argumentValues.size()? + argumentIdx < 0 || argumentIdx >= arguments.size()? argumentType.optional: - argumentValues[argumentIdx].getType() == TYPE_BYTEARRAY; + arguments[argumentIdx].getType() == TYPE_BYTEARRAY; break; } case TYPE_ARRAY: { argumentOk = - argumentIdx < 0 || argumentIdx >= argumentValues.size()? + argumentIdx < 0 || argumentIdx >= arguments.size()? argumentType.optional: - argumentValues[argumentIdx].getType() == TYPE_ARRAY; + arguments[argumentIdx].getType() == TYPE_ARRAY; break; } case TYPE_MAP: { argumentOk = - argumentIdx < 0 || argumentIdx >= argumentValues.size()? + argumentIdx < 0 || argumentIdx >= arguments.size()? argumentType.optional: - argumentValues[argumentIdx].getType() == TYPE_MAP; + arguments[argumentIdx].getType() == TYPE_MAP; break; } case TYPE_SET: { argumentOk = - argumentIdx < 0 || argumentIdx >= argumentValues.size()? + argumentIdx < 0 || argumentIdx >= arguments.size()? argumentType.optional: - argumentValues[argumentIdx].getType() == TYPE_SET; + arguments[argumentIdx].getType() == TYPE_SET; break; } default: { // custom data types argumentOk = - argumentIdx < 0 || argumentIdx >= argumentValues.size()? + argumentIdx < 0 || argumentIdx >= arguments.size()? argumentType.optional: - argumentValues[argumentIdx].getType() == argumentType.type; + arguments[argumentIdx].getType() == argumentType.type; break; } @@ -610,29 +620,29 @@ MiniScript::ScriptVariable MiniScript::executeScriptStatement(const ScriptSyntax Console::println( getStatementInformation(statement) + ": method '" + string(syntaxTree.value.getValueAsString()) + "'" + - ": argument value @ " + to_string(argumentIdx) + ": expected " + ScriptVariable::getTypeAsString(argumentType.type) + ", but got: " + (argumentIdx < argumentValues.size()?argumentValues[argumentIdx].getAsString():"nothing")); + ": argument value @ " + to_string(argumentIdx) + ": expected " + Variable::getTypeAsString(argumentType.type) + ", but got: " + (argumentIdx < arguments.size()?arguments[argumentIdx].getAsString():"nothing")); } argumentIdx++; } - if (scriptMethod->isVariadic() == false && argumentValues.size() > scriptMethod->getArgumentTypes().size()) { + if (method->isVariadic() == false && arguments.size() > method->getArgumentTypes().size()) { Console::println( getStatementInformation(statement) + ": method '" + string(syntaxTree.value.getValueAsString()) + "'" + - ": too many arguments: expected: " + to_string(scriptMethod->getArgumentTypes().size()) + ", got " + to_string(argumentValues.size())); + ": too many arguments: expected: " + to_string(method->getArgumentTypes().size()) + ", got " + to_string(arguments.size())); } } // execute method - span argumentValuesSpan(argumentValues); - scriptMethod->executeMethod(argumentValuesSpan, returnValue, statement); + span argumentsSpan(arguments); + method->executeMethod(argumentsSpan, returnValue, statement); // check return type - if (scriptMethod->isReturnValueNullable() == true && returnValue.getType() == TYPE_NULL) { + if (method->isReturnValueNullable() == true && returnValue.getType() == TYPE_NULL) { // no op, this is a valid return value } else - if (MiniScript::ScriptVariable::isExpectedType(returnValue.getType(), scriptMethod->getReturnValueType()) == false) { + if (MiniScript::Variable::isExpectedType(returnValue.getType(), method->getReturnValueType()) == false) { Console::println( getStatementInformation(statement) + ": method '" + string(syntaxTree.value.getValueAsString()) + "'" + - ": return value: expected " + ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()) + ", but got: " + ScriptVariable::getReturnTypeAsString(returnValue.getType(), false)); + ": return value: expected " + Variable::getReturnTypeAsString(method->getReturnValueType(), method->isReturnValueNullable()) + ", but got: " + Variable::getReturnTypeAsString(returnValue.getType(), false)); } // return returnValue; @@ -641,39 +651,39 @@ MiniScript::ScriptVariable MiniScript::executeScriptStatement(const ScriptSyntax return returnValue; } -bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, const vector& arguments, const ScriptStatement& statement, ScriptSyntaxTreeNode& syntaxTree) { +bool MiniScript::createStatementSyntaxTree(const string_view& methodName, const vector& arguments, const Statement& statement, SyntaxTreeNode& syntaxTree) { if (VERBOSE == true) Console::println("MiniScript::createScriptStatementSyntaxTree(): " + getStatementInformation(statement) + ": " + string(methodName) + "(" + getArgumentsAsString(arguments) + ")"); // method/function - auto scriptFunctionIdx = SCRIPTIDX_NONE; - ScriptMethod* scriptMethod = nullptr; + auto functionIdx = SCRIPTIDX_NONE; + Method* method = nullptr; // try first user functions { - auto scriptFunctionsIt = scriptFunctions.find(string(methodName)); - if (scriptFunctionsIt != scriptFunctions.end()) { - scriptFunctionIdx = scriptFunctionsIt->second; + auto functionsIt = functions.find(string(methodName)); + if (functionsIt != functions.end()) { + functionIdx = functionsIt->second; } } // try methods next { - auto scriptMethodsIt = scriptMethods.find(string(methodName)); - if (scriptMethodsIt != scriptMethods.end()) { - scriptMethod = scriptMethodsIt->second; + auto methodsIt = methods.find(string(methodName)); + if (methodsIt != methods.end()) { + method = methodsIt->second; } } // arguments vector argumentReferences(0); - if (scriptFunctionIdx != SCRIPTIDX_NONE) { - argumentReferences.resize(scripts[scriptFunctionIdx].arguments.size()); + if (functionIdx != SCRIPTIDX_NONE) { + argumentReferences.resize(scripts[functionIdx].functionArguments.size()); auto argumentIdx = 0; - for (const auto& argument: scripts[scriptFunctionIdx].arguments) { + for (const auto& argument: scripts[functionIdx].functionArguments) { argumentReferences[argumentIdx++] = argument.reference; } } else - if (scriptMethod != nullptr) { - argumentReferences.resize(scriptMethod->getArgumentTypes().size()); + if (method != nullptr) { + argumentReferences.resize(method->getArgumentTypes().size()); auto argumentIdx = 0; - for (const auto& argument: scriptMethod->getArgumentTypes()) { + for (const auto& argument: method->getArgumentTypes()) { argumentReferences[argumentIdx++] = argument.reference; } } @@ -682,14 +692,22 @@ bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, // object member access string_view accessObjectMemberObject; string_view accessObjectMemberMethod; + vector lamdaFunctionArguments; + string_view lamdaFunctionScriptCode; + if (viewIsLamdaFunction(argument, lamdaFunctionArguments, lamdaFunctionScriptCode) == true) { + Variable variable; + createLamdaFunction(variable, lamdaFunctionArguments, lamdaFunctionScriptCode, false, statement); + SyntaxTreeNode subSyntaxTree(SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, variable, nullptr, {}); + syntaxTree.arguments.push_back(subSyntaxTree); + } else if (getObjectMemberAccess(argument, accessObjectMemberObject, accessObjectMemberMethod, statement) == true) { // method call string_view subMethodName; vector subArguments; string accessObjectMemberStatement; - if (parseScriptStatement(argument, subMethodName, subArguments, statement, accessObjectMemberStatement) == true) { - ScriptSyntaxTreeNode subSyntaxTree; - if (createScriptStatementSyntaxTree(subMethodName, subArguments, statement, subSyntaxTree) == false) { + if (parseStatement(argument, subMethodName, subArguments, statement, accessObjectMemberStatement) == true) { + SyntaxTreeNode subSyntaxTree; + if (createStatementSyntaxTree(subMethodName, subArguments, statement, subSyntaxTree) == false) { return false; } syntaxTree.arguments.push_back(subSyntaxTree); @@ -700,16 +718,16 @@ bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, // plain variable if (viewIsVariableAccess(argument) == true) { // - ScriptVariable value; + Variable value; value.setValue(string(argument)); // look up getVariable method string methodName = argumentIdx >= argumentReferences.size() || argumentReferences[argumentIdx] == false?"getVariable":"getVariableReference"; - ScriptMethod* method = nullptr; + Method* method = nullptr; { - auto scriptMethodsIt = scriptMethods.find(methodName); - if (scriptMethodsIt != scriptMethods.end()) { - method = scriptMethodsIt->second; + auto methodsIt = methods.find(methodName); + if (methodsIt != methods.end()) { + method = methodsIt->second; } else { Console::println(getStatementInformation(statement) + ": unknown method '" + methodName + "'"); // @@ -720,13 +738,13 @@ bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, } syntaxTree.arguments.emplace_back( - ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD, - MiniScript::ScriptVariable(methodName), + SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD, + MiniScript::Variable(methodName), method, - initializer_list + initializer_list { { - ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, + SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, value, nullptr, {} @@ -750,9 +768,9 @@ bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, string_view subMethodName; vector subArguments; string accessObjectMemberStatement; - if (parseScriptStatement(argument, subMethodName, subArguments, statement, accessObjectMemberStatement) == true) { - ScriptSyntaxTreeNode subSyntaxTree; - if (createScriptStatementSyntaxTree(subMethodName, subArguments, statement, subSyntaxTree) == false) { + if (parseStatement(argument, subMethodName, subArguments, statement, accessObjectMemberStatement) == true) { + SyntaxTreeNode subSyntaxTree; + if (createStatementSyntaxTree(subMethodName, subArguments, statement, subSyntaxTree) == false) { return false; } syntaxTree.arguments.push_back(subSyntaxTree); @@ -762,31 +780,31 @@ bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, } } else { // string literal - ScriptVariable argumentValue; + Variable argumentValue; if ((StringTools::viewStartsWith(argument, "\"") == true && StringTools::viewEndsWith(argument, "\"") == true) || (StringTools::viewStartsWith(argument, "'") == true && StringTools::viewEndsWith(argument, "'") == true)) { // - ScriptVariable value; + Variable value; value.setValue(string(StringTools::viewSubstring(argument, 1, argument.size() - 1))); // syntaxTree.arguments.emplace_back( - ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, + SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, value, nullptr, - initializer_list{} + initializer_list{} ); } else { // implicitely literal - ScriptVariable value; + Variable value; value.setImplicitTypedValueFromStringView(argument, this, statement); // syntaxTree.arguments.emplace_back( - ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, + SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL, value, nullptr, - initializer_list{} + initializer_list{} ); } } @@ -794,17 +812,18 @@ bool MiniScript::createScriptStatementSyntaxTree(const string_view& methodName, argumentIdx++; } // try first user functions - if (scriptFunctionIdx != SCRIPTIDX_NONE) { - syntaxTree.type = ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION; - syntaxTree.value = string(methodName); + if (functionIdx != SCRIPTIDX_NONE) { + syntaxTree.type = SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION; + syntaxTree.value.setValue(string(methodName)); + syntaxTree.setFunctionScriptIdx(functionIdx); // return true; } else // try methods next - if (scriptMethod != nullptr) { - syntaxTree.type = ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD; - syntaxTree.value = string(methodName); - syntaxTree.method = scriptMethod; + if (method != nullptr) { + syntaxTree.type = SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD; + syntaxTree.value.setValue(string(methodName)); + syntaxTree.setMethod(method); // return true; } else { @@ -840,36 +859,36 @@ bool MiniScript::validateCallable(const string& function) { return true; } -bool MiniScript::validateCallable(const ScriptSyntaxTreeNode& syntaxTreeNode, const ScriptStatement& statement) { +bool MiniScript::validateCallable(const SyntaxTreeNode& syntaxTreeNode, const Statement& statement) { // switch (syntaxTreeNode.type) { - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { break; } - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { - const auto& contextFunctions = syntaxTreeNode.method->getContextFunctions(); + const auto& contextFunctions = syntaxTreeNode.getMethod()->getContextFunctions(); if (contextFunctions.empty() == false) { // Console::println( "MiniScript::validateCallable(): '" + getStatementInformation(statement) + ": method " + - syntaxTreeNode.method->getMethodName() + "() can not be called within a callable function" + syntaxTreeNode.getMethod()->getMethodName() + "() can not be called within a callable function" ); // parseErrors.push_back( getStatementInformation(statement) + ": method " + - syntaxTreeNode.method->getMethodName() + "() can not be called within a callable function" + syntaxTreeNode.getMethod()->getMethodName() + "() can not be called within a callable function" ); // return false; } } break; - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { for (const auto& argument: syntaxTreeNode.arguments) { if (validateCallable(argument, statement) == false) return false; @@ -912,16 +931,16 @@ bool MiniScript::validateContextFunctions(const string& function, vector return true; } -bool MiniScript::validateContextFunctions(const ScriptSyntaxTreeNode& syntaxTreeNode, vector& functionStack, const ScriptStatement& statement) { +bool MiniScript::validateContextFunctions(const SyntaxTreeNode& syntaxTreeNode, vector& functionStack, const Statement& statement) { // switch (syntaxTreeNode.type) { - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { break; } - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { - const auto& contextFunctions = syntaxTreeNode.method->getContextFunctions(); + const auto& contextFunctions = syntaxTreeNode.getMethod()->getContextFunctions(); if (contextFunctions.empty() == false) { // string contextFunctionsString; @@ -943,7 +962,7 @@ bool MiniScript::validateContextFunctions(const ScriptSyntaxTreeNode& syntaxTree "MiniScript::validateContextFunctions(): '" + getStatementInformation(statement) + ": method " + - syntaxTreeNode.method->getMethodName() + "() can only be called within the following functions: " + + syntaxTreeNode.getMethod()->getMethodName() + "() can only be called within the following functions: " + contextFunctionsString + ", but was called from " + functionStackFunction + "()" @@ -952,7 +971,7 @@ bool MiniScript::validateContextFunctions(const ScriptSyntaxTreeNode& syntaxTree parseErrors.push_back( getStatementInformation(statement) + ": method " + - syntaxTreeNode.method->getMethodName() + "() can only be called within the following functions: " + + syntaxTreeNode.getMethod()->getMethodName() + "() can only be called within the following functions: " + contextFunctionsString + ", but was called from " + functionStackFunction + "()" @@ -963,7 +982,7 @@ bool MiniScript::validateContextFunctions(const ScriptSyntaxTreeNode& syntaxTree } } break; - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { for (const auto& argument: syntaxTreeNode.arguments) { if (validateContextFunctions(argument, functionStack, statement) == false) return false; @@ -1013,9 +1032,9 @@ void MiniScript::executeStateMachine() { if (scriptState.lastStateMachineState == nullptr || scriptState.state != scriptState.lastState) { scriptState.lastState = scriptState.state; scriptState.lastStateMachineState = nullptr; - auto scriptStateMachineStateIt = scriptStateMachineStates.find(scriptState.state); - if (scriptStateMachineStateIt != scriptStateMachineStates.end()) { - scriptState.lastStateMachineState = scriptStateMachineStateIt->second; + auto stateMachineStateIt = stateMachineStates.find(scriptState.state); + if (stateMachineStateIt != stateMachineStates.end()) { + scriptState.lastStateMachineState = stateMachineStateIt->second; } } } @@ -1361,7 +1380,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { // yes haveScript = true; // functions: argument names - vector arguments; + vector arguments; // determine statement string statement; if (scriptType == Script::SCRIPTTYPE_FUNCTION) { @@ -1426,20 +1445,20 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } } auto trimmedStatement = StringTools::trim(statement); - ScriptStatement scriptStatement( + Statement evaluateStatement( currentLineIdx, STATEMENTIDX_FIRST, "internal.script.evaluate(" + StringTools::replace(StringTools::replace(trimmedStatement, "\\", "\\\\"), "\"", "\\\"") + ")", "internal.script.evaluate(" + StringTools::replace(StringTools::replace(trimmedStatement, "\\", "\\\\"), "\"", "\\\"") + ")", STATEMENTIDX_NONE ); - auto conditionOrNameExecutable = doStatementPreProcessing(trimmedStatement, scriptStatement); + auto conditionOrNameExecutable = doStatementPreProcessing(trimmedStatement, evaluateStatement); auto conditionOrName = trimmedStatement; auto emitCondition = StringTools::regexMatch(conditionOrName, "[a-zA-Z0-9_]+"); statementIdx = STATEMENTIDX_FIRST; // add to user functions if (scriptType == Script::SCRIPTTYPE_FUNCTION) { - scriptFunctions[conditionOrName] = scripts.size(); + functions[conditionOrName] = scripts.size(); } // push to scripts @@ -1448,12 +1467,12 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { currentLineIdx, conditionOrName, conditionOrNameExecutable, - ScriptStatement(currentLineIdx, statementIdx, conditionOrName, conditionOrNameExecutable, STATEMENTIDX_NONE), - ScriptSyntaxTreeNode(), + Statement(currentLineIdx, statementIdx, conditionOrName, conditionOrNameExecutable, STATEMENTIDX_NONE), + SyntaxTreeNode(), name, emitCondition, - initializer_list{}, - initializer_list{}, + initializer_list{}, + initializer_list{}, callable, arguments ); @@ -1551,14 +1570,14 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } } else if (StringTools::regexMatch(statementCode, "^elseif[\\s]*\\(.*\\)$") == true) { - ScriptStatement scriptStatement( + Statement elseIfStatement( currentLineIdx, STATEMENTIDX_FIRST, StringTools::replace(StringTools::replace(statementCode, "\\", "\\\\"), "\"", "\\\""), StringTools::replace(StringTools::replace(statementCode, "\\", "\\\\"), "\"", "\\\""), STATEMENTIDX_NONE ); - auto executableStatement = doStatementPreProcessing(statementCode, scriptStatement); + auto executableStatement = doStatementPreProcessing(statementCode, elseIfStatement); if (gotoStatementStack.empty() == false) { auto gotoStatementStackElement = gotoStatementStack.top(); gotoStatementStack.pop(); @@ -1594,14 +1613,14 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { scriptValid = false; } } else { - ScriptStatement scriptStatement( + Statement generatedStatement( currentLineIdx, STATEMENTIDX_FIRST, StringTools::replace(StringTools::replace(statementCode, "\\", "\\\\"), "\"", "\\\""), StringTools::replace(StringTools::replace(statementCode, "\\", "\\\\"), "\"", "\\\""), STATEMENTIDX_NONE ); - auto executableStatement = doStatementPreProcessing(statementCode, scriptStatement); + auto executableStatement = doStatementPreProcessing(statementCode, generatedStatement); if (StringTools::regexMatch(executableStatement, "^forTime[\\s]*\\(.*\\)$") == true || StringTools::regexMatch(executableStatement, "^forCondition[\\s]*\\(.*\\)$") == true) { gotoStatementStack.push( @@ -1644,11 +1663,11 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { string_view method; vector arguments; string accessObjectMemberStatement; - if (parseScriptStatement(script.executableCondition, method, arguments, script.conditionStatement, accessObjectMemberStatement) == false) { + if (parseStatement(script.executableCondition, method, arguments, script.conditionStatement, accessObjectMemberStatement) == false) { // scriptValid = false; } else - if (createScriptStatementSyntaxTree(method, arguments, script.conditionStatement, script.conditionSyntaxTree) == false) { + if (createStatementSyntaxTree(method, arguments, script.conditionStatement, script.conditionSyntaxTree) == false) { // scriptValid = false; } @@ -1661,11 +1680,11 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { string_view methodName; vector arguments; string accessObjectMemberStatement; - if (parseScriptStatement(statement.executableStatement, methodName, arguments, statement, accessObjectMemberStatement) == false) { + if (parseStatement(statement.executableStatement, methodName, arguments, statement, accessObjectMemberStatement) == false) { // scriptValid = false; } else - if (createScriptStatementSyntaxTree(methodName, arguments, statement, syntaxTree) == false) { + if (createStatementSyntaxTree(methodName, arguments, statement, syntaxTree) == false) { // scriptValid = false; } @@ -1683,10 +1702,10 @@ void MiniScript::parseScript(const string& pathName, const string& fileName) { scriptFileName = fileName; // - for (const auto& [scriptMethodId, scriptMethod]: scriptMethods) delete scriptMethod; - for (const auto& [scriptStateMachineStateId, scriptStateMachineState]: scriptStateMachineStates) delete scriptStateMachineState; - scriptMethods.clear(); - scriptStateMachineStates.clear(); + for (const auto& [methodName, method]: methods) delete method; + for (const auto& [stateMachineStateId, stateMachineState]: stateMachineStates) delete stateMachineState; + methods.clear(); + stateMachineStates.clear(); while (scriptStateStack.empty() == false) popScriptState(); // shutdown script state @@ -1699,9 +1718,9 @@ void MiniScript::parseScript(const string& pathName, const string& fileName) { // string scriptCode; try { - scriptCode = FileSystem::getContentAsString(pathName, fileName); + scriptCode = FileSystem::getContentAsString(scriptPathName, scriptFileName); } catch (FileSystem::FileSystemException& fse) { - Console::println("MiniScript::parseScript(): " + pathName + "/" + fileName + ": an error occurred: " + fse.what()); + Console::println(scriptPathName + "/" + scriptFileName + ": an error occurred: " + fse.what()); // scriptValid = true; // @@ -1721,7 +1740,7 @@ void MiniScript::parseScript(const string& pathName, const string& fileName) { startScript(); return; } else { - Console::println("MiniScript::parseScript(): " + pathName + "/" + fileName + ": Script has changed. Script will be run in interpreted mode. Retranspile and recompile your script if you want to run it natively."); + Console::println(scriptPathName + "/" + scriptFileName + ": Script has changed. Script will be run in interpreted mode. Retranspile and recompile your script if you want to run it natively."); native = false; } } @@ -1740,7 +1759,7 @@ void MiniScript::parseScript(const string& pathName, const string& fileName) { // if (script.scriptType == MiniScript::Script::SCRIPTTYPE_FUNCTION) { // - if (script.callable == true) { + if (script.callableFunction == true) { // if (validateCallable(script.condition) == false) { // @@ -1773,7 +1792,7 @@ void MiniScript::parseScript(const string& pathName, const string& fileName) { } } if (haveErrorScript == false) { - Console::println("MiniScript::parseScript(): '" + scriptFileName + ": script needs to define an error condition"); + Console::println(scriptPathName + "/" + scriptFileName + ": script needs to define an error condition"); // parseErrors.push_back("Script needs to define an error condition"); // @@ -1800,7 +1819,7 @@ void MiniScript::parseScript(const string& pathName, const string& fileName) { void MiniScript::startScript() { if (VERBOSE == true) Console::println("MiniScript::startScript(): '" + scriptFileName + ": starting script."); if (scriptValid == false) { - Console::println("MiniScript::startScript(): " + scriptFileName + ": script not valid: not starting"); + Console::println(scriptFileName + ": script not valid: not starting"); return; } auto& scriptState = getScriptState(); @@ -1828,7 +1847,7 @@ int MiniScript::determineScriptIdxToStart() { // emit condition } else { auto conditionMet = true; - auto returnValue = ScriptVariable(); + auto returnValue = Variable(); if (evaluateInternal(script.condition, script.executableCondition, returnValue) == true) { auto returnValueBoolValue = false; if (returnValue.getBooleanValue(returnValueBoolValue, false) == false) { @@ -1869,7 +1888,7 @@ int MiniScript::determineNamedScriptIdxToStart() { // no op } else { auto conditionMet = true; - ScriptVariable returnValue; + Variable returnValue; if (evaluateInternal(script.condition, script.executableCondition, returnValue) == true) { auto returnValueBoolValue = false; if (returnValue.getBooleanValue(returnValueBoolValue, false) == false) { @@ -1899,271 +1918,271 @@ int MiniScript::determineNamedScriptIdxToStart() { return SCRIPTIDX_NONE; } -bool MiniScript::getNextStatementOperator(const string& processedStatement, MiniScript::ScriptStatementOperator& nextOperator, const ScriptStatement& statement) { +const string MiniScript::doStatementPreProcessing(const string& processedStatement, const Statement& statement) { + auto preprocessedStatement = processedStatement; // - auto curlyBracketCount = 0; - auto bracketCount = 0; - auto quote = '\0'; - auto lc = '\0'; - for (auto i = 0; i < processedStatement.size(); i++) { - auto c = processedStatement[i]; - if ((c == '"' || c == '\'') && lc != '\\') { - if (quote == '\0') { - quote = c; - } else - if (quote == c) { - quote = '\0'; - } - } else - if (quote == '\0') { - if (c == '(') { - bracketCount++; - } else - if (c == ')') { - bracketCount--; - } else - if (c == '{') { - curlyBracketCount++; - } else - if (c == '}') { - curlyBracketCount--; - } else - if (curlyBracketCount == 0) { - for (int j = OPERATOR_NONE + 1; j < OPERATOR_MAX; j++) { - auto priorizedOperator = static_cast(j); - string operatorCandidate; - auto operatorString = getOperatorAsString(priorizedOperator); - if (operatorString.size() == 1) operatorCandidate+= processedStatement[i]; - if (operatorString.size() == 2 && i + 1 < processedStatement.size()) { - operatorCandidate+= processedStatement[i]; - operatorCandidate+= processedStatement[i + 1]; - } - if (operatorString == operatorCandidate && (nextOperator.idx == OPERATORIDX_NONE || priorizedOperator > nextOperator.scriptOperator)) { - if (i > 0 && isOperatorChar(processedStatement[i - 1]) == true) { - continue; - } - if (operatorString.size() == 2 && i + 2 < processedStatement.size() && isOperatorChar(processedStatement[i + 2]) == true) { - continue; - } else - if (operatorString.size() == 1 && i + 1 < processedStatement.size() && isOperatorChar(processedStatement[i + 1]) == true) { - continue; - } - if (priorizedOperator == OPERATOR_SUBTRACTION) { - string leftArgumentBrackets; - auto leftArgumentLeft = 0; - auto leftArgument = findLeftArgument(processedStatement, i - 1, leftArgumentLeft, leftArgumentBrackets); - if (leftArgument.length() == 0) continue; - } - nextOperator.idx = i; - nextOperator.scriptOperator = priorizedOperator; - } - } - } + struct StatementOperator { + int idx { OPERATORIDX_NONE }; + Operator operator_; + }; + // + auto trimArgument = [&](const string& argument) -> const string { + auto processedArgument = StringTools::trim(argument); + if (StringTools::startsWith(processedArgument, "(") == true && StringTools::endsWith(processedArgument, ")") == true) { + processedArgument = StringTools::substring(processedArgument, 1, processedArgument.size() - 1); } - lc = c; - } - + return processedArgument; + }; // - if (bracketCount > 0) { - Console::println(getStatementInformation(statement) + ": unbalanced bracket count: " + to_string(Math::abs(bracketCount)) + " " + (bracketCount < 0?"too much closed":"still open")); - // - parseErrors.push_back(getStatementInformation(statement) + ": unbalanced bracket count: " + to_string(Math::abs(bracketCount)) + " " + (bracketCount < 0?"too much closed":"still open")); + auto findLeftArgument = [&](const string& statement, int position, int& length, string& brackets) -> const string { // - return false; - } - // - return nextOperator.idx != OPERATORIDX_NONE; -} - -inline const string MiniScript::trimArgument(const string& argument) { - auto processedArgument = StringTools::trim(argument); - if (StringTools::startsWith(processedArgument, "(") == true && StringTools::endsWith(processedArgument, ")") == true) { - processedArgument = StringTools::substring(processedArgument, 1, processedArgument.size() - 1); - } - return processedArgument; -} - -inline const string MiniScript::findRightArgument(const string& statement, int position, int& length, string& brackets) { - // - auto bracketCount = 0; - auto squareBracketCount = 0; - auto curlyBracketCount = 0; - auto quote = '\0'; - auto lc = '\0'; - string argument; - length = 0; - for (auto i = position; i < statement.size(); i++) { - auto c = statement[i]; - // quote? - if ((c == '"' || c == '\'') && lc != '\\') { - if (quote == '\0') { - quote = c; - } else - if (quote == c) { - quote = '\0'; - } - argument+= c; - } else - // no quote - if (quote == '\0') { - if (c == '(') { - bracketCount++; - argument+= c; - } else - if (c == '[') { - squareBracketCount++; - argument+= c; - } else - if (c == '{') { - curlyBracketCount++; - argument+= c; - } else - if (c == ')') { - bracketCount--; - if (bracketCount < 0) { - brackets = "()"; - return trimArgument(argument); + auto bracketCount = 0; + auto squareBracketCount = 0; + auto curlyBracketCount = 0; + auto quote = '\0'; + auto lc = '\0'; + string argument; + length = 0; + for (int i = position; i >= 0; i--) { + auto c = statement[i]; + if ((c == '"' || c == '\'') && lc != '\\') { + if (quote == '\0') { + quote = c; + } else + if (quote == c) { + quote = '\0'; } - argument+= c; + argument = c + argument; } else - if (c == ']') { - squareBracketCount--; - // array initializer? - if (StringTools::startsWith(argument, "[") == false) { - // no + if (quote == '\0') { + if (c == ')') { + bracketCount++; + argument = c + argument; + } else + if (c == ']') { + squareBracketCount++; + argument = c + argument; + } else + if (c == '}') { + curlyBracketCount++; + argument = c + argument; + } else + if (c == '(') { + bracketCount--; + if (bracketCount < 0) { + brackets = "()"; + return trimArgument(argument); + } + argument = c + argument; + } else + if (c == '[') { + squareBracketCount--; if (squareBracketCount < 0) { brackets = "[]"; return trimArgument(argument); } + argument = c + argument; + } else + if (c == '{') { + curlyBracketCount--; + if (curlyBracketCount < 0) { + brackets = "{}"; + return trimArgument(argument); + } + argument = c + argument; + } else + if (squareBracketCount == 0 && curlyBracketCount == 0 && c == ',') { + if (bracketCount == 0) return trimArgument(argument); + argument = c + argument; + } else { + argument = c + argument; } - argument+= c; } else - if (c == '}') { - curlyBracketCount--; - if (curlyBracketCount < 0) { - brackets = "{}"; - return trimArgument(argument); + if (quote != '\0') { + argument = c + argument; + } + length++; + // + lc = c; + } + return trimArgument(argument); + }; + // + auto findRightArgument = [&](const string& statement, int position, int& length, string& brackets) -> const string { + // + auto bracketCount = 0; + auto squareBracketCount = 0; + auto curlyBracketCount = 0; + auto quote = '\0'; + auto lc = '\0'; + string argument; + length = 0; + for (auto i = position; i < statement.size(); i++) { + auto c = statement[i]; + // quote? + if ((c == '"' || c == '\'') && lc != '\\') { + if (quote == '\0') { + quote = c; + } else + if (quote == c) { + quote = '\0'; } argument+= c; } else - if (squareBracketCount == 0 && curlyBracketCount == 0 && c == ',') { - if (bracketCount == 0) return trimArgument(argument); - // - if (argument.empty() == true && (c == ' ' || c == '\t' || c == '\n')) { - // no op - } else { + // no quote + if (quote == '\0') { + if (c == '(') { + bracketCount++; argument+= c; - } - } else { - // - if (argument.empty() == true && (c == ' ' || c == '\t' || c == '\n')) { - // no op - } else { + } else + if (c == '[') { + squareBracketCount++; + argument+= c; + } else + if (c == '{') { + curlyBracketCount++; + argument+= c; + } else + if (c == ')') { + bracketCount--; + if (bracketCount < 0) { + brackets = "()"; + return trimArgument(argument); + } + argument+= c; + } else + if (c == ']') { + squareBracketCount--; + // array initializer? + if (StringTools::startsWith(argument, "[") == false) { + // no + if (squareBracketCount < 0) { + brackets = "[]"; + return trimArgument(argument); + } + } argument+= c; + } else + if (c == '}') { + curlyBracketCount--; + if (curlyBracketCount < 0) { + brackets = "{}"; + return trimArgument(argument); + } + argument+= c; + } else + if (squareBracketCount == 0 && curlyBracketCount == 0 && c == ',') { + if (bracketCount == 0) return trimArgument(argument); + // + if (argument.empty() == true && (c == ' ' || c == '\t' || c == '\n')) { + // no op + } else { + argument+= c; + } + } else { + // + if (argument.empty() == true && (c == ' ' || c == '\t' || c == '\n')) { + // no op + } else { + argument+= c; + } } + } else + if (quote != '\0') { + argument+= c; } - } else - if (quote != '\0') { - argument+= c; + length++; + // + lc = c; } - length++; // - lc = c; - } - // - return trimArgument(argument); -} - -inline const string MiniScript::findLeftArgument(const string& statement, int position, int& length, string& brackets) { - // adapt code similar to findRightArguument related to array and map/initializer + return trimArgument(argument); + }; // - auto bracketCount = 0; - auto squareBracketCount = 0; - auto curlyBracketCount = 0; - auto quote = '\0'; - auto lc = '\0'; - string argument; - length = 0; - for (int i = position; i >= 0; i--) { - auto c = statement[i]; - if ((c == '"' || c == '\'') && lc != '\\') { - if (quote == '\0') { - quote = c; - } else - if (quote == c) { - quote = '\0'; - } - argument = c + argument; - } else - if (quote == '\0') { - if (c == ')') { - bracketCount++; - argument = c + argument; - } else - if (c == ']') { - squareBracketCount++; - argument = c + argument; - } else - if (c == '}') { - curlyBracketCount++; - argument = c + argument; - } else - if (c == '(') { - bracketCount--; - if (bracketCount < 0) { - brackets = "()"; - return trimArgument(argument); - } - argument = c + argument; - } else - if (c == ':' && - bracketCount == 0 && - squareBracketCount == 0 && - curlyBracketCount == 0) { - // - brackets = ""; - return trimArgument(argument); - } else - if (c == '[') { - squareBracketCount--; - if (squareBracketCount < 0) { - brackets = "[]"; - return trimArgument(argument); + auto getNextStatementOperator = [&](const string& processedStatement, StatementOperator& nextOperator, const Statement& statement) { + bool lamdaFunctionDeclaration = false; + auto curlyBracketCount = 0; + auto bracketCount = 0; + auto quote = '\0'; + auto lc = '\0'; + for (auto i = 0; i < processedStatement.size(); i++) { + auto c = processedStatement[i]; + if ((c == '"' || c == '\'') && lc != '\\') { + if (quote == '\0') { + quote = c; + } else + if (quote == c) { + quote = '\0'; } - argument = c + argument; } else - if (c == '{') { - curlyBracketCount--; - if (curlyBracketCount < 0) { - brackets = "{}"; - return trimArgument(argument); + if (quote == '\0') { + if (c == '(') { + // read ahead if inline/lambda function + string_view lamdaFunctionCandidate(&processedStatement[i], processedStatement.size() - i); + if (viewIsLamdaFunction(lamdaFunctionCandidate) == true) lamdaFunctionDeclaration = true; + bracketCount++; + } else + if (c == ')') { + if (lamdaFunctionDeclaration == true) lamdaFunctionDeclaration = false; + bracketCount--; + } else + if (c == '{') { + curlyBracketCount++; + } else + if (c == '}') { + curlyBracketCount--; + } else + if (curlyBracketCount == 0 && lamdaFunctionDeclaration == false) { + for (int j = OPERATOR_NONE + 1; j < OPERATOR_MAX; j++) { + auto priorizedOperator = static_cast(j); + string operatorCandidate; + auto operatorString = getOperatorAsString(priorizedOperator); + if (operatorString.size() == 1) operatorCandidate+= processedStatement[i]; + if (operatorString.size() == 2 && i + 1 < processedStatement.size()) { + operatorCandidate+= processedStatement[i]; + operatorCandidate+= processedStatement[i + 1]; + } + if (operatorString == operatorCandidate && (nextOperator.idx == OPERATORIDX_NONE || priorizedOperator > nextOperator.operator_)) { + if (i > 0 && isOperatorChar(processedStatement[i - 1]) == true) { + continue; + } + if (operatorString.size() == 2 && i + 2 < processedStatement.size() && isOperatorChar(processedStatement[i + 2]) == true) { + continue; + } else + if (operatorString.size() == 1 && i + 1 < processedStatement.size() && isOperatorChar(processedStatement[i + 1]) == true) { + continue; + } + if (priorizedOperator == OPERATOR_SUBTRACTION) { + string leftArgumentBrackets; + auto leftArgumentLeft = 0; + auto leftArgument = findLeftArgument(processedStatement, i - 1, leftArgumentLeft, leftArgumentBrackets); + if (leftArgument.length() == 0) continue; + } + nextOperator.idx = i; + nextOperator.operator_ = priorizedOperator; + } + } } - argument = c + argument; - } else - if (squareBracketCount == 0 && curlyBracketCount == 0 && c == ',') { - if (bracketCount == 0) return trimArgument(argument); - argument = c + argument; - } else { - argument = c + argument; } - } else - if (quote != '\0') { - argument = c + argument; + lc = c; } - length++; - // - lc = c; - } - return trimArgument(argument); -} -const string MiniScript::doStatementPreProcessing(const string& processedStatement, const ScriptStatement& statement) { - auto preprocessedStatement = processedStatement; + // + if (bracketCount > 0) { + Console::println(getStatementInformation(statement) + ": unbalanced bracket count: " + to_string(Math::abs(bracketCount)) + " " + (bracketCount < 0?"too much closed":"still open")); + // + parseErrors.push_back(getStatementInformation(statement) + ": unbalanced bracket count: " + to_string(Math::abs(bracketCount)) + " " + (bracketCount < 0?"too much closed":"still open")); + // + return false; + } + // + return nextOperator.idx != OPERATORIDX_NONE; + }; // - ScriptStatementOperator nextOperators; + StatementOperator nextOperators; while (getNextStatementOperator(preprocessedStatement, nextOperators, statement) == true) { - auto methodIt = scriptOperators.find(nextOperators.scriptOperator); - if (methodIt == scriptOperators.end()) { + auto methodIt = operators.find(nextOperators.operator_); + if (methodIt == operators.end()) { Console::println(getStatementInformation(statement) + ": " + processedStatement + ": operator found in: '" + preprocessedStatement + "'@" + to_string(nextOperators.idx) + ": no method found"); // TODO: error handling return preprocessedStatement; @@ -2172,7 +2191,7 @@ const string MiniScript::doStatementPreProcessing(const string& processedStateme if (method->isVariadic() == false && method->getArgumentTypes().size() == 1) { // find the single argument right - auto operatorString = getOperatorAsString(nextOperators.scriptOperator); + auto operatorString = getOperatorAsString(nextOperators.operator_); string rightArgumentBrackets; int rightArgumentLength = 0; auto rightArgument = findRightArgument(preprocessedStatement, nextOperators.idx + operatorString.size(), rightArgumentLength, rightArgumentBrackets); @@ -2184,7 +2203,8 @@ const string MiniScript::doStatementPreProcessing(const string& processedStateme } else if (method->isVariadic() == true || method->getArgumentTypes().size() == 2) { - auto operatorString = getOperatorAsString(nextOperators.scriptOperator); + // + auto operatorString = getOperatorAsString(nextOperators.operator_); // find the first argument left string leftArgumentBrackets; int leftArgumentLength = 0; @@ -2199,7 +2219,7 @@ const string MiniScript::doStatementPreProcessing(const string& processedStateme return preprocessedStatement; } // - if (nextOperators.scriptOperator == OPERATOR_SET) { + if (nextOperators.operator_ == OPERATOR_SET) { leftArgument = "\"" + doStatementPreProcessing(leftArgument, statement) + "\""; } // substitute with method call @@ -2208,13 +2228,16 @@ const string MiniScript::doStatementPreProcessing(const string& processedStateme method->getMethodName() + "(" + leftArgument + ", " + rightArgument + ")" + StringTools::substring(preprocessedStatement, nextOperators.idx + operatorString.size() + rightArgumentLength, preprocessedStatement.size()); } - nextOperators = ScriptStatementOperator(); + // + nextOperators = StatementOperator(); } // return preprocessedStatement; } -bool MiniScript::getObjectMemberAccess(const string_view& executableStatement, string_view& object, string_view& method, const ScriptStatement& statement) { +bool MiniScript::getObjectMemberAccess(const string_view& executableStatement, string_view& object, string_view& method, const Statement& statement) { + // TODO: "xxx"->toUpperString() + // Console::println("oma: " + string(executableStatement)); // auto objectMemberAccess = false; auto objectStartIdx = string::npos; @@ -2272,6 +2295,8 @@ bool MiniScript::getObjectMemberAccess(const string_view& executableStatement, s object = string_view(&executableStatement[objectStartIdx], objectEndIdx - objectStartIdx); method = string_view(&executableStatement[memberCallStartIdx], memberCallEndIdx - memberCallStartIdx); // + // Console::println("\t" + string(object) + " / " + string(method)); + // objectMemberAccess = true; // dont break here, we can have multiple member access operators here, but we want the last one in this step } @@ -2283,7 +2308,7 @@ bool MiniScript::getObjectMemberAccess(const string_view& executableStatement, s return objectMemberAccess; } -bool MiniScript::call(int scriptIdx, span& argumentValues, ScriptVariable& returnValue) { +bool MiniScript::call(int scriptIdx, span& arguments, Variable& returnValue) { if (scriptIdx < 0 || scriptIdx >= scripts.size()) { Console::println("MiniScript::call(): invalid script index: " + to_string(scriptIdx)); return false; @@ -2295,11 +2320,11 @@ bool MiniScript::call(int scriptIdx, span& argumentValues, Scrip auto& scriptState = getScriptState(); // also put named arguments into state context variables auto argumentIdx = 0; - for (const auto& argument: scripts[scriptIdx].arguments) { - if (argumentIdx == argumentValues.size()) { + for (const auto& argument: scripts[scriptIdx].functionArguments) { + if (argumentIdx == arguments.size()) { break; } - setVariable(argument.name, argumentValues[argumentIdx], nullptr, argument.reference); + setVariable(argument.name, arguments[argumentIdx], nullptr, argument.reference); argumentIdx++; } } @@ -2329,15 +2354,15 @@ bool MiniScript::call(int scriptIdx, span& argumentValues, Scrip return true; } -const vector MiniScript::getMethods() { - vector methods; - for (const auto& [scriptMethodName, scriptMethod]: scriptMethods) { - if (scriptMethod->isPrivate() == true) continue; - methods.push_back(scriptMethod); +const vector MiniScript::getMethods() { + vector methods; + for (const auto& [methodName, method]: this->methods) { + if (method->isPrivate() == true) continue; + methods.push_back(method); } // struct { - bool operator()(ScriptMethod* a, ScriptMethod* b) const { + bool operator()(Method* a, Method* b) const { auto aPrefix = StringTools::substring(a->getMethodName(), 0, StringTools::lastIndexOf(a->getMethodName(), ".") + 1); auto aName = StringTools::substring(a->getMethodName(), StringTools::lastIndexOf(a->getMethodName(), ".") + 1); auto bPrefix = StringTools::substring(b->getMethodName(), 0, StringTools::lastIndexOf(b->getMethodName(), ".") + 1); @@ -2387,10 +2412,10 @@ const vector MiniScript::getMethods() { return methods; } -const vector MiniScript::getOperatorMethods() { - vector methods; - for (const auto& [scriptOperatorId, scriptMethod]: scriptOperators) { - methods.push_back(scriptMethod); +const vector MiniScript::getOperatorMethods() { + vector methods; + for (const auto& [operatorId, method]: operators) { + methods.push_back(method); } return methods; } @@ -2405,7 +2430,7 @@ const string MiniScript::getScriptInformation(int scriptIdx, bool includeStateme string argumentsString; switch(script.scriptType) { case Script::SCRIPTTYPE_FUNCTION: { - for (const auto& argument: script.arguments) { + for (const auto& argument: script.functionArguments) { if (argumentsString.empty() == false) argumentsString+= ", "; if (argument.reference == true) argumentsString+= "&"; argumentsString+= argument.name; @@ -2424,8 +2449,8 @@ const string MiniScript::getScriptInformation(int scriptIdx, bool includeStateme result+= "\n"; } if (includeStatements == true) { - for (const auto& scriptStatement: script.statements) { - result+= "\t" + to_string(scriptStatement.statementIdx) + ": " + StringTools::replace(scriptStatement.executableStatement, "\n", "\n\t\t") + (scriptStatement.gotoStatementIdx != STATEMENTIDX_NONE?" (gotoStatement " + to_string(scriptStatement.gotoStatementIdx) + ")":"") + "\n"; + for (const auto& statement: script.statements) { + result+= "\t" + to_string(statement.statementIdx) + ": " + StringTools::replace(statement.executableStatement, "\n", "\n\t\t") + (statement.gotoStatementIdx != STATEMENTIDX_NONE?" (gotoStatement " + to_string(statement.gotoStatementIdx) + ")":"") + "\n"; } result+= "\n"; } @@ -2446,9 +2471,9 @@ const string MiniScript::getInformation() { result+="State Machine States:\n"; { vector states; - for (const auto& [scriptStateMachineStateId, scriptStateMachineState]: scriptStateMachineStates) { + for (const auto& [stateMachineStateId, stateMachineState]: stateMachineStates) { string state; - state = scriptStateMachineState->getName() + "(" + to_string(scriptStateMachineState->getId()) + ")"; + state = stateMachineState->getName() + "(" + to_string(stateMachineState->getId()) + ")"; states.push_back(state); } sort(states.begin(), states.end()); @@ -2462,15 +2487,15 @@ const string MiniScript::getInformation() { result+= "Methods:\n"; { vector methods; - for (const auto& [scriptMethodName, scriptMethod]: scriptMethods) { - if (scriptMethod->isPrivate() == true) continue; - string method; - method+= scriptMethod->getMethodName(); - method+= "("; - method+= scriptMethod->getArgumentsInformation(); - method+= "): "; - method+= ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); - methods.push_back(method); + for (const auto& [methodName, method]: this->methods) { + if (method->isPrivate() == true) continue; + string methodDescription; + methodDescription+= method->getMethodName(); + methodDescription+= "("; + methodDescription+= method->getArgumentsInformation(); + methodDescription+= "): "; + methodDescription+= Variable::getReturnTypeAsString(method->getReturnValueType(), method->isReturnValueNullable()); + methods.push_back(methodDescription); } sort(methods.begin(), methods.end()); for (const auto& method: methods) result+= method + "\n"; @@ -2481,15 +2506,15 @@ const string MiniScript::getInformation() { result+= "Operators:\n"; { vector operators; - for (const auto& [scriptOperatorId, scriptMethod]: scriptOperators) { + for (const auto& [operatorId, method]: this->operators) { string operatorString; - operatorString+= getOperatorAsString(scriptMethod->getOperator()); + operatorString+= getOperatorAsString(method->getOperator()); operatorString+= " --> "; - operatorString+= scriptMethod->getMethodName(); + operatorString+= method->getMethodName(); operatorString+= "("; - operatorString+= scriptMethod->getArgumentsInformation(); + operatorString+= method->getArgumentsInformation(); operatorString+= "): "; - operatorString+= ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + operatorString+= Variable::getReturnTypeAsString(method->getReturnValueType(), method->isReturnValueNullable()); operators.push_back(operatorString); } sort(operators.begin(), operators.end()); @@ -2523,11 +2548,11 @@ void MiniScript::registerStateMachineStates() { // base if (native == false) { // - class ScriptStateNextStatement: public ScriptStateMachineState { + class ScriptStateNextStatement: public StateMachineState { private: MiniScript* miniScript { nullptr }; public: - ScriptStateNextStatement(MiniScript* miniScript): ScriptStateMachineState(), miniScript(miniScript) {} + ScriptStateNextStatement(MiniScript* miniScript): StateMachineState(), miniScript(miniScript) {} virtual const string getName() override { return "STATEMACHINESTATE_NEXT_STATEMENT"; } @@ -2541,18 +2566,18 @@ void MiniScript::registerStateMachineStates() { miniScript->setScriptStateState(STATEMACHINESTATE_WAIT_FOR_CONDITION); return; } - if (miniScript->native == false) miniScript->executeScriptLine(); + if (miniScript->native == false) miniScript->executeNextStatement(); } }; registerStateMachineState(new ScriptStateNextStatement(this)); } { // - class ScriptStateWait: public ScriptStateMachineState { + class ScriptStateWait: public StateMachineState { private: MiniScript* miniScript { nullptr }; public: - ScriptStateWait(MiniScript* miniScript): ScriptStateMachineState(), miniScript(miniScript) {} + ScriptStateWait(MiniScript* miniScript): StateMachineState(), miniScript(miniScript) {} virtual const string getName() override { return "STATEMACHINESTATE_WAIT"; } @@ -2570,11 +2595,11 @@ void MiniScript::registerStateMachineStates() { } { // - class ScriptStateWaitForCondition: public ScriptStateMachineState { + class ScriptStateWaitForCondition: public StateMachineState { private: MiniScript* miniScript { nullptr }; public: - ScriptStateWaitForCondition(MiniScript* miniScript): ScriptStateMachineState(), miniScript(miniScript) {} + ScriptStateWaitForCondition(MiniScript* miniScript): StateMachineState(), miniScript(miniScript) {} virtual const string getName() override { return "STATEMACHINESTATE_WAIT_FOR_CONDITION"; } @@ -2601,19 +2626,19 @@ void MiniScript::registerStateMachineStates() { void MiniScript::registerMethods() { // unregister old registered methods - for (const auto& [scriptMethodId, scriptMethod]: scriptMethods) delete scriptMethod; - scriptMethods.clear(); + for (const auto& [scriptMethodId, scriptMethod]: methods) delete scriptMethod; + methods.clear(); // script intern base methods { // - class ScriptMethodInternalScriptEvaluate: public ScriptMethod { + class MethodInternalScriptEvaluate: public Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodInternalScriptEvaluate(MiniScript* miniScript): - ScriptMethod( + MethodInternalScriptEvaluate(MiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_PSEUDO_MIXED, .name = "statement", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_PSEUDO_MIXED, .name = "statement", .optional = false, .reference = false, .nullable = false } }, TYPE_PSEUDO_MIXED ), @@ -2621,33 +2646,33 @@ void MiniScript::registerMethods() { const string getMethodName() override { return "internal.script.evaluate"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { - if (argumentValues.size() != 1) { + void executeMethod(span& arguments, Variable& returnValue, const Statement& statement) override { + if (arguments.size() != 1) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else - if (argumentValues.size() == 1) { - returnValue = argumentValues[0]; + if (arguments.size() == 1) { + returnValue = arguments[0]; } } bool isPrivate() const override { return true; } }; - registerMethod(new ScriptMethodInternalScriptEvaluate(this)); + registerMethod(new MethodInternalScriptEvaluate(this)); } { // - class ScriptMethodInternalEvaluateMemberAccess: public ScriptMethod { + class MethodInternalEvaluateMemberAccess: public Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodInternalEvaluateMemberAccess(MiniScript* miniScript): - ScriptMethod( + MethodInternalEvaluateMemberAccess(MiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "variable", .optional = false, .reference = false, .nullable = true }, - { .type = ScriptVariableType::TYPE_PSEUDO_MIXED, .name = "this", .optional = false, .reference = false, .nullable = true }, - { .type = ScriptVariableType::TYPE_STRING, .name = "member", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "variable", .optional = false, .reference = false, .nullable = true }, + { .type = VariableType::TYPE_PSEUDO_MIXED, .name = "this", .optional = false, .reference = false, .nullable = true }, + { .type = VariableType::TYPE_STRING, .name = "member", .optional = false, .reference = false, .nullable = false } }, TYPE_PSEUDO_MIXED, true @@ -2656,7 +2681,7 @@ void MiniScript::registerMethods() { const string getMethodName() override { return "internal.script.evaluateMemberAccess"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& arguments, Variable& returnValue, const Statement& statement) override { // Current layout: // 0: variable name of object, 1: variable content of object // 2: object method to call @@ -2667,84 +2692,84 @@ void MiniScript::registerMethods() { string variable; string member; // - if (argumentValues.size() < 3 || - miniScript->getStringValue(argumentValues, 2, member, false) == false) { + if (arguments.size() < 3 || + miniScript->getStringValue(arguments, 2, member, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { // do we have a this variable name? { string thisVariableName; - if (argumentValues[0].getType() != MiniScript::TYPE_NULL && argumentValues[0].getStringValue(thisVariableName) == true) { + if (arguments[0].getType() != MiniScript::TYPE_NULL && arguments[0].getStringValue(thisVariableName) == true) { // yep, looks like that, we always use a reference here - argumentValues[1] = miniScript->getVariable(thisVariableName, &statement, true); + arguments[1] = miniScript->getVariable(thisVariableName, &statement, true); } } // check if map, if so fetch function assignment of member property auto functionIdx = MiniScript::SCRIPTIDX_NONE; - if (argumentValues[1].getType() == TYPE_MAP) { + if (arguments[1].getType() == TYPE_MAP) { string function; - auto mapValue = argumentValues[1].getMapEntry(member); + auto mapValue = arguments[1].getMapEntry(member); if (mapValue.getType() == MiniScript::TYPE_FUNCTION_ASSIGNMENT && mapValue.getStringValue(function) == true) { functionIdx = miniScript->getFunctionScriptIdx(function); } } // - const auto& className = argumentValues[1].getClassName(); + const auto& className = arguments[1].getTypeAsString(); // if (className.empty() == false || functionIdx != MiniScript::SCRIPTIDX_NONE) { // - ScriptMethod* method { nullptr }; + Method* method { nullptr }; if (functionIdx == MiniScript::SCRIPTIDX_NONE) { #if defined(__MINISCRIPT_TRANSPILATION__) - method = evaluateMemberAccessArrays[static_cast(argumentValues[1].getType()) - static_cast(MiniScript::TYPE_STRING)][EVALUATEMEMBERACCESS_MEMBER]; + method = evaluateMemberAccessArrays[static_cast(functionArguments[1].getType()) - static_cast(MiniScript::TYPE_STRING)][EVALUATEMEMBERACCESS_MEMBER]; #else - method = miniScript->getMethod(className + "." + member); + method = miniScript->getMethod(className + "::" + member); #endif } if (method != nullptr || functionIdx != MiniScript::SCRIPTIDX_NONE) { // create method call arguments - vector callArgumentValues(1 + (argumentValues.size() - 3) / 2); + vector callArguments(1 + (arguments.size() - 3) / 2); // this - callArgumentValues[0] = move(argumentValues[1]); + callArguments[0] = move(arguments[1]); // additional method call arguments { - auto callArgumentValueIdx = 1; - for (auto argumentValueIdx = 3; argumentValueIdx < argumentValues.size(); argumentValueIdx+=2) { + auto callArgumentIdx = 1; + for (auto argumentIdx = 3; argumentIdx < arguments.size(); argumentIdx+=2) { // do we have a this variable name? string argumentVariableName; - if (argumentValues[argumentValueIdx].getType() != MiniScript::TYPE_NULL && argumentValues[argumentValueIdx].getStringValue(argumentVariableName) == true) { + if (arguments[argumentIdx].getType() != MiniScript::TYPE_NULL && arguments[argumentIdx].getStringValue(argumentVariableName) == true) { // yep, looks like that if (method != nullptr) { - argumentValues[argumentValueIdx + 1] = miniScript->getVariable(argumentVariableName, &statement, callArgumentValueIdx >= method->getArgumentTypes().size()?false:method->getArgumentTypes()[callArgumentValueIdx].reference); + arguments[argumentIdx + 1] = miniScript->getVariable(argumentVariableName, &statement, callArgumentIdx >= method->getArgumentTypes().size()?false:method->getArgumentTypes()[callArgumentIdx].reference); } else if (functionIdx != MiniScript::SCRIPTIDX_NONE) { - argumentValues[argumentValueIdx + 1] = miniScript->getVariable(argumentVariableName, &statement, callArgumentValueIdx >= miniScript->getScripts()[functionIdx].arguments.size()?false:miniScript->getScripts()[functionIdx].arguments[callArgumentValueIdx].reference); + arguments[argumentIdx + 1] = miniScript->getVariable(argumentVariableName, &statement, callArgumentIdx >= miniScript->getScripts()[functionIdx].functionArguments.size()?false:miniScript->getScripts()[functionIdx].functionArguments[callArgumentIdx].reference); } } // - callArgumentValues[callArgumentValueIdx] = move(argumentValues[argumentValueIdx + 1]); - callArgumentValueIdx++; + callArguments[callArgumentIdx] = move(arguments[argumentIdx + 1]); + callArgumentIdx++; } } // - span callArgumentValuesSpan(callArgumentValues); + span callArgumentsSpan(callArguments); // if (method != nullptr) { - method->executeMethod(callArgumentValuesSpan, returnValue, statement); + method->executeMethod(callArgumentsSpan, returnValue, statement); } else if (functionIdx != MiniScript::SCRIPTIDX_NONE) { - miniScript->call(functionIdx, callArgumentValuesSpan, returnValue); + miniScript->call(functionIdx, callArgumentsSpan, returnValue); } // write back arguments from call arguments // this - argumentValues[1] = move(callArgumentValuesSpan[0]); + arguments[1] = move(callArgumentsSpan[0]); // additional arguments { - auto callArgumentValueIdx = 1; - for (auto argumentValueIdx = 3; argumentValueIdx < argumentValues.size(); argumentValueIdx+=2) { - argumentValues[argumentValueIdx] = move(callArgumentValuesSpan[callArgumentValueIdx].getValueAsString()); - callArgumentValueIdx++; + auto callArgumentIdx = 1; + for (auto argumentIdx = 3; argumentIdx < arguments.size(); argumentIdx+=2) { + arguments[argumentIdx] = move(callArgumentsSpan[callArgumentIdx].getValueAsString()); + callArgumentIdx++; } } } @@ -2761,7 +2786,7 @@ void MiniScript::registerMethods() { return true; } }; - registerMethod(new ScriptMethodInternalEvaluateMemberAccess(this)); + registerMethod(new MethodInternalEvaluateMemberAccess(this)); } // register math methods @@ -2819,22 +2844,22 @@ void MiniScript::registerMethods() { XMLMethods::registerMethods(this); // - for (const auto scriptDataType: scriptDataTypes) { - if (scriptDataType->isMathDataType() == true) miniScriptMath->registerDataType(scriptDataType); - scriptDataType->registerMethods(this); + for (const auto dataType: dataTypes) { + if (dataType->isMathDataType() == true) miniScriptMath->registerDataType(dataType); + dataType->registerMethods(this); } // determine operators - for (const auto& [scriptMethodName, scriptMethod]: scriptMethods) { + for (const auto& [scriptMethodName, scriptMethod]: methods) { auto methodOperator = scriptMethod->getOperator(); if (methodOperator != OPERATOR_NONE) { auto methodOperatorString = getOperatorAsString(methodOperator); - auto scriptOperatorIt = scriptOperators.find(static_cast(methodOperator)); - if (scriptOperatorIt != scriptOperators.end()) { + auto scriptOperatorIt = operators.find(static_cast(methodOperator)); + if (scriptOperatorIt != operators.end()) { Console::println("MiniScript::registerMethods(): operator '" + methodOperatorString + "' already registered for method " + scriptMethod->getMethodName() + ""); continue; } - scriptOperators[static_cast(methodOperator)] = scriptMethod; + operators[static_cast(methodOperator)] = scriptMethod; } } } @@ -2843,8 +2868,42 @@ void MiniScript::registerVariables() { for (const auto& [variableName, variable]: getRootScriptState().variables) delete variable; } -const MiniScript::ScriptVariable MiniScript::initializeArray(const string_view& initializerString, MiniScript* miniScript, const ScriptStatement& statement) { - ScriptVariable variable; +void MiniScript::createLamdaFunction(Variable& variable, const vector& arguments, const string_view& functionScriptCode, bool populateThis, const Statement& statement) { + // function declaration + auto functionName = string() + "lamda_function_" + to_string(inlineFunctionIdx++); + auto inlineFunctionScriptCode = "function: " + functionName + "("; + if (populateThis == true) inlineFunctionScriptCode+= "&$this"; + auto argumentIdx = 0; + for (const auto& argument: arguments) { + if (argumentIdx > 0 || populateThis == true) inlineFunctionScriptCode+= ","; + inlineFunctionScriptCode+= argument; + argumentIdx++; + } + inlineFunctionScriptCode+= string() + ")" + "\n"; + // function definition + auto scriptCode = string(functionScriptCode); + auto lineIdx = MiniScript::LINE_FIRST; + auto currentLineIdx = MiniScript::LINE_FIRST; + for (auto i = 0; i < scriptCode.size(); i++) { + // + currentLineIdx = lineIdx; + + // try to get next statement code + auto statementCode = getNextStatement(scriptCode, i, lineIdx); + // + inlineFunctionScriptCode+= doStatementPreProcessing(statementCode, statement) + "\n"; + } + // + inlineFunctionScriptCode+= "\n"; + inlineFunctionScriptCode+= string() + "end" + "\n"; + // store it to be parsed later + deferredFunctionScriptCodes.push_back(inlineFunctionScriptCode); + // + variable.setFunctionAssignment(functionName); +} + +const MiniScript::Variable MiniScript::initializeArray(const string_view& initializerString, MiniScript* miniScript, const Statement& statement) { + Variable variable; variable.setType(TYPE_ARRAY); // auto bracketCount = 0; @@ -2877,7 +2936,7 @@ const MiniScript::ScriptVariable MiniScript::initializeArray(const string_view& if (arrayValueLength > 0) { auto arrayValueStringView = StringTools::viewTrim(string_view(&initializerString[arrayValueStart], arrayValueLength)); if (arrayValueStringView.empty() == false) { - ScriptVariable arrayValue; + Variable arrayValue; arrayValue.setImplicitTypedValueFromStringView(arrayValueStringView, miniScript, statement); variable.pushArrayEntry(arrayValue); } @@ -2989,14 +3048,14 @@ const MiniScript::ScriptVariable MiniScript::initializeArray(const string_view& lc = c; } // - auto initalizer = make_unique(string(initializerString), statement, nullptr); + auto initalizer = make_unique(string(initializerString), statement, nullptr); variable.ir.initializer->copy(initalizer.get()); // return variable; } -const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& initializerString, MiniScript* miniScript, const ScriptStatement& statement) { - ScriptVariable variable; +const MiniScript::Variable MiniScript::initializeMapSet(const string_view& initializerString, MiniScript* miniScript, const Statement& statement) { + Variable variable; variable.setType(TYPE_MAP); // auto bracketCount = 0; @@ -3068,7 +3127,7 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& if (mapValueLength > 0) { auto mapValueStringView = StringTools::viewTrim(string_view(&initializerString[mapValueStart], mapValueLength)); if (mapValueStringView.empty() == false) { - ScriptVariable mapValue; + Variable mapValue; mapValue.setImplicitTypedValueFromStringView(mapValueStringView, miniScript, statement); // variable.setMapEntry(string(mapKey), mapValue); @@ -3078,7 +3137,7 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& } } else { // - variable.setMapEntry(string(mapKey), ScriptVariable()); + variable.setMapEntry(string(mapKey), Variable()); } } // @@ -3095,6 +3154,7 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& auto lc = '\0'; for (; i < initializerString.size(); i++) { auto c = initializerString[i]; + auto nc = i < initializerString.size() - 1?initializerString[i + 1]:'\0'; // quotes if (curlyBracketCount == 1 && squareBracketCount == 0 && (c == '"' || c == '\'') && lc != '\\') { // we have a new quote here @@ -3126,7 +3186,7 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& } else // no quote if (quote == '\0') { - if (curlyBracketCount == 1 && squareBracketCount == 0 && bracketCount == 0 && c == ':' && lc != '\\') { + if (curlyBracketCount == 1 && squareBracketCount == 0 && bracketCount == 0 && c == ':' && nc != ':' && lc != ':' && lc != '\\') { // if (quotedMapKeyStart != string::npos) { quotedMapKeyEnd = i - 1; @@ -3229,39 +3289,9 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& // vector arguments; string_view functionScriptCodeStringView; - if (viewIsInlineFunction(mapValueStringView, arguments, functionScriptCodeStringView) == true) { - string functionScriptCode; - // function declaration - auto functionName = string() + "map_inline_function_" + to_string(miniScript->inlineFunctionIdx++); - functionScriptCode = "function: " + functionName + "(&$this"; - auto argumentIdx = 0; - for (const auto& argument: arguments) { - functionScriptCode+= ","; - functionScriptCode+= argument; - argumentIdx++; - } - functionScriptCode+= string() + ")" + "\n"; - // function definition - auto scriptCode = string(functionScriptCodeStringView); - auto lineIdx = MiniScript::LINE_FIRST; - auto currentLineIdx = MiniScript::LINE_FIRST; - for (auto i = 0; i < scriptCode.size(); i++) { - // - currentLineIdx = lineIdx; - - // try to get next statement code - auto statementCode = miniScript->getNextStatement(scriptCode, i, lineIdx); - // - functionScriptCode+= miniScript->doStatementPreProcessing(statementCode, statement) + "\n"; - } - // - functionScriptCode+= "\n"; - functionScriptCode+= string() + "end" + "\n"; - // store it to be parsed later - miniScript->deferredFunctionScriptCodes.push_back(functionScriptCode); - // - ScriptVariable mapValue; - mapValue.setFunctionAssignment(functionName); + if (viewIsLamdaFunction(mapValueStringView, arguments, functionScriptCodeStringView) == true) { + Variable mapValue; + miniScript->createLamdaFunction(mapValue, arguments, functionScriptCodeStringView, true, statement); variable.setMapEntry(string(mapKey), mapValue); } else { // map/set @@ -3351,7 +3381,7 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& } // convert to set if no values given if (hasValues == false) { - ScriptVariable setVariable; + Variable setVariable; setVariable.setType(TYPE_SET); const auto& mapValueReference = variable.getMapValueReference(); for (const auto& [mapVariableKey, mapVariableValue]: mapValueReference) { @@ -3360,17 +3390,17 @@ const MiniScript::ScriptVariable MiniScript::initializeMapSet(const string_view& variable = setVariable; } // - auto initalizer = make_unique(string(initializerString), statement, nullptr); + auto initalizer = make_unique(string(initializerString), statement, nullptr); variable.ir.initializer->copy(initalizer.get()); // return variable; } -void MiniScript::ScriptVariable::setFunctionCallStatement(const string& initializerStatement, MiniScript* miniScript, const ScriptStatement& statement) { +void MiniScript::Variable::setFunctionCallStatement(const string& initializerStatement, MiniScript* miniScript, const Statement& statement) { setType(TYPE_FUNCTION_CALL); getStringValueReference().setValue(initializerStatement); // - ScriptStatement initializerScriptStatement( + Statement initializerScriptStatement( statement.line, statement.statementIdx, initializerStatement, @@ -3381,18 +3411,18 @@ void MiniScript::ScriptVariable::setFunctionCallStatement(const string& initiali string_view methodName; vector arguments; string accessObjectMemberStatement; - ScriptSyntaxTreeNode* evaluateSyntaxTree = new ScriptSyntaxTreeNode(); - if (miniScript->parseScriptStatement(initializerStatement, methodName, arguments, initializerScriptStatement, accessObjectMemberStatement) == false) { + SyntaxTreeNode* evaluateSyntaxTree = new SyntaxTreeNode(); + if (miniScript->parseStatement(initializerStatement, methodName, arguments, initializerScriptStatement, accessObjectMemberStatement) == false) { // } else - if (miniScript->createScriptStatementSyntaxTree(methodName, arguments, initializerScriptStatement, *evaluateSyntaxTree) == false) { + if (miniScript->createStatementSyntaxTree(methodName, arguments, initializerScriptStatement, *evaluateSyntaxTree) == false) { // } else { getInitializerReference() = new Initializer(initializerStatement, statement, evaluateSyntaxTree); } } -inline MiniScript::ScriptVariable* MiniScript::getVariableIntern(const string& name, const string& callerMethod, ScriptVariable*& parentVariable, int64_t& arrayIdx, string& key, int& setAccessBool, const ScriptStatement* statement, bool expectVariable, bool global) { +inline MiniScript::Variable* MiniScript::getVariableIntern(const string& name, const string& callerMethod, Variable*& parentVariable, int64_t& arrayIdx, string& key, int& setAccessBool, const Statement* statement, bool expectVariable, bool global) { // if (isVariableAccess(name) == false) { if (statement != nullptr) { @@ -3420,11 +3450,11 @@ inline MiniScript::ScriptVariable* MiniScript::getVariableIntern(const string& n return nullptr; } // retrieve variable from function script state - ScriptVariable* variablePtr = nullptr; + Variable* variablePtr = nullptr; if (global == false) { const auto& scriptState = getScriptState(); - auto scriptVariableIt = scriptState.variables.find(extractedVariableName.empty() == false?extractedVariableName:name); - if (scriptVariableIt == scriptState.variables.end()) { + auto variableIt = scriptState.variables.find(extractedVariableName.empty() == false?extractedVariableName:name); + if (variableIt == scriptState.variables.end()) { if (isFunctionRunning() == false) { if (expectVariable == true) { if (statement != nullptr) { @@ -3436,14 +3466,14 @@ inline MiniScript::ScriptVariable* MiniScript::getVariableIntern(const string& n return nullptr; } } else { - variablePtr = scriptVariableIt->second; + variablePtr = variableIt->second; } } // if no success try to retrieve variable from root script state, but only when expecting variable aka reading variable if (global == true || (expectVariable == true && variablePtr == nullptr)) { const auto& scriptState = getRootScriptState(); - auto scriptVariableIt = scriptState.variables.find(extractedVariableName.empty() == false?extractedVariableName:name); - if (scriptVariableIt == scriptState.variables.end()) { + auto variableIt = scriptState.variables.find(extractedVariableName.empty() == false?extractedVariableName:name); + if (variableIt == scriptState.variables.end()) { if (expectVariable == true) { if (statement != nullptr) { Console::println(getStatementInformation(*statement) + ": variable: " + name + " does not exist"); @@ -3453,7 +3483,7 @@ inline MiniScript::ScriptVariable* MiniScript::getVariableIntern(const string& n } return nullptr; } else { - variablePtr = scriptVariableIt->second; + variablePtr = variableIt->second; } } // @@ -3596,8 +3626,8 @@ inline MiniScript::ScriptVariable* MiniScript::getVariableIntern(const string& n } } -inline bool MiniScript::evaluateInternal(const string& statement, const string& executableStatement, ScriptVariable& returnValue, bool pushOwnScriptState) { - ScriptStatement evaluateStatement( +inline bool MiniScript::evaluateInternal(const string& statement, const string& executableStatement, Variable& returnValue, bool pushOwnScriptState) { + Statement evaluateStatement( LINE_NONE, 0, "internal.script.evaluate(" + statement + ")", @@ -3609,11 +3639,11 @@ inline bool MiniScript::evaluateInternal(const string& statement, const string& string_view methodName; vector arguments; string accessObjectMemberStatement; - ScriptSyntaxTreeNode evaluateSyntaxTree; - if (parseScriptStatement(scriptEvaluateStatement, methodName, arguments, evaluateStatement, accessObjectMemberStatement) == false) { + SyntaxTreeNode evaluateSyntaxTree; + if (parseStatement(scriptEvaluateStatement, methodName, arguments, evaluateStatement, accessObjectMemberStatement) == false) { return false; } else - if (createScriptStatementSyntaxTree(methodName, arguments, evaluateStatement, evaluateSyntaxTree) == false) { + if (createStatementSyntaxTree(methodName, arguments, evaluateStatement, evaluateSyntaxTree) == false) { return false; } else { // @@ -3623,7 +3653,7 @@ inline bool MiniScript::evaluateInternal(const string& statement, const string& } getScriptState().running = true; // - returnValue = executeScriptStatement( + returnValue = executeStatement( evaluateSyntaxTree, evaluateStatement ); @@ -3634,11 +3664,11 @@ inline bool MiniScript::evaluateInternal(const string& statement, const string& } } -inline const MiniScript::ScriptVariable MiniScript::initializeVariable(const ScriptVariable& variable) { +inline const MiniScript::Variable MiniScript::initializeVariable(const Variable& variable) { switch (variable.getType()) { case TYPE_ARRAY: { - ScriptVariable arrayVariable; + Variable arrayVariable; // arrayVariable.setType(TYPE_ARRAY); auto arrayPointer = variable.getArrayPointer(); @@ -3651,7 +3681,7 @@ inline const MiniScript::ScriptVariable MiniScript::initializeVariable(const Scr } case TYPE_MAP: { - ScriptVariable mapVariable; + Variable mapVariable; // auto mapPointer = variable.getMapPointer(); if (mapPointer == nullptr) break; @@ -3663,7 +3693,7 @@ inline const MiniScript::ScriptVariable MiniScript::initializeVariable(const Scr } case TYPE_FUNCTION_CALL: { - return executeScriptStatement( + return executeStatement( *variable.getInitializer()->getSyntaxTree(), variable.getInitializer()->getStatement() ); @@ -3684,7 +3714,7 @@ inline bool MiniScript::viewIsKey(const string_view& candidate) { return true; } -inline bool MiniScript::getVariableAccessOperatorLeftRightIndices(const string& name, const string& callerMethod, string::size_type& accessOperatorLeftIdx, string::size_type& accessOperatorRightIdx, const ScriptStatement* statement, int startIdx) { +inline bool MiniScript::getVariableAccessOperatorLeftRightIndices(const string& name, const string& callerMethod, string::size_type& accessOperatorLeftIdx, string::size_type& accessOperatorRightIdx, const Statement* statement, int startIdx) { accessOperatorLeftIdx = string::npos; accessOperatorRightIdx = string::npos; auto haveKey = false; @@ -3750,7 +3780,7 @@ inline bool MiniScript::getVariableAccessOperatorLeftRightIndices(const string& return true; } -inline bool MiniScript::evaluateAccess(const string& name, const string& callerMethod, string::size_type& arrayAccessOperatorLeftIdx, string::size_type& arrayAccessOperatorRightIdx, int64_t& arrayIdx, string& key, const ScriptStatement* statement) { +inline bool MiniScript::evaluateAccess(const string& name, const string& callerMethod, string::size_type& arrayAccessOperatorLeftIdx, string::size_type& arrayAccessOperatorRightIdx, int64_t& arrayIdx, string& key, const Statement* statement) { key.clear(); arrayIdx = ARRAYIDX_NONE; // check for dot access @@ -3766,7 +3796,7 @@ inline bool MiniScript::evaluateAccess(const string& name, const string& callerM arrayIdx = Integer::viewParse(arrayIdxExpressionStringView); } else { // TODO: as evaluate statement we also might need the expression that had not yet a preprocessor run for error messages and such - ScriptVariable statementReturnValue; + Variable statementReturnValue; auto evaluateStatement = string(arrayIdxExpressionStringView); if (evaluateInternal(evaluateStatement, evaluateStatement, statementReturnValue, false) == false || statementReturnValue.getIntegerValue(arrayIdx, false) == false) { if (statement != nullptr) { @@ -3784,3 +3814,31 @@ inline bool MiniScript::evaluateAccess(const string& name, const string& callerM // return true; } + +void MiniScript::setConstant(Variable& variable) { + variable.setConstant(); + switch (variable.getType()) { + case TYPE_ARRAY: + { + auto arrayPointer = variable.getArrayPointer(); + if (arrayPointer == nullptr) break; + for (const auto arrayEntry: *arrayPointer) { + setConstant(*arrayEntry); + } + // + break; + } + case TYPE_MAP: + { + auto mapPointer = variable.getMapPointer(); + if (mapPointer == nullptr) break; + for (const auto& [mapKey, mapValue]: *mapPointer) { + setConstant(*mapValue); + } + // + break; + } + default: + break; + } +} diff --git a/ext/miniscript/src/miniscript/miniscript/MiniScript.h b/ext/miniscript/src/miniscript/miniscript/MiniScript.h index cc9b58482..f9374045e 100644 --- a/ext/miniscript/src/miniscript/miniscript/MiniScript.h +++ b/ext/miniscript/src/miniscript/miniscript/MiniScript.h @@ -69,7 +69,7 @@ class miniscript::miniscript::MiniScript { friend class Transpiler; public: - enum ScriptOperator { + enum Operator { // see: https://en.cppreference.com/w/cpp/language/operator_precedence OPERATOR_NONE, // priority 2 @@ -109,15 +109,15 @@ class miniscript::miniscript::MiniScript { OPERATOR_MAX }; - enum StateMachineState { + enum StateMachineStateId { STATEMACHINESTATE_NONE = -1, STATEMACHINESTATE_NEXT_STATEMENT, STATEMACHINESTATE_WAIT, STATEMACHINESTATE_WAIT_FOR_CONDITION }; - struct ScriptStatement { - ScriptStatement( + struct Statement { + Statement( int line, int statementIdx, const string& statement, @@ -137,7 +137,7 @@ class miniscript::miniscript::MiniScript { int gotoStatementIdx; }; - enum ScriptVariableType { + enum VariableType { // primitives TYPE_NULL, TYPE_BOOLEAN, @@ -159,13 +159,13 @@ class miniscript::miniscript::MiniScript { }; // - class ScriptSyntaxTreeNode; - class ScriptVariable; + class SyntaxTreeNode; + class Variable; /** - * Script data type + * Data type */ - class ScriptDataType { + class DataType { friend class MiniScript; friend class MathMethods; @@ -190,83 +190,83 @@ class miniscript::miniscript::MiniScript { /** * Register methods - * @param miniScript mini script instance + * @param miniScript MiniScript instance */ virtual void registerMethods(MiniScript* miniScript) const = 0; /** - * Unset script variable value + * Unset variable value * @param variable variable */ - virtual void unsetScriptVariableValue(ScriptVariable& variable) const = 0; + virtual void unsetVariableValue(Variable& variable) const = 0; /** - * Set script variable value + * Set variable value * @param variable variable * @param value value */ - virtual void setScriptVariableValue(ScriptVariable& variable, const void* value) const = 0; + virtual void setVariableValue(Variable& variable, const void* value) const = 0; /** - * Copy script variable + * Copy variable * @param to to * @param from from */ - virtual void copyScriptVariable(ScriptVariable& to, const ScriptVariable& from) const = 0; + virtual void copyVariable(Variable& to, const Variable& from) const = 0; /** * Multiply - * @param miniScript mini script instance - * @param argumentValues argument values + * @param miniScript MiniScript instance + * @param arguments argument values * @param returnValue return value * @param statement statement * @return mul was executed */ - virtual bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const = 0; + virtual bool mul(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const = 0; /** * Division - * @param miniScript mini script instance - * @param argumentValues argument values + * @param miniScript MiniScript instance + * @param arguments argument values * @param returnValue return value * @param statement statement * @return div was executed */ - virtual bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const = 0; + virtual bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const = 0; /** * Addition - * @param miniScript mini script instance - * @param argumentValues argument values + * @param miniScript MiniScript instance + * @param arguments argument values * @param returnValue return value * @param statement statement * @return add was executed */ - virtual bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const = 0; + virtual bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const = 0; /** * Subtraction - * @param miniScript mini script instance - * @param argumentValues argument values + * @param miniScript MiniScript instance + * @param arguments argument values * @param returnValue return value * @param statement statement * @return sub was executed */ - virtual bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const = 0; + virtual bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const = 0; public: // forbid class copy - FORBID_CLASS_COPY(ScriptDataType) + FORBID_CLASS_COPY(DataType) /** - * Script data type + * Data type * @param mathDataType is math data type and provides math methods */ - ScriptDataType(bool mathDataType): mathDataType(mathDataType) { + DataType(bool mathDataType): mathDataType(mathDataType) { // } - virtual ~ScriptDataType() { + virtual ~DataType() { // } @@ -277,11 +277,6 @@ class miniscript::miniscript::MiniScript { return type; } - /** - * @return class name - */ - virtual const string& getClassName() const = 0; - /** * @return type as string */ @@ -292,19 +287,19 @@ class miniscript::miniscript::MiniScript { * @param variable variable * @return value as string */ - virtual const string getValueAsString(const ScriptVariable& variable) const = 0; + virtual const string getValueAsString(const Variable& variable) const = 0; }; /** - * MiniScript script variable + * Variable */ - class ScriptVariable { + class Variable { friend class MiniScript; private: /** - * MiniScript variable initializer + * Variable initializer */ class Initializer { public: @@ -313,7 +308,7 @@ class miniscript::miniscript::MiniScript { */ Initializer(): statement( - MiniScript::ScriptStatement( + MiniScript::Statement( MiniScript::LINE_NONE, MiniScript::STATEMENTIDX_NONE, string(), @@ -321,7 +316,7 @@ class miniscript::miniscript::MiniScript { MiniScript::STATEMENTIDX_NONE ) ), - syntaxTree(new ScriptSyntaxTreeNode()) { + syntaxTree(new SyntaxTreeNode()) { // } @@ -331,7 +326,7 @@ class miniscript::miniscript::MiniScript { * @param statement statement * @param syntaxTree syntax tree */ - Initializer(const string& initializerString, const ScriptStatement& statement, ScriptSyntaxTreeNode* syntaxTree): initializerString(initializerString), statement(statement), syntaxTree(syntaxTree) {} + Initializer(const string& initializerString, const Statement& statement, SyntaxTreeNode* syntaxTree): initializerString(initializerString), statement(statement), syntaxTree(syntaxTree) {} /** * Destructor @@ -360,38 +355,39 @@ class miniscript::miniscript::MiniScript { /** * @return statement */ - const ScriptStatement& getStatement() const { + const Statement& getStatement() const { return statement; } /** * @return syntax tree node */ - const ScriptSyntaxTreeNode* getSyntaxTree() const { + const SyntaxTreeNode* getSyntaxTree() const { return syntaxTree; } private: string initializerString; - ScriptStatement statement; - ScriptSyntaxTreeNode* syntaxTree; + Statement statement; + SyntaxTreeNode* syntaxTree; }; // + static constexpr uint32_t TYPE_BITS_VALUE { 1073741823 }; // 2 ^ 30 - 1 + static constexpr uint32_t CONSTANT_BIT_VALUE { 1073741824 }; // 2 ^ 30 static constexpr uint32_t REFERENCE_BIT_VALUE { 2147483648 }; // 2 ^ 31 - static constexpr uint32_t TYPE_BITS_VALUE { 2147483647 }; // 2 ^ 31 - 1 // union ir { Initializer* initializer; - ScriptVariable* reference; + Variable* reference; }; /** * String value */ class StringValue { - friend class ScriptVariable; + friend class Variable; public: /** * Constructor @@ -448,23 +444,46 @@ class miniscript::miniscript::MiniScript { }; // 24 bytes - uint32_t typeAndReference { TYPE_NULL }; // 4 bytes + uint32_t typeReferenceConstantBits { TYPE_NULL }; // 4 bytes int32_t referenceCounter { 1 }; // 4 bytes uint64_t valuePtr { 0LL }; // 8 bytes ir ir {}; // 8 bytes + /** + * @return is constant + */ + inline bool isConstant() const { + return + (typeReferenceConstantBits & CONSTANT_BIT_VALUE) == CONSTANT_BIT_VALUE || + (isReference() == true && (ir.reference->typeReferenceConstantBits & CONSTANT_BIT_VALUE) == CONSTANT_BIT_VALUE); + } + + /** + * Set constant + */ + inline void setConstant() { + typeReferenceConstantBits|= CONSTANT_BIT_VALUE; + } + + /** + * Unset constant + */ + inline void unsetConstant() { + typeReferenceConstantBits&= TYPE_BITS_VALUE | REFERENCE_BIT_VALUE; + } + /** * @return is reference */ inline bool isReference() const { - return (typeAndReference & REFERENCE_BIT_VALUE) == REFERENCE_BIT_VALUE; + return (typeReferenceConstantBits & REFERENCE_BIT_VALUE) == REFERENCE_BIT_VALUE; } /** * @return unset reference */ inline void unsetReference() { - typeAndReference&= TYPE_BITS_VALUE; + typeReferenceConstantBits&= TYPE_BITS_VALUE | CONSTANT_BIT_VALUE; ir.reference = nullptr; } @@ -472,9 +491,9 @@ class miniscript::miniscript::MiniScript { * Set reference * @param variable variable */ - inline void setReference(ScriptVariable* variable) { - typeAndReference|= REFERENCE_BIT_VALUE; - ir.reference = (ScriptVariable*)variable; + inline void setReference(Variable* variable) { + typeReferenceConstantBits|= REFERENCE_BIT_VALUE; + ir.reference = (Variable*)variable; ir.reference->acquireReference(); } @@ -504,7 +523,7 @@ class miniscript::miniscript::MiniScript { * @return initializer */ inline Initializer*& getInitializerReference() { - return isReference() == true?ir.reference->ir.initializer:ir.initializer; + return isReference() == false?ir.initializer:ir.reference->ir.initializer; } /** @@ -512,7 +531,7 @@ class miniscript::miniscript::MiniScript { * @return value ptr */ inline const uint64_t& getValuePtrReference() const { - return isReference() == true?ir.reference->valuePtr:valuePtr; + return isReference() == false?valuePtr:ir.reference->valuePtr; } /** @@ -520,7 +539,7 @@ class miniscript::miniscript::MiniScript { * @return value ptr */ inline uint64_t& getValuePtrReference() { - return isReference() == true?ir.reference->valuePtr:valuePtr; + return isReference() == false?valuePtr:ir.reference->valuePtr; } /** @@ -596,29 +615,29 @@ class miniscript::miniscript::MiniScript { /** * @return array value reference */ - inline vector& getArrayValueReference() { - return *static_cast*>((void*)getValuePtrReference()); + inline vector& getArrayValueReference() { + return *static_cast*>((void*)getValuePtrReference()); } /** * @return const array value reference */ - inline const vector& getArrayValueReference() const { - return *static_cast*>((void*)getValuePtrReference()); + inline const vector& getArrayValueReference() const { + return *static_cast*>((void*)getValuePtrReference()); } /** * @return map value reference */ - inline unordered_map& getMapValueReference() { - return *static_cast*>((void*)getValuePtrReference()); + inline unordered_map& getMapValueReference() { + return *static_cast*>((void*)getValuePtrReference()); } /** * @return const map value reference */ - inline const unordered_map& getMapValueReference() const { - return *static_cast*>((void*)getValuePtrReference()); + inline const unordered_map& getMapValueReference() const { + return *static_cast*>((void*)getValuePtrReference()); } /** @@ -637,24 +656,31 @@ class miniscript::miniscript::MiniScript { public: // class names - MINISCRIPT_STATIC_DLL_IMPEXT static const string CLASSNAME_NONE; - MINISCRIPT_STATIC_DLL_IMPEXT static const string CLASSNAME_STRING; - MINISCRIPT_STATIC_DLL_IMPEXT static const string CLASSNAME_BYTEARRAY; - MINISCRIPT_STATIC_DLL_IMPEXT static const string CLASSNAME_ARRAY; - MINISCRIPT_STATIC_DLL_IMPEXT static const string CLASSNAME_MAP; - MINISCRIPT_STATIC_DLL_IMPEXT static const string CLASSNAME_SET; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_NONE; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_NULL; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_BOOLEAN; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_INTEGER; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_FLOAT; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_FUNCTION; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_NUMBER; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_MIXED; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_STRING; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_BYTEARRAY; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_ARRAY; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_MAP; + MINISCRIPT_STATIC_DLL_IMPEXT static const string TYPENAME_SET; /** * Create reference variable * @param variable variable * @returns reference variable */ - inline static ScriptVariable createReferenceVariable(const ScriptVariable* variable) { + inline static Variable createReferenceVariable(const Variable* variable) { // copy a reference variable is cheap if (variable->isReference() == true) return *variable; // - ScriptVariable referenceVariable; - referenceVariable.setReference((ScriptVariable*)variable); + Variable referenceVariable; + referenceVariable.setReference((Variable*)variable); return referenceVariable; } @@ -663,21 +689,21 @@ class miniscript::miniscript::MiniScript { * @param variable variable * @returns reference variable */ - inline static ScriptVariable* createReferenceVariablePointer(const ScriptVariable* variable) { + inline static Variable* createReferenceVariablePointer(const Variable* variable) { // copy a reference variable is cheap - if (variable->isReference() == true) return new ScriptVariable(*variable); + if (variable->isReference() == true) return new Variable(*variable); // - ScriptVariable* referenceVariable = new ScriptVariable(); - referenceVariable->setReference((ScriptVariable*)variable); + Variable* referenceVariable = new Variable(); + referenceVariable->setReference((Variable*)variable); return referenceVariable; } /** - * Copy script variable + * Copy variable * @param from from * @param to to */ - inline static void copyScriptVariable(ScriptVariable& to, const ScriptVariable& from) { + inline static void copyVariable(Variable& to, const Variable& from) { // initial setup to.setType(from.getType()); // do the copy @@ -734,13 +760,14 @@ class miniscript::miniscript::MiniScript { default: // custom data type auto dataTypeIdx = static_cast(from.getType()) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { + if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { _Console::println("ScriptVariable::copyScriptVariable(): unknown custom data type with id " + to_string(dataTypeIdx)); return; } - MiniScript::scriptDataTypes[dataTypeIdx]->copyScriptVariable(to, from); + MiniScript::dataTypes[dataTypeIdx]->copyVariable(to, from); } - + // + if (from.isConstant() == true) to.setConstant(); } /** @@ -748,13 +775,13 @@ class miniscript::miniscript::MiniScript { * @param variable variable * @returns reference variable */ - inline static ScriptVariable createNonReferenceVariable(const ScriptVariable* variable) { + inline static Variable createNonReferenceVariable(const Variable* variable) { // copy a non reference variable is cheap if (variable->isReference() == false) return *variable; // otherwise do the copy - ScriptVariable nonReferenceVariable; + Variable nonReferenceVariable; // - copyScriptVariable(nonReferenceVariable, *variable); + copyVariable(nonReferenceVariable, *variable); // return nonReferenceVariable; } @@ -764,13 +791,13 @@ class miniscript::miniscript::MiniScript { * @param variable variable * @returns reference variable */ - inline static ScriptVariable* createNonReferenceVariablePointer(const ScriptVariable* variable) { + inline static Variable* createNonReferenceVariablePointer(const Variable* variable) { // copy a non reference variable is cheap - if (variable->isReference() == false) return new ScriptVariable(*variable); + if (variable->isReference() == false) return new Variable(*variable); // otherwise do the copy - ScriptVariable* nonReferenceVariable = new ScriptVariable(); + Variable* nonReferenceVariable = new Variable(); // - copyScriptVariable(*nonReferenceVariable, *variable); + copyVariable(*nonReferenceVariable, *variable); // return nonReferenceVariable; } @@ -779,11 +806,11 @@ class miniscript::miniscript::MiniScript { * Copy constructor * @param variable variable to copy */ - inline ScriptVariable(const ScriptVariable& variable) { + inline Variable(const Variable& variable) { if (variable.isReference() == true) { setReference(variable.ir.reference); } else { - copyScriptVariable(*this, variable); + copyVariable(*this, variable); } } @@ -791,8 +818,8 @@ class miniscript::miniscript::MiniScript { * Move constructor * @param variable variable to move from */ - inline ScriptVariable(ScriptVariable&& variable): - typeAndReference(exchange(variable.typeAndReference, static_cast(MiniScript::TYPE_NULL))), + inline Variable(Variable&& variable): + typeReferenceConstantBits(exchange(variable.typeReferenceConstantBits, static_cast(MiniScript::TYPE_NULL))), valuePtr(exchange(variable.valuePtr, 0ll)), referenceCounter(exchange(variable.referenceCounter, 1)) { // TODO: improve me @@ -805,7 +832,7 @@ class miniscript::miniscript::MiniScript { * @param variable variable to copy * @return this variable */ - inline ScriptVariable& operator=(const ScriptVariable& variable) { + inline Variable& operator=(const Variable& variable) { // set up new variable if (variable.isReference() == true) { // release current reference @@ -820,7 +847,7 @@ class miniscript::miniscript::MiniScript { } else { setType(TYPE_NULL); // - copyScriptVariable(*this, variable); + copyVariable(*this, variable); } // return *this; @@ -829,10 +856,10 @@ class miniscript::miniscript::MiniScript { /** * Move operator * @param variable variable to move from - * @return this script variable + * @return this variable */ - inline ScriptVariable& operator=(ScriptVariable&& variable) { - swap(typeAndReference, variable.typeAndReference); + inline Variable& operator=(Variable&& variable) { + swap(typeReferenceConstantBits, variable.typeReferenceConstantBits); swap(valuePtr, variable.valuePtr); swap(ir, variable.ir); swap(referenceCounter, variable.referenceCounter); @@ -843,13 +870,13 @@ class miniscript::miniscript::MiniScript { /** * Constructor */ - inline ScriptVariable() { + inline Variable() { } /** * Destructor */ - inline ~ScriptVariable() { + inline ~Variable() { if (isReference() == true) { ir.reference->releaseReference(); } @@ -863,7 +890,7 @@ class miniscript::miniscript::MiniScript { * Constructor * @param value value */ - inline ScriptVariable(bool value) { + inline Variable(bool value) { setValue(value); } @@ -871,7 +898,7 @@ class miniscript::miniscript::MiniScript { * Constructor * @param value value */ - inline ScriptVariable(int64_t value) { + inline Variable(int64_t value) { setValue(value); } @@ -879,7 +906,7 @@ class miniscript::miniscript::MiniScript { * Constructor * @param value value */ - inline ScriptVariable(float value) { + inline Variable(float value) { setValue(value); } @@ -887,7 +914,7 @@ class miniscript::miniscript::MiniScript { * Constructor * @param value value */ - inline ScriptVariable(const string& value) { + inline Variable(const string& value) { setValue(value); } @@ -895,7 +922,7 @@ class miniscript::miniscript::MiniScript { * Constructor * @param value value */ - inline ScriptVariable(const vector& value) { + inline Variable(const vector& value) { setValue(value); } @@ -903,22 +930,22 @@ class miniscript::miniscript::MiniScript { * Constructor * @param value value */ - inline ScriptVariable(const unordered_map& value) { + inline Variable(const unordered_map& value) { setValue(value); } /** * @return type */ - inline ScriptVariableType getType() const { - return static_cast((isReference() == true?ir.reference->typeAndReference:typeAndReference) & TYPE_BITS_VALUE); + inline VariableType getType() const { + return static_cast((isReference() == false?typeReferenceConstantBits:ir.reference->typeReferenceConstantBits) & TYPE_BITS_VALUE); } /** * Set type * @param newType new type */ - inline void setType(ScriptVariableType newType) { + inline void setType(VariableType newType) { if (getType() == newType) return; switch(getType()) { case TYPE_NULL: @@ -945,13 +972,13 @@ class miniscript::miniscript::MiniScript { break; case TYPE_ARRAY: for (auto arrayValue: getArrayValueReference()) arrayValue->releaseReference(); - delete static_cast*>((void*)getValuePtrReference()); + delete static_cast*>((void*)getValuePtrReference()); delete getInitializerReference(); getInitializerReference() = nullptr; break; case TYPE_MAP: for (const auto& [mapEntryName, mapEntryValue]: getMapValueReference()) mapEntryValue->releaseReference(); - delete static_cast*>((void*)getValuePtrReference()); + delete static_cast*>((void*)getValuePtrReference()); delete getInitializerReference(); getInitializerReference() = nullptr; break; @@ -963,19 +990,23 @@ class miniscript::miniscript::MiniScript { default: // custom data type auto dataTypeIdx = static_cast(this->getType()) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { + if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { _Console::println("ScriptVariable::setType(): unknown custom data type with id " + to_string(dataTypeIdx)); return; } - MiniScript::scriptDataTypes[dataTypeIdx]->unsetScriptVariableValue(*this); + MiniScript::dataTypes[dataTypeIdx]->unsetVariableValue(*this); } this->getValuePtrReference() = 0LL; // if (isReference() == true) { - ir.reference->typeAndReference = newType; + ir.reference->typeReferenceConstantBits = + static_cast(newType) | + ((ir.reference->typeReferenceConstantBits & CONSTANT_BIT_VALUE) == CONSTANT_BIT_VALUE?CONSTANT_BIT_VALUE:0); } else { - typeAndReference = newType; + typeReferenceConstantBits = + static_cast(newType) | + ((typeReferenceConstantBits & CONSTANT_BIT_VALUE) == CONSTANT_BIT_VALUE?CONSTANT_BIT_VALUE:0); } // switch(getType()) { @@ -997,11 +1028,11 @@ class miniscript::miniscript::MiniScript { getValuePtrReference() = (uint64_t)(new vector()); break; case TYPE_ARRAY: - getValuePtrReference() = (uint64_t)(new vector()); + getValuePtrReference() = (uint64_t)(new vector()); getInitializerReference() = new Initializer(); break; case TYPE_MAP: - getValuePtrReference() = (uint64_t)(new unordered_map()); + getValuePtrReference() = (uint64_t)(new unordered_map()); getInitializerReference() = new Initializer(); break; case TYPE_SET: @@ -1015,11 +1046,11 @@ class miniscript::miniscript::MiniScript { default: // custom data type auto dataTypeIdx = static_cast(this->getType()) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { + if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { _Console::println("ScriptVariable::setType(): unknown custom data type with id " + to_string(dataTypeIdx)); return; } - MiniScript::scriptDataTypes[dataTypeIdx]->setScriptVariableValue(*this, nullptr); + MiniScript::dataTypes[dataTypeIdx]->setVariableValue(*this, nullptr); } } @@ -1186,7 +1217,7 @@ class miniscript::miniscript::MiniScript { * @param statement statement * @return success */ - inline bool getByteValue(MiniScript* miniScript, uint8_t& value, const ScriptStatement* statement = nullptr) const { + inline bool getByteValue(MiniScript* miniScript, uint8_t& value, const Statement* statement = nullptr) const { int64_t intValue; if (getIntegerValue(intValue, false) == true && value >= 0 && value <= 255) { value = intValue; @@ -1275,11 +1306,11 @@ class miniscript::miniscript::MiniScript { * Set array value from given value into variable * @param value value */ - inline void setValue(const vector& value) { + inline void setValue(const vector& value) { setType(TYPE_ARRAY); auto& arrayValue = getArrayValueReference(); for (const auto arrayEntry: value) { - arrayValue.push_back(new ScriptVariable(*arrayEntry)); + arrayValue.push_back(new Variable(*arrayEntry)); } } @@ -1287,11 +1318,11 @@ class miniscript::miniscript::MiniScript { * Set map value from given value into variable * @param value value */ - inline void setValue(const unordered_map& value) { + inline void setValue(const unordered_map& value) { setType(TYPE_MAP); auto& mapValue = getMapValueReference(); for (const auto& [mapEntryName, mapEntryValue]: value) { - mapValue[mapEntryName] = new ScriptVariable(*mapEntryValue); + mapValue[mapEntryName] = new Variable(*mapEntryValue); } } @@ -1311,11 +1342,11 @@ class miniscript::miniscript::MiniScript { inline void setValue(const void* value) { // custom data type auto dataTypeIdx = static_cast(this->getType()) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { + if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { _Console::println("ScriptVariable::setValue(): unknown custom data type with id " + to_string(dataTypeIdx)); return; } - MiniScript::scriptDataTypes[dataTypeIdx]->setScriptVariableValue(*this, value); + MiniScript::dataTypes[dataTypeIdx]->setVariableValue(*this, value); } /** @@ -1404,7 +1435,7 @@ class miniscript::miniscript::MiniScript { /** * @return return const pointer to underlying vector or nullptr */ - inline const vector* getArrayPointer() const { + inline const vector* getArrayPointer() const { if (getType() != TYPE_ARRAY) return nullptr; auto& arrayValue = getArrayValueReference(); return &arrayValue; @@ -1413,7 +1444,7 @@ class miniscript::miniscript::MiniScript { /** * @return pointer to underlying vector or nullptr */ - inline vector* getArrayPointer() { + inline vector* getArrayPointer() { if (getType() != TYPE_ARRAY) return nullptr; auto& arrayValue = getArrayValueReference(); return &arrayValue; @@ -1433,33 +1464,33 @@ class miniscript::miniscript::MiniScript { * @param idx index * @return entry from array with given index */ - inline const ScriptVariable getArrayEntry(int64_t idx) const { - if (getType() != TYPE_ARRAY) return ScriptVariable(); + inline const Variable getArrayEntry(int64_t idx) const { + if (getType() != TYPE_ARRAY) return Variable(); const auto& arrayValue = getArrayValueReference(); if (idx >= 0 && idx < arrayValue.size()) return *arrayValue[idx]; - return ScriptVariable(); + return Variable(); } /** * Set entry in array with given index * @param idx index */ - inline void setArrayEntry(int64_t idx, const ScriptVariable& value) { + inline void setArrayEntry(int64_t idx, const Variable& value) { setType(TYPE_ARRAY); if (idx < 0) return; auto& arrayValue = getArrayValueReference(); - while (arrayValue.size() <= idx) pushArrayEntry(ScriptVariable()); + while (arrayValue.size() <= idx) pushArrayEntry(Variable()); arrayValue[idx]->releaseReference(); - arrayValue[idx] = new ScriptVariable(value); + arrayValue[idx] = new Variable(value); } /** * Push entry to array * @param value value */ - inline void pushArrayEntry(const ScriptVariable& value) { + inline void pushArrayEntry(const Variable& value) { setType(TYPE_ARRAY); - getArrayValueReference().push_back(new ScriptVariable(value)); + getArrayValueReference().push_back(new Variable(value)); } /** @@ -1484,13 +1515,12 @@ class miniscript::miniscript::MiniScript { auto& arrayValue = getArrayValueReference(); for (auto i = 0; i < arrayValue.size(); i++) arrayValue[i]->releaseReference(); arrayValue.clear(); - return; } /** * @return return const pointer to underlying unordered_map or nullptr */ - inline const unordered_map* getMapPointer() const { + inline const unordered_map* getMapPointer() const { if (getType() != TYPE_MAP) return nullptr; auto& mapValue = getMapValueReference(); return &mapValue; @@ -1499,7 +1529,7 @@ class miniscript::miniscript::MiniScript { /** * @return pointer to underlying unordered_map or nullptr */ - inline unordered_map* getMapPointer() { + inline unordered_map* getMapPointer() { if (getType() != TYPE_MAP) return nullptr; auto& mapValue = getMapValueReference(); return &mapValue; @@ -1531,12 +1561,12 @@ class miniscript::miniscript::MiniScript { * @param key key * @return map entry from given key */ - inline const ScriptVariable getMapEntry(const string& key) const { - if (getType() != TYPE_MAP) return ScriptVariable(); + inline const Variable getMapEntry(const string& key) const { + if (getType() != TYPE_MAP) return Variable(); const auto& mapValue = getMapValueReference(); auto it = mapValue.find(key); if (it != mapValue.end()) return *it->second; - return ScriptVariable(); + return Variable(); } /** @@ -1544,11 +1574,11 @@ class miniscript::miniscript::MiniScript { * @param key key * @param value value */ - inline void setMapEntry(const string& key, const ScriptVariable& value) { + inline void setMapEntry(const string& key, const Variable& value) { setType(TYPE_MAP); auto mapValueIt = getMapValueReference().find(key); if (mapValueIt != getMapValueReference().end()) mapValueIt->second->releaseReference(); - getMapValueReference()[key] = new ScriptVariable(value); + getMapValueReference()[key] = new Variable(value); } /** @@ -1583,8 +1613,8 @@ class miniscript::miniscript::MiniScript { * Get map values * @return values */ - inline const vector getMapValues() const { - vector values; + inline const vector getMapValues() const { + vector values; if (getType() != TYPE_MAP) return values; const auto& mapValue = getMapValueReference(); for (const auto& [mapEntryKey, mapEntryValue]: mapValue) { @@ -1593,6 +1623,18 @@ class miniscript::miniscript::MiniScript { return values; } + /** + * Clear array + */ + inline void clearMap() { + if (getType() != TYPE_MAP) return; + auto& mapValue = getMapValueReference(); + for (const auto& [mapEntryName, mapEntryValue]: mapValue) { + mapEntryValue->releaseReference(); + } + mapValue.clear(); + } + /** * @return const pointer to underlying unordered_set or nullptr */ @@ -1668,13 +1710,22 @@ class miniscript::miniscript::MiniScript { return keys; } + /** + * Clear set + */ + inline void clearSet() { + if (getType() != TYPE_SET) return; + auto& setValue = getSetValueReference(); + setValue.clear(); + } + /** * Set array/map values initializer function call statement * @param miniScript miniscript instance * @param statement statement * @param initializerStatement initializer statement */ - void setFunctionCallStatement(const string& initializerStatement, MiniScript* miniScript, const ScriptStatement& statement); + void setFunctionCallStatement(const string& initializerStatement, MiniScript* miniScript, const Statement& statement); /** * Set function assignment from given value into variable @@ -1691,7 +1742,7 @@ class miniscript::miniscript::MiniScript { * @param miniScript mini script * @param statement statement */ - inline void setImplicitTypedValue(const string& value, MiniScript* miniScript, const ScriptStatement& statement) { + inline void setImplicitTypedValue(const string& value, MiniScript* miniScript, const Statement& statement) { setImplicitTypedValueFromStringView(string_view(value), miniScript, statement); } @@ -1701,7 +1752,7 @@ class miniscript::miniscript::MiniScript { * @param miniScript mini script * @param statement statement */ - inline void setImplicitTypedValueFromStringView(const string_view& value, MiniScript* miniScript, const ScriptStatement& statement) { + inline void setImplicitTypedValueFromStringView(const string_view& value, MiniScript* miniScript, const Statement& statement) { string_view function; // if (value == "null") { @@ -1735,12 +1786,10 @@ class miniscript::miniscript::MiniScript { if (value.find('(') != string::npos && value.find(')') != string::npos) { setFunctionCallStatement(miniScript->doStatementPreProcessing(string(value), statement), miniScript, statement); - _Console::println("Function Call Statement: " + miniScript->doStatementPreProcessing(string(value), statement)); } else // variable if (viewIsVariableAccess(value) == true) { setFunctionCallStatement("getVariable(\"" + string(value) + "\")", miniScript, statement); - _Console::println("Variable Access: " + string(value)); } else { setValue(string(value)); } @@ -1752,7 +1801,7 @@ class miniscript::miniscript::MiniScript { * @param expectedType expected type * @return given variable type does match expected variable type */ - inline static bool isExpectedType(ScriptVariableType type, ScriptVariableType expectedType) { + inline static bool isExpectedType(VariableType type, VariableType expectedType) { if (type == expectedType) return true; switch(expectedType) { case TYPE_PSEUDO_NUMBER: @@ -1765,75 +1814,38 @@ class miniscript::miniscript::MiniScript { } /** - * @return class name of given script variable type - */ - inline const string& getClassName() { - return getClassName(getType()); - } - - /** - * Return class name of given script variable type - * @param type type - * @return class name of given script variable type - */ - inline static const string& getClassName(ScriptVariableType type) { - switch (type) { - case TYPE_NULL: return CLASSNAME_NONE; - case TYPE_BOOLEAN: return CLASSNAME_NONE; - case TYPE_INTEGER: return CLASSNAME_NONE; - case TYPE_FLOAT: return CLASSNAME_NONE; - case TYPE_FUNCTION_CALL: return CLASSNAME_NONE; - case TYPE_FUNCTION_ASSIGNMENT: return CLASSNAME_NONE; - case TYPE_PSEUDO_NUMBER: return CLASSNAME_NONE; - case TYPE_PSEUDO_MIXED: return CLASSNAME_NONE; - case TYPE_STRING: return CLASSNAME_STRING; - case TYPE_BYTEARRAY: return CLASSNAME_BYTEARRAY; - case TYPE_ARRAY: return CLASSNAME_ARRAY; - case TYPE_MAP: return CLASSNAME_MAP; - case TYPE_SET: return CLASSNAME_SET; - default: - // custom data types - auto dataTypeIdx = static_cast(type) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { - return CLASSNAME_NONE; - } - return MiniScript::scriptDataTypes[dataTypeIdx]->getClassName(); - } - } - - /** - * Returns given script variable type as string + * Returns given variable type as string * @param type type - * @return script variable type as string + * @return variable type as string */ - inline static const string getTypeAsString(ScriptVariableType type) { + inline static const string& getTypeAsString(VariableType type) { switch(type) { - case TYPE_NULL: return "Null"; - case TYPE_BOOLEAN: return "Boolean"; - case TYPE_INTEGER: return "Integer"; - case TYPE_FLOAT: return "Float"; - case TYPE_FUNCTION_CALL: return string(); - case TYPE_FUNCTION_ASSIGNMENT: return string(); - case TYPE_PSEUDO_NUMBER: return "Number"; - case TYPE_PSEUDO_MIXED: return "Mixed"; - case TYPE_STRING: return "String"; - case TYPE_BYTEARRAY: return "ByteArray"; - case TYPE_ARRAY: return "Array"; - case TYPE_MAP: return "Map"; - case TYPE_SET: return "Set"; + case TYPE_NULL: return TYPENAME_NULL; + case TYPE_BOOLEAN: return TYPENAME_BOOLEAN; + case TYPE_INTEGER: return TYPENAME_INTEGER; + case TYPE_FLOAT: return TYPENAME_FLOAT; + case TYPE_FUNCTION_CALL: return TYPENAME_NONE; + case TYPE_FUNCTION_ASSIGNMENT: return TYPENAME_FUNCTION; + case TYPE_PSEUDO_NUMBER: return TYPENAME_NUMBER; + case TYPE_PSEUDO_MIXED: return TYPENAME_MIXED; + case TYPE_STRING: return TYPENAME_STRING; + case TYPE_BYTEARRAY: return TYPENAME_BYTEARRAY; + case TYPE_ARRAY: return TYPENAME_ARRAY; + case TYPE_MAP: return TYPENAME_MAP; + case TYPE_SET: return TYPENAME_SET; default: // custom data types auto dataTypeIdx = static_cast(type) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { - return CLASSNAME_NONE; + if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { + return TYPENAME_NONE; } - return MiniScript::scriptDataTypes[dataTypeIdx]->getTypeAsString(); + return MiniScript::dataTypes[dataTypeIdx]->getTypeAsString(); } - return string(); + return TYPENAME_NONE; } /** - * @return this script variable type as string + * @return this variable type as string */ inline const string getTypeAsString() const { return getTypeAsString(getType()); @@ -1845,7 +1857,7 @@ class miniscript::miniscript::MiniScript { * @param nullable nullable * @return return value variable type string representation */ - inline static const string getReturnTypeAsString(ScriptVariableType type, bool nullable) { + inline static const string getReturnTypeAsString(VariableType type, bool nullable) { switch(type) { case TYPE_NULL: return "Null"; default: return string(nullable?"?":"") + getTypeAsString(type); @@ -1863,7 +1875,7 @@ class miniscript::miniscript::MiniScript { } /** - * @return string representation of script variable type + * @return string representation of variable type */ inline const string getAsString() const { string result; @@ -1877,11 +1889,11 @@ class miniscript::miniscript::MiniScript { } /** - * Print string representation of script variable + * Print string representation of variable * @param formatted formatted * @param jsonCompatible json compatible * @param depth recursion depth - * @return string representation of script variable type + * @return string representation of variable type */ inline const string getValueAsString(bool formatted = false, bool jsonCompatible = false, int depth = 0) const { string result; @@ -2042,11 +2054,11 @@ class miniscript::miniscript::MiniScript { default: // custom data types auto dataTypeIdx = static_cast(getType()) - TYPE_PSEUDO_CUSTOM_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::scriptDataTypes.size()) { + if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { _Console::println("ScriptVariable::getValueAsString(): unknown custom data type with id " + to_string(dataTypeIdx)); return result; } - return MiniScript::scriptDataTypes[dataTypeIdx]->getValueAsString(*this); + return MiniScript::dataTypes[dataTypeIdx]->getValueAsString(*this); } return result; @@ -2054,22 +2066,22 @@ class miniscript::miniscript::MiniScript { }; /** - * Script State Machine State + * State Machine State */ - class ScriptStateMachineState { + class StateMachineState { public: // forbid class copy - FORBID_CLASS_COPY(ScriptStateMachineState) + FORBID_CLASS_COPY(StateMachineState) /** * Constructor */ - ScriptStateMachineState() {} + StateMachineState() {} /** * Destructor */ - virtual ~ScriptStateMachineState() {} + virtual ~StateMachineState() {} /** * @return name @@ -2082,18 +2094,18 @@ class miniscript::miniscript::MiniScript { virtual int getId() = 0; /** - * Execute script state machine state + * Execute state machine state */ virtual void execute() = 0; }; /** - * Script method + * Method */ - class ScriptMethod { + class Method { public: struct ArgumentType { - ScriptVariableType type; + VariableType type; string name; bool optional; bool reference; @@ -2101,7 +2113,7 @@ class miniscript::miniscript::MiniScript { }; // forbid class copy - FORBID_CLASS_COPY(ScriptMethod) + FORBID_CLASS_COPY(Method) /** * Constructor @@ -2109,9 +2121,9 @@ class miniscript::miniscript::MiniScript { * @param returnValueType return value type * @param returnValueNullable true if return value can also be a null value */ - ScriptMethod( + Method( const vector& argumentTypes = {}, - ScriptVariableType returnValueType = ScriptVariableType::TYPE_NULL, + VariableType returnValueType = VariableType::TYPE_NULL, bool returnValueNullable = false ): argumentTypes(argumentTypes), @@ -2123,20 +2135,20 @@ class miniscript::miniscript::MiniScript { /** * Destructor */ - virtual ~ScriptMethod() {} + virtual ~Method() {} /** - * @return script method name + * @return method name */ virtual const string getMethodName() = 0; /** - * Execute script method - * @param argumentValues argument values + * Execute method + * @param arguments argument values * @param returnValue return value * @param statement statement */ - virtual void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) = 0; + virtual void executeMethod(span& arguments, Variable& returnValue, const Statement& statement) = 0; /** * @return arguments @@ -2165,7 +2177,7 @@ class miniscript::miniscript::MiniScript { if (argumentType.reference == true) { result+= "&"; } - result+= "$" + argumentType.name + ": " + (argumentType.nullable == true?"?":"") + ScriptVariable::getTypeAsString(argumentType.type); + result+= "$" + argumentType.name + ": " + (argumentType.nullable == true?"?":"") + Variable::getTypeAsString(argumentType.type); } argumentIdx++; } @@ -2181,7 +2193,7 @@ class miniscript::miniscript::MiniScript { /** * @return return value type */ - const ScriptVariableType& getReturnValueType() const { + const VariableType& getReturnValueType() const { return returnValueType; } @@ -2209,7 +2221,7 @@ class miniscript::miniscript::MiniScript { /** * @return operator */ - virtual ScriptOperator getOperator() const { + virtual Operator getOperator() const { return OPERATOR_NONE; } @@ -2225,46 +2237,69 @@ class miniscript::miniscript::MiniScript { private: vector argumentTypes; - ScriptVariableType returnValueType; + VariableType returnValueType; bool returnValueNullable; }; - struct ScriptSyntaxTreeNode { + struct SyntaxTreeNode { enum Type { SCRIPTSYNTAXTREENODE_NONE, SCRIPTSYNTAXTREENODE_LITERAL, SCRIPTSYNTAXTREENODE_EXECUTE_METHOD, SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION }; - ScriptSyntaxTreeNode(): + SyntaxTreeNode(): type(SCRIPTSYNTAXTREENODE_NONE), - value(ScriptVariable()), - method(nullptr), + value(Variable()), + pointer(0ll), arguments({}) {} - ScriptSyntaxTreeNode( + SyntaxTreeNode( Type type, - const ScriptVariable& value, - ScriptMethod* method, - const vector& arguments + const Variable& value, + Method* method, + const vector& arguments ): type(type), value(value), - method(method), + pointer((uint64_t)method), arguments(arguments) {} + SyntaxTreeNode( + Type type, + const Variable& value, + uint64_t functionIdx, + const vector& arguments + ): + type(type), + value(value), + pointer(functionIdx), + arguments(arguments) + {} + inline Method* getMethod() const { + return (Method*)pointer; + } + inline void setMethod(Method* method) { + pointer = (uint64_t)method; + } + inline uint64_t getFunctionScriptIdx() const { + return pointer; + } + inline void setFunctionScriptIdx(uint64_t scriptIdx) { + pointer = scriptIdx; + } Type type; - ScriptVariable value; - ScriptMethod* method; - vector arguments; + Variable value; + uint64_t pointer; + vector arguments; }; /** * Script */ struct Script { - struct ScriptArgument { - ScriptArgument( + struct FunctionArgument { + FunctionArgument( const string& name, bool reference ): @@ -2281,16 +2316,16 @@ class miniscript::miniscript::MiniScript { // applies only for on and on-enabled const string& condition, const string& executableCondition, - ScriptStatement conditionStatement, - ScriptSyntaxTreeNode conditionSyntaxTree, + Statement conditionStatement, + SyntaxTreeNode conditionSyntaxTree, // applies only for on-enabled const string& name, bool emitCondition, - const vector& statements, - const vector& syntaxTree, + const vector& statements, + const vector& syntaxTree, // applies only for functions - bool callable, - const vector& arguments + bool callableFunction, + const vector& functionArguments ): scriptType(scriptType), line(line), @@ -2302,21 +2337,21 @@ class miniscript::miniscript::MiniScript { emitCondition(emitCondition), statements(statements), syntaxTree(syntaxTree), - callable(callable), - arguments(arguments) + callableFunction(callableFunction), + functionArguments(functionArguments) {} ScriptType scriptType; int line; string condition; string executableCondition; - ScriptStatement conditionStatement; - ScriptSyntaxTreeNode conditionSyntaxTree; + Statement conditionStatement; + SyntaxTreeNode conditionSyntaxTree; string name; bool emitCondition; - vector statements; - vector syntaxTree; - bool callable; - vector arguments; + vector statements; + vector syntaxTree; + bool callableFunction; + vector functionArguments; }; static constexpr int SCRIPTIDX_NONE { -1 }; @@ -2345,11 +2380,11 @@ class miniscript::miniscript::MiniScript { * @param arguments arguments * @return arguments as string */ - inline const string getArgumentsAsString(const vector& arguments) { + inline const string getArgumentsAsString(const vector& arguments) { string argumentsString; for (const auto& argument: arguments) { switch (argument.type) { - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: switch(argument.value.getType()) { case TYPE_NULL: { @@ -2375,8 +2410,8 @@ class miniscript::miniscript::MiniScript { } } break; - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: - case ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: argumentsString+= (argumentsString.empty() == false?", ":"") + argument.value.getValueAsString() + string("(") + getArgumentsAsString(argument.arguments) + string(")"); break; default: @@ -2406,7 +2441,7 @@ class miniscript::miniscript::MiniScript { }; int state { STATE_NONE }; int lastState { STATE_NONE }; - ScriptStateMachineState* lastStateMachineState { nullptr }; + StateMachineState* lastStateMachineState { nullptr }; bool running { false }; int scriptIdx { SCRIPTIDX_NONE }; int statementIdx { STATEMENTIDX_NONE }; @@ -2414,12 +2449,12 @@ class miniscript::miniscript::MiniScript { int64_t timeWaitStarted { TIME_NONE }; int64_t timeWaitTime { TIME_NONE }; string id; - unordered_map variables; + unordered_map variables; unordered_map forTimeStarted; stack conditionStack; stack endTypeStack; // applies for functions only - ScriptVariable returnValue; + Variable returnValue; }; bool native; @@ -2465,7 +2500,7 @@ class miniscript::miniscript::MiniScript { * Go to statement goto from given statement * @param statement statement */ - void gotoStatementGoto(const ScriptStatement& statement) { + void gotoStatementGoto(const Statement& statement) { getScriptState().gotoStatementIdx = statement.gotoStatementIdx; } @@ -2485,11 +2520,11 @@ class miniscript::miniscript::MiniScript { } /** - * Set native user script functions - * @param nativeScriptFunctions native user script functions + * Set native functions + * @param nativeFunctions native functions */ - inline void setNativeScriptFunctions(const unordered_map& nativeScriptFunctions) { - this->scriptFunctions = nativeScriptFunctions; + inline void setNativeFunctions(const unordered_map& nativeFunctions) { + this->functions = nativeFunctions; } /** @@ -2502,7 +2537,7 @@ class miniscript::miniscript::MiniScript { * @param scriptIdx script index * @param stateMachineState state machine state */ - inline void resetScriptExecutationState(int scriptIdx, StateMachineState stateMachineState) { + inline void resetScriptExecutationState(int scriptIdx, StateMachineStateId stateMachineState) { auto& scriptState = getScriptState(); if (isFunctionRunning() == false) enabledNamedConditions.clear(); scriptState.forTimeStarted.clear(); @@ -2586,6 +2621,16 @@ class miniscript::miniscript::MiniScript { */ virtual int determineNamedScriptIdxToStart(); + /*** + * Create inline/lamda function for given variable + * @param variable variable + * @param arguments arguments + * @param functionScriptCode function script code + * @param populateThis populate this variable, which applies to inline member function of maps/objects + * @param statement statement + */ + void createLamdaFunction(Variable& variable, const vector& arguments, const string_view& functionScriptCode, bool populateThis, const Statement& statement); + /** * Initialize array by initializer string * @param initializerString initializer string @@ -2593,7 +2638,7 @@ class miniscript::miniscript::MiniScript { * @param statement statement * @return initialized variable */ - static const ScriptVariable initializeArray(const string_view& initializerString, MiniScript* miniScript, const ScriptStatement& statement); + static const Variable initializeArray(const string_view& initializerString, MiniScript* miniScript, const Statement& statement); /** * Initialize map/set by initializer string @@ -2602,34 +2647,32 @@ class miniscript::miniscript::MiniScript { * @param statement statement * @return initialized variable */ - static const ScriptVariable initializeMapSet(const string_view& initializerString, MiniScript* miniScript, const ScriptStatement& statement); + static const Variable initializeMapSet(const string_view& initializerString, MiniScript* miniScript, const Statement& statement); private: static constexpr bool VERBOSE { false }; // MINISCRIPT_STATIC_DLL_IMPEXT static const string OPERATOR_CHARS; - MINISCRIPT_STATIC_DLL_IMPEXT static vector scriptDataTypes; + MINISCRIPT_STATIC_DLL_IMPEXT static vector dataTypes; // TODO: maybe we need a better naming for this - // script functions defined by script itself - unordered_map scriptFunctions; - // script methods defined by using ScriptMethod - unordered_map scriptMethods; - unordered_map scriptStateMachineStates; - unordered_map scriptOperators; + // functions defined by script itself + unordered_map functions; + // registered methods + unordered_map methods; + // registered state machine states + unordered_map stateMachineStates; + // operators + unordered_map operators; + // string scriptPathName; string scriptFileName; - bool scriptValid { false }; - // - struct ScriptStatementOperator { - int idx { OPERATORIDX_NONE }; - ScriptOperator scriptOperator; - }; + bool scriptValid { false }; /** - * Parse additional script code into this MiniScript instance + * Parse script code into this MiniScript instance * @param scriptCode script code * @return success */ @@ -2637,21 +2680,21 @@ class miniscript::miniscript::MiniScript { /** - * Execute a single script line + * Execute next statement */ - void executeScriptLine(); + void executeNextStatement(); /** * Get next statement from script code * @param scriptCode script code * @param i character index - * @param line script line + * @param line line * @return next statement */ const string getNextStatement(const string& scriptCode, int& i, int& line); /** - * Parse a script statement + * Parse a statement * @param executableStatement executable statement * @param methodName method name * @param arguments arguments @@ -2659,25 +2702,25 @@ class miniscript::miniscript::MiniScript { * @param accessObjectMember generated access object member statement * @return success */ - bool parseScriptStatement(const string_view& executableStatement, string_view& methodName, vector& arguments, const ScriptStatement& statement, string& accessObjectMemberStatement); + bool parseStatement(const string_view& executableStatement, string_view& methodName, vector& arguments, const Statement& statement, string& accessObjectMemberStatement); /** - * Execute a script statement + * Execute a statement * @param syntaxTree syntax tree * @param statement statement - * @return return value as script variable + * @return return value as variable */ - ScriptVariable executeScriptStatement(const ScriptSyntaxTreeNode& syntaxTree, const ScriptStatement& statement); + Variable executeStatement(const SyntaxTreeNode& syntaxTree, const Statement& statement); /** - * Create script statement syntax tree + * Create statement syntax tree * @param methodName method name * @param arguments arguments * @param statement statement * @param syntaxTree syntax tree * @return success */ - bool createScriptStatementSyntaxTree(const string_view& methodName, const vector& arguments, const ScriptStatement& statement, ScriptSyntaxTreeNode& syntaxTree); + bool createStatementSyntaxTree(const string_view& methodName, const vector& arguments, const Statement& statement, SyntaxTreeNode& syntaxTree); /** * Validate callabe @@ -2690,7 +2733,7 @@ class miniscript::miniscript::MiniScript { * @param syntaxTreeNode syntax tree node * @param statement statement */ - bool validateCallable(const ScriptSyntaxTreeNode& syntaxTreeNode, const ScriptStatement& statement); + bool validateCallable(const SyntaxTreeNode& syntaxTreeNode, const Statement& statement); /** * Validate context functions @@ -2705,7 +2748,7 @@ class miniscript::miniscript::MiniScript { * @param functionStack function stack * @param statement statement */ - bool validateContextFunctions(const ScriptSyntaxTreeNode& syntaxTreeNode, vector& functionStack, const ScriptStatement& statement); + bool validateContextFunctions(const SyntaxTreeNode& syntaxTreeNode, vector& functionStack, const Statement& statement); /** * Returns if char is operator char @@ -2716,45 +2759,12 @@ class miniscript::miniscript::MiniScript { return OPERATOR_CHARS.find(c) != string::npos; } - /** - * Determine next not substituted operator in statement - * @param processedStatement statement that is currently being processed - * @param nextOperator next operator - * @param statement statement - */ - bool getNextStatementOperator(const string& processedStatement, ScriptStatementOperator& nextOperator, const ScriptStatement& statement); - - /** - * Trim argument and remove unnessessary parenthesis - * @param argument argument - * @return processed argument - */ - const string trimArgument(const string& argument); - - /** - * Find right argument in statement beginning from position - * @param statement statement - * @param position position - * @param length argument length - * @param brackets barrier brackets - */ - const string findRightArgument(const string& statement, int position, int& length, string& brackets); - - /** - * Find left argument in statement beginning from position - * @param statement statement - * @param position position - * @param length argument length - * @param brackets barrier brackets - */ - const string findLeftArgument(const string& statement, int position, int& length, string& brackets); - /** * Do statement pre processing, 1) replace operators with corresponding methods * @param processedStatement statement that is currently being processed * @param statement statement */ - const string doStatementPreProcessing(const string& processedStatement, const ScriptStatement& statement); + const string doStatementPreProcessing(const string& processedStatement, const Statement& statement); /** * Returns if statement has a object member access @@ -2764,7 +2774,7 @@ class miniscript::miniscript::MiniScript { * @param statement statement * @return statement has a object member access */ - bool getObjectMemberAccess(const string_view& executableStatement, string_view& object, string_view& method, const ScriptStatement& statement); + bool getObjectMemberAccess(const string_view& executableStatement, string_view& object, string_view& method, const Statement& statement); /** * Get access operator left and right indices @@ -2775,7 +2785,7 @@ class miniscript::miniscript::MiniScript { * @param statement statement * @param startIdx startIdx */ - bool getVariableAccessOperatorLeftRightIndices(const string& name, const string& callerMethod, string::size_type& accessOperatorLeftIdx, string::size_type& accessOperatorRightIdx, const ScriptStatement* statement = nullptr, int startIdx = 0); + bool getVariableAccessOperatorLeftRightIndices(const string& name, const string& callerMethod, string::size_type& accessOperatorLeftIdx, string::size_type& accessOperatorRightIdx, const Statement* statement = nullptr, int startIdx = 0); /** * Evaluate access @@ -2787,7 +2797,7 @@ class miniscript::miniscript::MiniScript { * @param key map key * @param statement statement */ - bool evaluateAccess(const string& name, const string& callerMethod, string::size_type& arrayAccessOperatorLeftIdx, string::size_type& arrayAccessOperatorRightIdx, int64_t& arrayIdx, string& key, const ScriptStatement* statement = nullptr); + bool evaluateAccess(const string& name, const string& callerMethod, string::size_type& arrayAccessOperatorLeftIdx, string::size_type& arrayAccessOperatorRightIdx, int64_t& arrayIdx, string& key, const Statement* statement = nullptr); /** * Returns pointer of variable with given name or nullptr @@ -2802,24 +2812,24 @@ class miniscript::miniscript::MiniScript { * @param global use global context instead of current context * @return pointer to variable */ - ScriptVariable* getVariableIntern(const string& name, const string& callerMethod, ScriptVariable*& parentVariable, int64_t& arrayIdx, string& key, int& setAccessBool, const ScriptStatement* statement = nullptr, bool expectVariable = true, bool global = false); + Variable* getVariableIntern(const string& name, const string& callerMethod, Variable*& parentVariable, int64_t& arrayIdx, string& key, int& setAccessBool, const Statement* statement = nullptr, bool expectVariable = true, bool global = false); /** * Evaluate given statement without executing preprocessor run - * @param statement script statement - * @param executableStatement executable script statement - * @param returnValue script return value + * @param statement statement + * @param executableStatement executable statement + * @param returnValue return value * @param pushOwnScriptState push own script state * @return success */ - bool evaluateInternal(const string& statement, const string& executableStatement, ScriptVariable& returnValue, bool pushOwnScriptState = true); + bool evaluateInternal(const string& statement, const string& executableStatement, Variable& returnValue, bool pushOwnScriptState = true); /** * Initialize variable * @param variable variable * @return initialized variable */ - const ScriptVariable initializeVariable(const ScriptVariable& variable); + const Variable initializeVariable(const Variable& variable); /** * Returns if a given string is a function assignment @@ -2862,13 +2872,87 @@ class miniscript::miniscript::MiniScript { } /** - * Returns if a given string is a inline function + * Returns if a given string is a inline/lambda function + * @param candidate candidate + * @return if candidate is a inline/lambda function + */ + inline static bool viewIsLamdaFunction(const string_view& candidate) { + if (candidate.size() == 0) return false; + // + auto i = 0; + // ( + if (candidate[i++] != '(') return false; + // spaces + for (; i < candidate.size() && _Character::isSpace(candidate[i]) == true; i++); if (i >= candidate.size()) return false; + // + auto argumentStartIdx = string::npos; + auto argumentEndIdx = string::npos; + // + for (; i < candidate.size(); i++) { + auto c = candidate[i]; + if (c == '&') { + if (argumentStartIdx == string::npos) { + argumentStartIdx = i; + } else { + return false; + } + } else + if (c == '$') { + if (argumentStartIdx == string::npos) { + argumentStartIdx = i; + } else + if (argumentStartIdx == i - 1 && candidate[argumentStartIdx] == '&') { + // no op + } else { + return false; + } + } else + if (c == ',' || c == ')') { + if (argumentEndIdx == string::npos) { + if (argumentStartIdx != string::npos) { + argumentEndIdx = i; + } + // + argumentStartIdx = string::npos; + argumentEndIdx = string::npos; + } else { + return false; + } + if (c == ')') { + i++; + break; + } + } else + if (argumentStartIdx != string::npos && _Character::isAlphaNumeric(candidate[i]) == false && c != '_') { + return false; + } + } + // + if (i >= candidate.size()) return false; + // spaces + for (; i < candidate.size() && _Character::isSpace(candidate[i]) == true; i++); if (i >= candidate.size()) return false; + // - + if (candidate[i++] != '-') return false; + // + if (i >= candidate.size()) return false; + // > + if (candidate[i++] != '>') return false; + // spaces + for (; i < candidate.size() && _Character::isSpace(candidate[i]) == true; i++); if (i >= candidate.size()) return false; + // + if (candidate[i++] != '{') return false; + // + return true; + } + + /** + * Returns if a given string is a inline/lambda function * @param candidate candidate * @param arguments arguments * @param functionScriptCode function script code - * @return if candidate is a inline function + * @return if candidate is a inline/lambda function */ - inline static bool viewIsInlineFunction(const string_view& candidate, vector& arguments, string_view& functionScriptCode) { + inline static bool viewIsLamdaFunction(const string_view& candidate, vector& arguments, string_view& functionScriptCode) { if (candidate.size() == 0) return false; // auto i = 0; @@ -2987,6 +3071,12 @@ class miniscript::miniscript::MiniScript { static bool viewIsKey(const string_view& candidate); public: + /** + * Set variable recursively to be a constant + * @param variable variable + */ + static void setConstant(Variable& variable); + /** * @return context */ @@ -3020,27 +3110,27 @@ class miniscript::miniscript::MiniScript { /** * @return data types */ - inline static const vector& getDataTypes() { - return scriptDataTypes; + inline static const vector& getDataTypes() { + return dataTypes; } /** * Returns data type by class name or nullptr * @param className class name - * @return script data type + * @return data type */ - inline static ScriptDataType* getDataTypeByClassName(const string& className) { - for (const auto scriptDataType: scriptDataTypes) { - if (scriptDataType->getClassName() == className) return scriptDataType; + inline static DataType* getDataTypeByClassName(const string& className) { + for (const auto dataType: dataTypes) { + if (dataType->getTypeAsString() == className) return dataType; } return nullptr; } /** - * Register script data type - * @param scriptDataType script data type + * Register data type + * @param dataType data type */ - static void registerDataType(ScriptDataType* scriptDataType); + static void registerDataType(DataType* dataType); // forbid class copy FORBID_CLASS_COPY(MiniScript) @@ -3080,7 +3170,7 @@ class miniscript::miniscript::MiniScript { } /** - * @return if this script was compiled to C++ and is executed nativly + * @return if this script was compiled to C++ and is executed natively */ inline bool isNative() { return native; @@ -3108,7 +3198,7 @@ class miniscript::miniscript::MiniScript { } /** - * @return script state + * @return root script state */ inline ScriptState& getRootScriptState() { return *(scriptStateStack[0].get()); @@ -3122,7 +3212,7 @@ class miniscript::miniscript::MiniScript { } /** - * @return mini script math + * @return math methods */ inline MathMethods* getMathMethods() { return miniScriptMath.get(); @@ -3141,7 +3231,7 @@ class miniscript::miniscript::MiniScript { * @return method exists */ inline bool hasMethod(const string& methodName) { - return scriptMethods.find(methodName) != scriptMethods.end(); + return methods.find(methodName) != methods.end(); } /** @@ -3150,7 +3240,7 @@ class miniscript::miniscript::MiniScript { * @return function exists */ inline bool hasFunction(const string& functionName) { - return scriptFunctions.find(functionName) != scriptFunctions.end(); + return functions.find(functionName) != functions.end(); } /** @@ -3169,18 +3259,18 @@ class miniscript::miniscript::MiniScript { virtual void registerVariables(); /** - * Return script statement information + * Return statement information * @param statement statement - * @return script statement information + * @return statement information */ - inline const string getStatementInformation(const ScriptStatement& statement) { + inline const string getStatementInformation(const Statement& statement) { return scriptFileName + ":" + to_string(statement.line) + ": " + statement.statement; } /** - * Get script argument information + * Get argument information * @param methodName method name - * @return script argument information + * @return argument information */ inline const string getArgumentInformation(const string& methodName) { auto scriptMethod = getMethod(methodName); @@ -3193,11 +3283,11 @@ class miniscript::miniscript::MiniScript { /** * Get operator as string - * @param scriptOperator script operator - * @return script operator as string + * @param operator_ operator + * @return operator as string */ - inline static string getOperatorAsString(ScriptOperator scriptOperator) { - switch(scriptOperator) { + inline static string getOperatorAsString(Operator operator_) { + switch(operator_) { case(OPERATOR_NONE): return "NONE"; case(OPERATOR_INCREMENT): return "++"; case(OPERATOR_DECREMENT): return "--"; @@ -3231,7 +3321,7 @@ class miniscript::miniscript::MiniScript { * @param type type * @return has type */ - inline static bool hasType(const span& arguments, ScriptVariableType type) { + inline static bool hasType(const span& arguments, VariableType type) { for (const auto& argument: arguments) if (argument.getType() == type) return true; return false; } @@ -3244,7 +3334,7 @@ class miniscript::miniscript::MiniScript { * @param optional optionalfalse * @return success */ - inline static bool getBooleanValue(const span& arguments, int idx, bool& value, bool optional = false) { + inline static bool getBooleanValue(const span& arguments, int idx, bool& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; return argument.getBooleanValue(value, optional); @@ -3258,7 +3348,7 @@ class miniscript::miniscript::MiniScript { * @param optional optional * @return success */ - inline static bool getIntegerValue(const span& arguments, int idx, int64_t& value, bool optional = false) { + inline static bool getIntegerValue(const span& arguments, int idx, int64_t& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; return argument.getIntegerValue(value, optional); @@ -3272,7 +3362,7 @@ class miniscript::miniscript::MiniScript { * @param optional optional * @return success */ - inline static bool getFloatValue(const span& arguments, int idx, float& value, bool optional = false) { + inline static bool getFloatValue(const span& arguments, int idx, float& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; return argument.getFloatValue(value, optional); @@ -3286,23 +3376,23 @@ class miniscript::miniscript::MiniScript { * @param optional optional * @return success */ - inline static bool getStringValue(const span& arguments, int idx, string& value, bool optional = false) { + inline static bool getStringValue(const span& arguments, int idx, string& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; return argument.getStringValue(value, optional); } /** - * Register script state machine state + * Register state machine state * @param state state */ - void registerStateMachineState(ScriptStateMachineState* state); + void registerStateMachineState(StateMachineState* state); /** - * Register script method - * @param scriptMethod script method + * Register method + * @param method method */ - void registerMethod(ScriptMethod* scriptMethod); + void registerMethod(Method* method); /** * Returns if a given string is a variable name @@ -3335,7 +3425,7 @@ class miniscript::miniscript::MiniScript { * @param createReference optional flag for creating variable references * @return variable */ - inline const ScriptVariable getVariable(const string& name, const ScriptStatement* statement = nullptr, bool createReference = false) { + inline const Variable getVariable(const string& name, const Statement* statement = nullptr, bool createReference = false) { // global accessor string globalVariableName; if (_StringTools::startsWith(name, "$GLOBAL.") == true) { @@ -3343,37 +3433,40 @@ class miniscript::miniscript::MiniScript { } // - ScriptVariable* parentVariable = nullptr; + Variable* parentVariable = nullptr; string key; int64_t arrayIdx = ARRAYIDX_NONE; int setAccessBool = SETACCESSBOOL_NONE; auto variablePtr = getVariableIntern(globalVariableName.empty() == true?name:globalVariableName, __FUNCTION__, parentVariable, arrayIdx, key, setAccessBool, statement, true, globalVariableName.empty() == false); // set '.' operator if (setAccessBool != SETACCESSBOOL_NONE) { - return ScriptVariable(setAccessBool == SETACCESSBOOL_TRUE); + return Variable(setAccessBool == SETACCESSBOOL_TRUE); } else - // we have a pointer to a ordinary script variable + // we have a pointer to a ordinary variable if (variablePtr != nullptr) { - return createReference == false?*variablePtr:ScriptVariable::createReferenceVariable(variablePtr); + // if we return any variable we can safely remove the constness, a reference can of course keep its constness + auto variable = createReference == false?*variablePtr:Variable::createReferenceVariable(variablePtr); + variable.unsetConstant(); + return variable; } else { // special case for accessing byte array entries at given array index if (parentVariable != nullptr && parentVariable->getType() == TYPE_BYTEARRAY && arrayIdx >= ARRAYIDX_FIRST) { - return ScriptVariable(static_cast(parentVariable->getByteArrayEntry(arrayIdx))); + return Variable(static_cast(parentVariable->getByteArrayEntry(arrayIdx))); } else { // nothing to return - return ScriptVariable(); + return Variable(); } } } /** - * Set script variable + * Set variable * @param name name * @param variable variable * @param statement optional statement the variable is written in * @param createReference optional flag for creating variable references */ - inline void setVariable(const string& name, const ScriptVariable& variable, const ScriptStatement* statement = nullptr, bool createReference = false) { + inline void setVariable(const string& name, const Variable& variable, const Statement* statement = nullptr, bool createReference = false) { // global accessor string globalVariableName; if (_StringTools::startsWith(name, "$GLOBAL.") == true) { @@ -3381,14 +3474,18 @@ class miniscript::miniscript::MiniScript { } // - ScriptVariable* parentVariable = nullptr; + Variable* parentVariable = nullptr; string key; int64_t arrayIdx = ARRAYIDX_NONE; int setAccessBool = SETACCESSBOOL_NONE; auto variablePtr = getVariableIntern(globalVariableName.empty() == true?name:globalVariableName, __FUNCTION__, parentVariable, arrayIdx, key, setAccessBool, statement, false, globalVariableName.empty() == false); // common case if (variablePtr != nullptr) { - *variablePtr = variable; + if (variablePtr->isConstant() == false) { + *variablePtr = variable; + } else { + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); + } return; } else // array add operator @@ -3396,33 +3493,43 @@ class miniscript::miniscript::MiniScript { if (parentVariable == nullptr) { string callerMethod = __FUNCTION__; if (statement != nullptr) { - _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: '" + name + "': map access operator without map: '" + key + "'"); + _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: " + name + ": map access operator without map: '" + key + "'"); } else { - _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: '" + name + "': map access operator without map: '" + key + "'"); + _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: " + name + ": map access operator without map: '" + key + "'"); } } else // all checks passed, push to map if (parentVariable->getType() == MiniScript::TYPE_MAP) { - parentVariable->setMapEntry(key, createReference == false?ScriptVariable::createNonReferenceVariable(&variable):ScriptVariable::createReferenceVariable(&variable)); + // check if our parent is not a const variable + if (parentVariable->isConstant() == false) { + parentVariable->setMapEntry(key, createReference == false?Variable::createNonReferenceVariable(&variable):Variable::createReferenceVariable(&variable)); + } else { + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); + } } else if (parentVariable->getType() == MiniScript::TYPE_SET) { - bool booleanValue; - if (variable.getBooleanValue(booleanValue, false) == true) { - if (booleanValue == true) { - parentVariable->insertSetKey(key); + // check if our parent is not a const variable + if (parentVariable->isConstant() == false) { + bool booleanValue; + if (variable.getBooleanValue(booleanValue, false) == true) { + if (booleanValue == true) { + parentVariable->insertSetKey(key); + } else { + parentVariable->removeSetKey(key); + } } else { - parentVariable->removeSetKey(key); + string callerMethod = __FUNCTION__; + _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: " + name + ": set access operator: expected boolean variable to remove/insert key in set, but got " + variable.getTypeAsString()); } } else { - string callerMethod = __FUNCTION__; - _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: '" + name + "': set access operator: expected boolean variable to remove/insert key in set, but got " + variable.getTypeAsString()); + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); } } else { string callerMethod = __FUNCTION__; if (statement != nullptr) { - _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: '" + name + "': map/set access operator: expected map/set, but got " + parentVariable->getTypeAsString() + ": '" + key + "'"); + _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: " + name + ": map/set access operator: expected map/set, but got " + parentVariable->getTypeAsString() + ": '" + key + "'"); } else { - _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: '" + name + "': map/set access operator: expected map/set, but got " + parentVariable->getTypeAsString() + ": '" + key + "'"); + _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: " + name + ": map/set access operator: expected map/set, but got " + parentVariable->getTypeAsString() + ": '" + key + "'"); } } // @@ -3432,29 +3539,37 @@ class miniscript::miniscript::MiniScript { if (parentVariable == nullptr) { string callerMethod = __FUNCTION__; if (statement != nullptr) { - _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: '" + name + "': [] array push operator without array"); + _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: " + name + ": [] array push operator without array"); } else { - _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: '" + name + "': [] array push operator without array"); + _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: " + name + ": [] array push operator without array"); } } else if (parentVariable->getType() == MiniScript::TYPE_BYTEARRAY) { - // all checks passed, push variable to array - auto& arrayValueReference = parentVariable->getByteArrayValueReference(); - uint8_t value; - if (variable.getByteValue(this, value, statement) == true) { - arrayValueReference.push_back(value); + // check if our parent is not a const variable + if (parentVariable->isConstant() == false) { + // all checks passed, push variable to array + uint8_t value; + if (variable.getByteValue(this, value, statement) == true) { + parentVariable->pushByteArrayEntry(value); + } + } else { + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); } } else if (parentVariable->getType() == MiniScript::TYPE_ARRAY) { - // all checks passed, push variable to array - auto& arrayValueReference = parentVariable->getArrayValueReference(); - arrayValueReference.push_back(createReference == false?ScriptVariable::createNonReferenceVariablePointer(&variable):ScriptVariable::createReferenceVariablePointer(&variable)); + // check if our parent is not a const variable + if (parentVariable->isConstant() == false) { + // all checks passed, push variable to array + parentVariable->pushArrayEntry(createReference == false?Variable::createNonReferenceVariable(&variable):Variable::createReferenceVariable(&variable)); + } else { + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); + } } else { string callerMethod = __FUNCTION__; if (statement != nullptr) { - _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: '" + name + "': [] array push operator: expected byte array or array, but got " + parentVariable->getTypeAsString()); + _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: " + name + ": [] array push operator: expected byte array or array, but got " + parentVariable->getTypeAsString()); } else { - _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: '" + name + "': [] array push operator: expected byte array or array, but got " + parentVariable->getTypeAsString()); + _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: " + name + ": [] array push operator: expected byte array or array, but got " + parentVariable->getTypeAsString()); } } // @@ -3462,37 +3577,49 @@ class miniscript::miniscript::MiniScript { } else // special case for accessing byte array entries at given array index if (arrayIdx >= ARRAYIDX_FIRST && parentVariable != nullptr && parentVariable->getType() == TYPE_BYTEARRAY) { - int64_t value; - if (variable.getIntegerValue(value, false) == true && value >= 0 && value <= 255) { - parentVariable->pushByteArrayEntry(value); - } else { - string callerMethod = __FUNCTION__; - if (statement != nullptr) { - _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: '" + name + "': [] byte array push operator: expected byte integer value (0 <= byte <= 255), but got " + variable.getTypeAsString()); + // check if our parent is not a const variable + if (parentVariable->isConstant() == false) { + uint8_t value; + if (variable.getByteValue(this, value, statement) == true) { + parentVariable->pushByteArrayEntry(value); } else { - _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: '" + name + "': [] byte array push operator: expected byte integer value (0 <= byte <= 255), but got " + variable.getTypeAsString()); + string callerMethod = __FUNCTION__; + if (statement != nullptr) { + _Console::println("MiniScript::" + callerMethod + "(): " + getStatementInformation(*statement) + ": variable: " + name + ": [] byte array push operator: expected byte integer value (0 <= byte <= 255), but got " + variable.getTypeAsString()); + } else { + _Console::println("MiniScript::" + callerMethod + "(): '" + scriptFileName + "': variable: " + name + ": [] byte array push operator: expected byte integer value (0 <= byte <= 255), but got " + variable.getTypeAsString()); + } } + } else { + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); } } // default auto& scriptState = globalVariableName.empty() == true?getScriptState():getRootScriptState(); - auto scriptVariableIt = scriptState.variables.find(globalVariableName.empty() == true?name:globalVariableName); - if (scriptVariableIt != scriptState.variables.end()) { - *scriptVariableIt->second = variable; + auto variableIt = scriptState.variables.find(globalVariableName.empty() == true?name:globalVariableName); + if (variableIt != scriptState.variables.end()) { + auto& existingVariable = variableIt->second; + if (existingVariable->isConstant() == false) { + // if we set a variable in variable scope that did exist before, we can safely remove the constness + *existingVariable = variable; + } else { + _Console::println(getStatementInformation(*statement) + ": constant: " + name + ": Assignment of constant is not allowed"); + } return; } else { + // if we set a variable in variable scope that did not exist before, we keep things as they are regarding constness scriptState.variables[globalVariableName.empty() == true?name:globalVariableName] = - createReference == false?ScriptVariable::createNonReferenceVariablePointer(&variable):ScriptVariable::createReferenceVariablePointer(&variable); + createReference == false?Variable::createNonReferenceVariablePointer(&variable):Variable::createReferenceVariablePointer(&variable); } } /** - * Unset script variable + * Unset variable * @param name name * @param statement optional statement the variable is unset in */ - inline void unsetVariable(const string& name, const ScriptStatement* statement = nullptr) { + inline void unsetVariable(const string& name, const Statement* statement = nullptr) { // TODO: } @@ -3540,61 +3667,59 @@ class miniscript::miniscript::MiniScript { virtual void execute(); /** - * Call (script user) function - * @param function (script user) function - * @param argumentValues argument values - * @param returnValue return value - * @return success + * Return function script index by function name + * @param function function + * @return function script index */ inline int getFunctionScriptIdx(const string& function) { // lookup function - auto scriptFunctionsIt = scriptFunctions.find(function); - if (scriptFunctionsIt == scriptFunctions.end()) { + auto functionIt = functions.find(function); + if (functionIt == functions.end()) { return SCRIPTIDX_NONE; } // - auto scriptIdx = scriptFunctionsIt->second; + auto scriptIdx = functionIt->second; // return scriptIdx; } /** - * Call (script user) function + * Call function * @param scriptIdx script index - * @param argumentValues argument values + * @param arguments argument values * @param returnValue return value * @return success */ - virtual bool call(int scriptIdx, span& argumentValues, ScriptVariable& returnValue); + virtual bool call(int scriptIdx, span& arguments, Variable& returnValue); /** - * Call (script user) function - * @param function (script user) function - * @param argumentValues argument values + * Call function + * @param function function + * @param arguments argument values * @param returnValue return value * @return success */ - inline bool call(const string& function, span& argumentValues, ScriptVariable& returnValue) { + inline bool call(const string& function, span& arguments, Variable& returnValue) { // lookup function - auto scriptFunctionsIt = scriptFunctions.find(function); - if (scriptFunctionsIt == scriptFunctions.end()) { + auto functionIt = functions.find(function); + if (functionIt == functions.end()) { // _Console::println("MiniScript::call(): Script user function not found: " + function); return false; } // - auto scriptIdx = scriptFunctionsIt->second; + auto scriptIdx = functionIt->second; // call it - return call(scriptIdx, argumentValues, returnValue); + return call(scriptIdx, arguments, returnValue); } /** - * Evaluate given statement - * @param statement script statement - * @param returnValue script return value + * Evaluate statement + * @param evaluateStatement evaluate statement + * @param returnValue return value * @return success */ - inline bool evaluate(const string& evaluateStatement, ScriptVariable& returnValue) { - ScriptStatement evaluateScriptStatement( + inline bool evaluate(const string& evaluateStatement, Variable& returnValue) { + Statement evaluateScriptStatement( LINE_NONE, STATEMENTIDX_FIRST, "internal.script.evaluate(" + _StringTools::replace(_StringTools::replace(evaluateStatement, "\\", "\\\\"), "\"", "\\\"") + ")", @@ -3614,29 +3739,29 @@ class miniscript::miniscript::MiniScript { /** * Get method by method name * @param methodName method name - * @return script method or nullptr + * @return method or nullptr */ - inline ScriptMethod* getMethod(const string& methodName) { - auto scriptMethodIt = scriptMethods.find(methodName); - if (scriptMethodIt != scriptMethods.end()) { - return scriptMethodIt->second; + inline Method* getMethod(const string& methodName) { + auto methodIt = methods.find(methodName); + if (methodIt != methods.end()) { + return methodIt->second; } else { return nullptr; } } /** - * @return script methods + * @return methods */ - const vector getMethods(); + const vector getMethods(); /** - * @return script operator methods + * @return operator methods */ - const vector getOperatorMethods(); + const vector getOperatorMethods(); /** - * Get miniscript script information + * Get script information for a specific script index * @param scriptIdx script index * @param includeStatements include statements * @return information as string @@ -3644,7 +3769,7 @@ class miniscript::miniscript::MiniScript { const string getScriptInformation(int scriptIdx, bool includeStatements = true); /** - * Get miniscript instance information + * Get MiniScript instance information * @return information as string */ const string getInformation(); diff --git a/ext/miniscript/src/miniscript/miniscript/NetworkMethods.cpp b/ext/miniscript/src/miniscript/miniscript/NetworkMethods.cpp index 3b2409887..02eb7e1cb 100644 --- a/ext/miniscript/src/miniscript/miniscript/NetworkMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/NetworkMethods.cpp @@ -23,12 +23,12 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { // network { // - class ScriptMethodNetworkHTTPClientHEAD: public MiniScript::ScriptMethod { + class MethodNetworkHTTPClientHEAD: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNetworkHTTPClientHEAD(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNetworkHTTPClientHEAD(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "url", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_MAP, .name = "queryParameters", .optional = true, .reference = false, .nullable = true }, @@ -41,16 +41,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "network.httpclient.head"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string url; - if (argumentValues.size() <= 3 && - MiniScript::getStringValue(argumentValues, 0, url, false) == true && - (argumentValues.size() <= 1 || argumentValues[1].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 2 || argumentValues[2].getType() == MiniScript::TYPE_MAP)) { + if (arguments.size() <= 3 && + MiniScript::getStringValue(arguments, 0, url, false) == true && + (arguments.size() <= 1 || arguments[1].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 2 || arguments[2].getType() == MiniScript::TYPE_MAP)) { // GET parameters unordered_map getParameters; - if (argumentValues.size() >= 2) { - auto getParameterMapPtr = argumentValues[1].getMapPointer(); + if (arguments.size() >= 2) { + auto getParameterMapPtr = arguments[1].getMapPointer(); if (getParameterMapPtr != nullptr) { for (const auto& [key, value]: *getParameterMapPtr) { getParameters[key] = value->getValueAsString(); @@ -59,8 +59,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // headers unordered_map headers; - if (argumentValues.size() >= 3) { - auto headersMapPtr = argumentValues[2].getMapPointer(); + if (arguments.size() >= 3) { + auto headersMapPtr = arguments[2].getMapPointer(); if (headersMapPtr != nullptr) { for (const auto& [key, value]: *headersMapPtr) { headers[key] = value->getValueAsString(); @@ -79,7 +79,7 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { returnValue.setType(MiniScript::TYPE_MAP); returnValue.setMapEntry("status", static_cast(httpClient.getStatusCode())); // - MiniScript::ScriptVariable responseHeaders; + MiniScript::Variable responseHeaders; responseHeaders.setType(MiniScript::TYPE_MAP); for (const auto& [headerName, headerValue]: httpClient.getResponseHeaders()) { responseHeaders.setMapEntry(headerName, headerValue); @@ -94,16 +94,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodNetworkHTTPClientHEAD(miniScript)); + miniScript->registerMethod(new MethodNetworkHTTPClientHEAD(miniScript)); } { // - class ScriptMethodNetworkHTTPClientGET: public MiniScript::ScriptMethod { + class MethodNetworkHTTPClientGET: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNetworkHTTPClientGET(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNetworkHTTPClientGET(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "url", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_MAP, .name = "queryParameters", .optional = true, .reference = false, .nullable = true }, @@ -116,16 +116,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "network.httpclient.get"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string url; - if (argumentValues.size() <= 3 && - MiniScript::getStringValue(argumentValues, 0, url, false) == true && - (argumentValues.size() <= 1 || argumentValues[1].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 2 || argumentValues[2].getType() == MiniScript::TYPE_MAP)) { + if (arguments.size() <= 3 && + MiniScript::getStringValue(arguments, 0, url, false) == true && + (arguments.size() <= 1 || arguments[1].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 2 || arguments[2].getType() == MiniScript::TYPE_MAP)) { // GET parameters unordered_map getParameters; - if (argumentValues.size() >= 2) { - auto getParameterMapPtr = argumentValues[1].getMapPointer(); + if (arguments.size() >= 2) { + auto getParameterMapPtr = arguments[1].getMapPointer(); if (getParameterMapPtr != nullptr) { for (const auto& [key, value]: *getParameterMapPtr) { getParameters[key] = value->getValueAsString(); @@ -135,8 +135,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // headers unordered_map headers; - if (argumentValues.size() >= 3) { - auto headersMapPtr = argumentValues[2].getMapPointer(); + if (arguments.size() >= 3) { + auto headersMapPtr = arguments[2].getMapPointer(); if (headersMapPtr != nullptr) { for (const auto& [key, value]: *headersMapPtr) { headers[key] = value->getValueAsString(); @@ -162,7 +162,7 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { returnValue.setMapEntry("status", static_cast(httpClient.getStatusCode())); returnValue.setMapEntry("response", response); // - MiniScript::ScriptVariable responseHeaders; + MiniScript::Variable responseHeaders; responseHeaders.setType(MiniScript::TYPE_MAP); for (const auto& [headerName, headerValue]: httpClient.getResponseHeaders()) { responseHeaders.setMapEntry(headerName, headerValue); @@ -177,16 +177,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodNetworkHTTPClientGET(miniScript)); + miniScript->registerMethod(new MethodNetworkHTTPClientGET(miniScript)); } { // - class ScriptMethodNetworkHTTPClientPOST: public MiniScript::ScriptMethod { + class MethodNetworkHTTPClientPOST: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNetworkHTTPClientPOST(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNetworkHTTPClientPOST(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "url", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "data", .optional = false, .reference = false, .nullable = false }, @@ -200,19 +200,19 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "network.httpclient.post"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string url; string dataString; - if (argumentValues.size() >= 2 && argumentValues.size() <= 4 && - MiniScript::getStringValue(argumentValues, 0, url, false) == true && - (MiniScript::getStringValue(argumentValues, 1, dataString, true) == true || argumentValues[2].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 2 || argumentValues[2].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 3 || argumentValues[3].getType() == MiniScript::TYPE_MAP)) { + if (arguments.size() >= 2 && arguments.size() <= 4 && + MiniScript::getStringValue(arguments, 0, url, false) == true && + (MiniScript::getStringValue(arguments, 1, dataString, true) == true || arguments[2].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 2 || arguments[2].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 3 || arguments[3].getType() == MiniScript::TYPE_MAP)) { // post parameters unordered_map postParameters; - if (argumentValues.size() >= 2) { - if (argumentValues[1].getType() == MiniScript::TYPE_MAP) { - auto postParameterMapPtr = argumentValues[1].getMapPointer(); + if (arguments.size() >= 2) { + if (arguments[1].getType() == MiniScript::TYPE_MAP) { + auto postParameterMapPtr = arguments[1].getMapPointer(); if (postParameterMapPtr != nullptr) { for (const auto& [key, value]: *postParameterMapPtr) { postParameters[key] = value->getValueAsString(); @@ -222,8 +222,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // GET parameters unordered_map getParameters; - if (argumentValues.size() >= 3) { - auto getParameterMapPtr = argumentValues[2].getMapPointer(); + if (arguments.size() >= 3) { + auto getParameterMapPtr = arguments[2].getMapPointer(); if (getParameterMapPtr != nullptr) { for (const auto& [key, value]: *getParameterMapPtr) { getParameters[key] = value->getValueAsString(); @@ -232,8 +232,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // headers unordered_map headers; - if (argumentValues.size() >= 4) { - auto headersMapPtr = argumentValues[3].getMapPointer(); + if (arguments.size() >= 4) { + auto headersMapPtr = arguments[3].getMapPointer(); if (headersMapPtr != nullptr) { for (const auto& [key, value]: *headersMapPtr) { headers[key] = value->getValueAsString(); @@ -264,7 +264,7 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { returnValue.setMapEntry("status", static_cast(httpClient.getStatusCode())); returnValue.setMapEntry("response", response); // - MiniScript::ScriptVariable responseHeaders; + MiniScript::Variable responseHeaders; responseHeaders.setType(MiniScript::TYPE_MAP); for (const auto& [headerName, headerValue]: httpClient.getResponseHeaders()) { responseHeaders.setMapEntry(headerName, headerValue); @@ -279,16 +279,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodNetworkHTTPClientPOST(miniScript)); + miniScript->registerMethod(new MethodNetworkHTTPClientPOST(miniScript)); } { // - class ScriptMethodNetworkHTTPClientPUT: public MiniScript::ScriptMethod { + class MethodNetworkHTTPClientPUT: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNetworkHTTPClientPUT(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNetworkHTTPClientPUT(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "url", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "data", .optional = false, .reference = false, .nullable = false }, @@ -302,19 +302,19 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "network.httpclient.put"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string url; string dataString; - if (argumentValues.size() >= 2 && argumentValues.size() <= 4 && - MiniScript::getStringValue(argumentValues, 0, url, false) == true && - (MiniScript::getStringValue(argumentValues, 1, dataString, true) == true || argumentValues[2].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 2 || argumentValues[2].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 3 || argumentValues[3].getType() == MiniScript::TYPE_MAP)) { + if (arguments.size() >= 2 && arguments.size() <= 4 && + MiniScript::getStringValue(arguments, 0, url, false) == true && + (MiniScript::getStringValue(arguments, 1, dataString, true) == true || arguments[2].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 2 || arguments[2].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 3 || arguments[3].getType() == MiniScript::TYPE_MAP)) { // post parameters unordered_map postParameters; - if (argumentValues.size() >= 2) { - if (argumentValues[1].getType() == MiniScript::TYPE_MAP) { - auto postParameterMapPtr = argumentValues[1].getMapPointer(); + if (arguments.size() >= 2) { + if (arguments[1].getType() == MiniScript::TYPE_MAP) { + auto postParameterMapPtr = arguments[1].getMapPointer(); if (postParameterMapPtr != nullptr) { for (const auto& [key, value]: *postParameterMapPtr) { postParameters[key] = value->getValueAsString(); @@ -324,8 +324,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // GET parameters unordered_map getParameters; - if (argumentValues.size() >= 3) { - auto getParameterMapPtr = argumentValues[2].getMapPointer(); + if (arguments.size() >= 3) { + auto getParameterMapPtr = arguments[2].getMapPointer(); if (getParameterMapPtr != nullptr) { for (const auto& [key, value]: *getParameterMapPtr) { getParameters[key] = value->getValueAsString(); @@ -334,8 +334,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // headers unordered_map headers; - if (argumentValues.size() >= 4) { - auto headersMapPtr = argumentValues[3].getMapPointer(); + if (arguments.size() >= 4) { + auto headersMapPtr = arguments[3].getMapPointer(); if (headersMapPtr != nullptr) { for (const auto& [key, value]: *headersMapPtr) { headers[key] = value->getValueAsString(); @@ -366,7 +366,7 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { returnValue.setMapEntry("status", static_cast(httpClient.getStatusCode())); returnValue.setMapEntry("response", response); // - MiniScript::ScriptVariable responseHeaders; + MiniScript::Variable responseHeaders; responseHeaders.setType(MiniScript::TYPE_MAP); for (const auto& [headerName, headerValue]: httpClient.getResponseHeaders()) { responseHeaders.setMapEntry(headerName, headerValue); @@ -381,16 +381,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodNetworkHTTPClientPUT(miniScript)); + miniScript->registerMethod(new MethodNetworkHTTPClientPUT(miniScript)); } { // - class ScriptMethodNetworkHTTPClientDELETE: public MiniScript::ScriptMethod { + class MethodNetworkHTTPClientDELETE: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodNetworkHTTPClientDELETE(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodNetworkHTTPClientDELETE(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "url", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_MAP, .name = "queryParameters", .optional = true, .reference = false, .nullable = true }, @@ -403,16 +403,16 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "network.httpclient.delete"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string url; - if (argumentValues.size() <= 3 && - MiniScript::getStringValue(argumentValues, 0, url, false) == true && - (argumentValues.size() <= 1 || argumentValues[1].getType() == MiniScript::TYPE_MAP) && - (argumentValues.size() <= 2 || argumentValues[2].getType() == MiniScript::TYPE_MAP)) { + if (arguments.size() <= 3 && + MiniScript::getStringValue(arguments, 0, url, false) == true && + (arguments.size() <= 1 || arguments[1].getType() == MiniScript::TYPE_MAP) && + (arguments.size() <= 2 || arguments[2].getType() == MiniScript::TYPE_MAP)) { // GET parameters unordered_map getParameters; - if (argumentValues.size() >= 2) { - auto getParameterMapPtr = argumentValues[1].getMapPointer(); + if (arguments.size() >= 2) { + auto getParameterMapPtr = arguments[1].getMapPointer(); if (getParameterMapPtr != nullptr) { for (const auto& [key, value]: *getParameterMapPtr) { getParameters[key] = value->getValueAsString(); @@ -421,8 +421,8 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } // headers unordered_map headers; - if (argumentValues.size() >= 3) { - auto headersMapPtr = argumentValues[2].getMapPointer(); + if (arguments.size() >= 3) { + auto headersMapPtr = arguments[2].getMapPointer(); if (headersMapPtr != nullptr) { for (const auto& [key, value]: *headersMapPtr) { headers[key] = value->getValueAsString(); @@ -441,7 +441,7 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { returnValue.setType(MiniScript::TYPE_MAP); returnValue.setMapEntry("status", static_cast(httpClient.getStatusCode())); // - MiniScript::ScriptVariable responseHeaders; + MiniScript::Variable responseHeaders; responseHeaders.setType(MiniScript::TYPE_MAP); for (const auto& [headerName, headerValue]: httpClient.getResponseHeaders()) { responseHeaders.setMapEntry(headerName, headerValue); @@ -456,6 +456,6 @@ void NetworkMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodNetworkHTTPClientDELETE(miniScript)); + miniScript->registerMethod(new MethodNetworkHTTPClientDELETE(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/ScriptMethods.cpp b/ext/miniscript/src/miniscript/miniscript/ScriptMethods.cpp index 93a58e7c1..7f44b79f7 100644 --- a/ext/miniscript/src/miniscript/miniscript/ScriptMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/ScriptMethods.cpp @@ -21,40 +21,40 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { // script methods { // - class ScriptMethodScriptWaitForCondition: public MiniScript::ScriptMethod { + class MethodScriptWaitForCondition: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptWaitForCondition(MiniScript* miniScript): miniScript(miniScript) {} + MethodScriptWaitForCondition(MiniScript* miniScript): miniScript(miniScript) {} const string getMethodName() override { return "script.waitForCondition"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // script bindings miniScript->getScriptState().timeWaitStarted = Time::getCurrentMillis(); miniScript->getScriptState().timeWaitTime = 100LL; miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_WAIT_FOR_CONDITION); } }; - miniScript->registerMethod(new ScriptMethodScriptWaitForCondition(miniScript)); + miniScript->registerMethod(new MethodScriptWaitForCondition(miniScript)); } { // - class ScriptMethodScriptWait: public MiniScript::ScriptMethod { + class MethodScriptWait: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptWait(MiniScript* miniScript): - MiniScript::ScriptMethod({ + MethodScriptWait(MiniScript* miniScript): + MiniScript::Method({ { .type = MiniScript::TYPE_INTEGER, .name = "time", .optional = false, .reference = false, .nullable = false } }), miniScript(miniScript) {} const string getMethodName() override { return "script.wait"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t time; - if (miniScript->getIntegerValue(argumentValues, 0, time) == true) { + if (miniScript->getIntegerValue(arguments, 0, time) == true) { miniScript->getScriptState().timeWaitStarted = Time::getCurrentMillis(); miniScript->getScriptState().timeWaitTime = time; miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_WAIT); @@ -63,16 +63,16 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodScriptWait(miniScript)); + miniScript->registerMethod(new MethodScriptWait(miniScript)); } { // - class ScriptMethodScriptEmit: public MiniScript::ScriptMethod { + class MethodScriptEmit: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptEmit(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodScriptEmit(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false } } @@ -81,9 +81,9 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "script.emit"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string condition; - if (MiniScript::getStringValue(argumentValues, 0, condition, false) == true) { + if (MiniScript::getStringValue(arguments, 0, condition, false) == true) { miniScript->emit(condition); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -91,16 +91,16 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodScriptEmit(miniScript)); + miniScript->registerMethod(new MethodScriptEmit(miniScript)); } { // - class ScriptMethodScriptEnableNamedCondition: public MiniScript::ScriptMethod { + class MethodScriptEnableNamedCondition: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptEnableNamedCondition(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodScriptEnableNamedCondition(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "name", .optional = false, .reference = false, .nullable = false } } @@ -109,9 +109,9 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "script.enableNamedCondition"; // METHOD_ENABLENAMEDCONDITION; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string name; - if (MiniScript::getStringValue(argumentValues, 0, name, false) == true) { + if (MiniScript::getStringValue(arguments, 0, name, false) == true) { miniScript->enabledNamedConditions.erase( remove( miniScript->enabledNamedConditions.begin(), @@ -127,16 +127,16 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodScriptEnableNamedCondition(miniScript)); + miniScript->registerMethod(new MethodScriptEnableNamedCondition(miniScript)); } { // - class ScriptMethodScriptDisableNamedCondition: public MiniScript::ScriptMethod { + class MethodScriptDisableNamedCondition: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptDisableNamedCondition(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodScriptDisableNamedCondition(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "name", .optional = false, .reference = false, .nullable = false } } @@ -145,9 +145,9 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "script.disableNamedCondition"; // METHOD_DISABLENAMEDCONDITION; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string name; - if (MiniScript::getStringValue(argumentValues, 0, name, false) == true) { + if (MiniScript::getStringValue(arguments, 0, name, false) == true) { miniScript->enabledNamedConditions.erase( remove( miniScript->enabledNamedConditions.begin(), @@ -162,21 +162,21 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodScriptDisableNamedCondition(miniScript)); + miniScript->registerMethod(new MethodScriptDisableNamedCondition(miniScript)); } { // - class ScriptMethodScriptGetNamedConditions: public MiniScript::ScriptMethod { + class MethodScriptGetNamedConditions: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptGetNamedConditions(MiniScript* miniScript): - MiniScript::ScriptMethod({}, MiniScript::TYPE_STRING), + MethodScriptGetNamedConditions(MiniScript* miniScript): + MiniScript::Method({}, MiniScript::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "script.getNamedConditions"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string result; for (const auto& namedCondition: miniScript->enabledNamedConditions) { result+= result.empty() == false?",":namedCondition; @@ -184,16 +184,16 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { returnValue.setValue(result); } }; - miniScript->registerMethod(new ScriptMethodScriptGetNamedConditions(miniScript)); + miniScript->registerMethod(new MethodScriptGetNamedConditions(miniScript)); } { // - class ScriptMethodScriptEvaluate: public MiniScript::ScriptMethod { + class MethodScriptEvaluate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptEvaluate(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodScriptEvaluate(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "statement", .optional = false, .reference = false, .nullable = false } }, @@ -203,9 +203,9 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "script.evaluate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string statementString; - if (miniScript->getStringValue(argumentValues, 0, statementString, false) == false) { + if (miniScript->getStringValue(arguments, 0, statementString, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -215,16 +215,16 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodScriptEvaluate(miniScript)); + miniScript->registerMethod(new MethodScriptEvaluate(miniScript)); } { // - class ScriptMethodScriptCall: public MiniScript::ScriptMethod { + class MethodScriptCall: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptCall(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodScriptCall(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "function", .optional = false, .reference = false, .nullable = false } }, @@ -234,9 +234,9 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "script.call"; // METHOD_SCRIPTCALL; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string function; - if (miniScript->getStringValue(argumentValues, 0, function) == false) { + if (miniScript->getStringValue(arguments, 0, function) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -245,18 +245,18 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": function not found: " + function); miniScript->startErrorScript(); } else { - #if defined (__APPLE__) - // MACOSX currently does not support initializing span using begin and end iterators, - vector callArgumentValues(argumentValues.size() - 1); - for (auto i = 1; i < argumentValues.size(); i++) callArgumentValues[i - 1] = move(argumentValues[i]); + #if defined (__clang__) + // Clang currently does not support initializing span using begin and end iterators, + vector callArguments(arguments.size() - 1); + for (auto i = 1; i < arguments.size(); i++) callArguments[i - 1] = move(arguments[i]); // call - span callArgumentValuesSpan(callArgumentValues); - miniScript->call(scriptIdx, callArgumentValuesSpan, returnValue); + span callArgumentsSpan(callArguments); + miniScript->call(scriptIdx, callArgumentsSpan, returnValue); // move back arguments - for (auto i = 1; i < argumentValues.size(); i++) argumentValues[i] = move(callArgumentValues[i - 1]); + for (auto i = 1; i < arguments.size(); i++) arguments[i] = move(callArguments[i - 1]); #else - span callArgumentValuesSpan(argumentValues.begin() + 1, argumentValues.end()); - miniScript->call(scriptIdx, callArgumentValuesSpan, returnValue); + span callArgumentsSpan(arguments.begin() + 1, arguments.end()); + miniScript->call(scriptIdx, callArgumentsSpan, returnValue); #endif } } @@ -265,43 +265,43 @@ void ScriptMethods::registerMethods(MiniScript* miniScript) { return true; } }; - miniScript->registerMethod(new ScriptMethodScriptCall(miniScript)); + miniScript->registerMethod(new MethodScriptCall(miniScript)); } { // - class ScriptMethodScriptStop: public MiniScript::ScriptMethod { + class MethodScriptStop: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptStop(MiniScript* miniScript): MiniScript::ScriptMethod(), miniScript(miniScript) {} + MethodScriptStop(MiniScript* miniScript): MiniScript::Method(), miniScript(miniScript) {} const string getMethodName() override { return "script.stop"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // miniScript->stopScriptExecution(); miniScript->stopRunning(); } }; - miniScript->registerMethod(new ScriptMethodScriptStop(miniScript)); + miniScript->registerMethod(new MethodScriptStop(miniScript)); } { // - class ScriptMethodScriptGetVariables: public MiniScript::ScriptMethod { + class MethodScriptGetVariables: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodScriptGetVariables(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_MAP), miniScript(miniScript) {} + MethodScriptGetVariables(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_MAP), miniScript(miniScript) {} const string getMethodName() override { return "script.getVariables"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setType(MiniScript::TYPE_MAP); for (const auto& [variableName, variableValue]: miniScript->getScriptState().variables) { returnValue.setMapEntry(variableName, *variableValue); } } }; - miniScript->registerMethod(new ScriptMethodScriptGetVariables(miniScript)); + miniScript->registerMethod(new MethodScriptGetVariables(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/SetMethods.cpp b/ext/miniscript/src/miniscript/miniscript/SetMethods.cpp index d1d70a193..d78bfa592 100644 --- a/ext/miniscript/src/miniscript/miniscript/SetMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/SetMethods.cpp @@ -17,33 +17,33 @@ void SetMethods::registerMethods(MiniScript* miniScript) { // sets { // - class ScriptMethodSet: public MiniScript::ScriptMethod { + class MethodSet: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSet(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSet(MiniScript* miniScript): + MiniScript::Method( {}, MiniScript::TYPE_SET ), miniScript(miniScript) {} const string getMethodName() override { - return "set"; + return "Set"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setType(MiniScript::TYPE_SET); } }; - miniScript->registerMethod(new ScriptMethodSet(miniScript)); + miniScript->registerMethod(new MethodSet(miniScript)); } { // - class ScriptMethodSetInsert: public MiniScript::ScriptMethod { + class MethodSetInsert: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSetInsert(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSetInsert(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_SET, .name = "set", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false } @@ -52,31 +52,31 @@ void SetMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "set.insert"; + return "Set::insert"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() != 2 || - argumentValues[0].getType() != MiniScript::TYPE_SET || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() != 2 || + arguments[0].getType() != MiniScript::TYPE_SET || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].insertSetKey(key); + arguments[0].insertSetKey(key); } } }; - miniScript->registerMethod(new ScriptMethodSetInsert(miniScript)); + miniScript->registerMethod(new MethodSetInsert(miniScript)); } { // - class ScriptMethodSetHas: public MiniScript::ScriptMethod { + class MethodSetHas: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSetHas(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSetHas(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_SET, .name = "set", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false } @@ -85,31 +85,31 @@ void SetMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "set.has"; + return "Set::has"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_SET || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_SET || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(argumentValues[0].hasSetKey(key)); + returnValue.setValue(arguments[0].hasSetKey(key)); } } }; - miniScript->registerMethod(new ScriptMethodSetHas(miniScript)); + miniScript->registerMethod(new MethodSetHas(miniScript)); } { // - class ScriptMethodSetRemove: public MiniScript::ScriptMethod { + class MethodSetRemove: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSetRemove(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSetRemove(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_SET, .name = "set", .optional = false, .reference = true, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "key", .optional = false, .reference = false, .nullable = false } @@ -118,31 +118,31 @@ void SetMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "set.remove"; + return "Set::remove"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string key; - if (argumentValues.size() < 2 || - argumentValues[0].getType() != MiniScript::TYPE_SET || - MiniScript::getStringValue(argumentValues, 1, key, false) == false) { + if (arguments.size() < 2 || + arguments[0].getType() != MiniScript::TYPE_SET || + MiniScript::getStringValue(arguments, 1, key, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - argumentValues[0].removeSetKey(key); + arguments[0].removeSetKey(key); } } }; - miniScript->registerMethod(new ScriptMethodSetRemove(miniScript)); + miniScript->registerMethod(new MethodSetRemove(miniScript)); } { // - class ScriptMethodSetGetKeys: public MiniScript::ScriptMethod { + class MethodSetGetKeys: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodSetGetKeys(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodSetGetKeys(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_SET, .name = "set", .optional = false, .reference = false, .nullable = false }, }, @@ -150,16 +150,16 @@ void SetMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "set.getKeys"; + return "Set::getKeys"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // - if (argumentValues.size() != 1 || - argumentValues[0].getType() != MiniScript::TYPE_SET) { + if (arguments.size() != 1 || + arguments[0].getType() != MiniScript::TYPE_SET) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto keys = argumentValues[0].getSetKeys(); + auto keys = arguments[0].getSetKeys(); returnValue.setType(MiniScript::TYPE_ARRAY); for (const auto& key: keys) { returnValue.pushArrayEntry(key); @@ -167,6 +167,80 @@ void SetMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodSetGetKeys(miniScript)); + miniScript->registerMethod(new MethodSetGetKeys(miniScript)); + } + { + // + class MethodSetClear: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodSetClear(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_SET, .name = "set", .optional = false, .reference = true, .nullable = false } + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "Set::clear"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + if ((arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_SET)) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + arguments[0].clearSet(); + } + } + }; + miniScript->registerMethod(new MethodSetClear(miniScript)); + } + { + // + class MethodSetForEach: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodSetForEach(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_SET, .name = "set", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_FUNCTION_ASSIGNMENT, .name = "function", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "cookie", .optional = true, .reference = true, .nullable = false } + }, + MiniScript::TYPE_NULL + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "Set::forEach"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string function; + if ((arguments.size() != 2 && arguments.size() != 3) || + arguments[0].getType() != MiniScript::TYPE_SET || + MiniScript::getStringValue(arguments, 1, function, false) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto setPtr = arguments[0].getSetPointer(); + if (setPtr != nullptr) { + for (auto setEntry: *setPtr) { + vector functionArguments { MiniScript::Variable(setEntry) }; + if (arguments.size() == 3) functionArguments.push_back(arguments[2]); + span functionArgumentsSpan(functionArguments); + MiniScript::Variable functionReturnValue; + miniScript->call(function, functionArgumentsSpan, functionReturnValue); + // exit condition + bool result = false; + functionReturnValue.getBooleanValue(result, false); + if (result == true) break; + } + } + } + } + }; + miniScript->registerMethod(new MethodSetForEach(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/StringMethods.cpp b/ext/miniscript/src/miniscript/miniscript/StringMethods.cpp index 52a793a72..94eee5f5c 100644 --- a/ext/miniscript/src/miniscript/miniscript/StringMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/StringMethods.cpp @@ -8,75 +8,33 @@ #include #include #include -#include +#include +#include #include using std::span; -using miniscript::utilities::StringTools; +using miniscript::miniscript::StringMethods; using miniscript::math::Math; using miniscript::miniscript::MiniScript; -using miniscript::miniscript::StringMethods; using miniscript::utilities::Character; using miniscript::utilities::Console; using miniscript::utilities::Float; using miniscript::utilities::Integer; +using miniscript::utilities::UTF8StringTools; using miniscript::utilities::UTF8CharacterIterator; -inline vector StringMethods::tokenize(const string& stringValue, const string& delimiters, bool emptyTokens) { - vector tokens; - // - string token; - // - UTF8CharacterIterator u8It(stringValue); - UTF8CharacterIterator delimiterU8It(delimiters); - // iterate string value - for (; u8It.hasNext(); ) { - auto c = u8It.next(); - // iterate delimiters - delimiterU8It.reset(); - // - auto foundDelimiter = false; - for (; delimiterU8It.hasNext(); ) { - // check if delimiter character is our current string value char - auto dc = delimiterU8It.next(); - // got a delimiter? - if (c == dc) { - foundDelimiter = true; - // yep, add token to elements if we have any - if (emptyTokens == true || token.empty() == false) { - tokens.push_back(token); - token.clear(); - } - // - break; - } - } - // - if (foundDelimiter == false) { - // no delimiter, add char to token - token+= Character::toString(c); - } - } - // do we have a token still? add it to elements - if (emptyTokens == true || token.empty() == false) { - tokens.push_back(token); - } - // - return tokens; -} - void StringMethods::registerMethods(MiniScript* miniScript) { // string functions { // - class ScriptMethodString: public MiniScript::ScriptMethod { + class MethodString: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodString(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodString(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -84,11 +42,11 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string"; + return "String"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { returnValue.setValue(stringValue); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -96,16 +54,16 @@ void StringMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodString(miniScript)); + miniScript->registerMethod(new MethodString(miniScript)); } { // - class ScriptMethodStringLength: public MiniScript::ScriptMethod { + class MethodStringLength: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringLength(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringLength(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -113,32 +71,28 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.length"; + return "String::length"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { - // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(2147483647); // 2 ^ 31 - 1 - // - returnValue.setValue(static_cast(u8It.getCharacterPosition())); + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { + returnValue.setValue(static_cast(UTF8StringTools::getLength(stringValue, arguments[0].getStringValueCache()))); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } } }; - miniScript->registerMethod(new ScriptMethodStringLength(miniScript)); + miniScript->registerMethod(new MethodStringLength(miniScript)); } { // - class ScriptMethodStringCharAt: public MiniScript::ScriptMethod { + class MethodStringCharAt: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringCharAt(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringCharAt(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "index", .optional = false, .reference = false, .nullable = false } @@ -147,34 +101,30 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.charAt"; + return "String::charAt"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; int64_t index; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getIntegerValue(argumentValues, 1, index, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getIntegerValue(arguments, 1, index, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(index); - // - returnValue.setValue(u8It.hasNext() == true?Character::toString(u8It.next()):string()); + returnValue.setValue(UTF8StringTools::getCharAt(stringValue, index, arguments[0].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringCharAt(miniScript)); + miniScript->registerMethod(new MethodStringCharAt(miniScript)); } { // - class ScriptMethodStringStartsWith: public MiniScript::ScriptMethod { + class MethodStringStartsWith: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringStartsWith(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringStartsWith(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "prefix", .optional = false, .reference = false, .nullable = false } @@ -183,30 +133,30 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.startsWith"; + return "String::startsWith"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string prefix; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, prefix, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, prefix, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(StringTools::startsWith(stringValue, prefix)); + returnValue.setValue(UTF8StringTools::startsWith(stringValue, prefix)); } } }; - miniScript->registerMethod(new ScriptMethodStringStartsWith(miniScript)); + miniScript->registerMethod(new MethodStringStartsWith(miniScript)); } { // - class ScriptMethodStringEndsWith: public MiniScript::ScriptMethod { + class MethodStringEndsWith: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringEndsWith(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringEndsWith(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "suffix", .optional = false, .reference = false, .nullable = false } @@ -215,30 +165,30 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.endsWith"; + return "String::endsWith"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string suffix; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, suffix, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, suffix, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(StringTools::endsWith(stringValue, suffix)); + returnValue.setValue(UTF8StringTools::endsWith(stringValue, suffix)); } } }; - miniScript->registerMethod(new ScriptMethodStringEndsWith(miniScript)); + miniScript->registerMethod(new MethodStringEndsWith(miniScript)); } { // - class ScriptMethodStringReplace: public MiniScript::ScriptMethod { + class MethodStringReplace: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringReplace(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringReplace(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, @@ -249,38 +199,34 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.replace"; + return "String::replace"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string what; string by; int64_t beginIndex = 0; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, what, false) == false || - MiniScript::getStringValue(argumentValues, 2, by, false) == false || - MiniScript::getIntegerValue(argumentValues, 3, beginIndex, true) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, what, false) == false || + MiniScript::getStringValue(arguments, 2, by, false) == false || + MiniScript::getIntegerValue(arguments, 3, beginIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(beginIndex); - // - returnValue.setValue(StringTools::replace(stringValue, what, by, u8It.getBinaryPosition())); + returnValue.setValue(UTF8StringTools::replace(stringValue, what, by, beginIndex, arguments[0].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringReplace(miniScript)); + miniScript->registerMethod(new MethodStringReplace(miniScript)); } { // - class ScriptMethodStringIndexOf: public MiniScript::ScriptMethod { + class MethodStringIndexOf: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringIndexOf(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringIndexOf(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, @@ -290,42 +236,32 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.indexOf"; + return "String::indexOf"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string what; int64_t beginIndex = 0; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, what, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, beginIndex, true) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, what, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(beginIndex); - // - auto index = StringTools::indexOf(stringValue, what, u8It.getBinaryPosition()); - if (index == string::npos) { - returnValue.setValue(static_cast(-1)); - } else { - u8It.seekBinaryPosition(index); - returnValue.setValue(static_cast(u8It.getCharacterPosition())); - } + returnValue.setValue(UTF8StringTools::indexOf(stringValue, what, beginIndex, arguments[0].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringIndexOf(miniScript)); + miniScript->registerMethod(new MethodStringIndexOf(miniScript)); } { // - class ScriptMethodStringFirstIndexOf: public MiniScript::ScriptMethod { + class MethodStringFirstIndexOf: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringFirstIndexOf(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringFirstIndexOf(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, @@ -335,50 +271,32 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.firstIndexOf"; + return "String::firstIndexOf"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string what; int64_t beginIndex = 0; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, what, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, beginIndex, true) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, what, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(beginIndex); - // utf8 character iterator - UTF8CharacterIterator whatU8It(what, argumentValues[1].getStringValueCache()); - // - auto index = Integer::MAX_VALUE; - while (whatU8It.hasNext() == true) { - auto whatChar = Character::toString(whatU8It.next()); - auto whatIndex = StringTools::indexOf(stringValue, whatChar, u8It.getBinaryPosition()); - if (whatIndex != string::npos) index = Math::min(index, whatIndex); - } - // - if (index == string::npos) { - returnValue.setValue(static_cast(-1)); - } else { - u8It.seekBinaryPosition(index); - returnValue.setValue(static_cast(u8It.getCharacterPosition())); - } + returnValue.setValue(UTF8StringTools::firstIndexOf(stringValue, what, beginIndex, arguments[0].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringFirstIndexOf(miniScript)); + miniScript->registerMethod(new MethodStringFirstIndexOf(miniScript)); } { // - class ScriptMethodStringLastIndexOf: public MiniScript::ScriptMethod { + class MethodStringLastIndexOf: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringLastIndexOf(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringLastIndexOf(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, @@ -388,50 +306,122 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.lastIndexOf"; + return "String::lastIndexOf"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string what; - int64_t beginIndex = -1; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, what, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, beginIndex, true) == false) { + int64_t beginIndex = 0; + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, what, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(beginIndex); - // utf8 character iterator - UTF8CharacterIterator whatU8It(what, argumentValues[1].getStringValueCache()); - // - auto index = Integer::MIN_VALUE; - while (whatU8It.hasNext() == true) { - auto whatChar = Character::toString(whatU8It.next()); - auto whatIndex = StringTools::indexOf(stringValue, whatChar, u8It.getBinaryPosition()); - if (whatIndex != string::npos) index = Math::max(index, whatIndex); - } - // - if (index == string::npos) { - returnValue.setValue(static_cast(-1)); - } else { - u8It.seekBinaryPosition(index); - returnValue.setValue(static_cast(u8It.getCharacterPosition())); - } + returnValue.setValue(UTF8StringTools::lastIndexOf(stringValue, what, beginIndex, arguments[0].getStringValueCache())); + } + } + }; + miniScript->registerMethod(new MethodStringLastIndexOf(miniScript)); + } + { + // + class MethodStringFirstIndexOfChars: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodStringFirstIndexOfChars(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "beginIndex", .optional = true, .reference = false, .nullable = false } + }, + MiniScript::TYPE_INTEGER + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "String::firstIndexOfChars"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string stringValue; + string what; + int64_t beginIndex = 0; + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, what, false) == false || + MiniScript::getIntegerValue(arguments, 2, beginIndex, true) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + returnValue.setValue( + static_cast( + UTF8StringTools::firstIndexOfChars( + stringValue, + what, + beginIndex, + arguments[0].getStringValueCache(), + arguments[1].getStringValueCache() + ) + ) + ); + } + } + }; + miniScript->registerMethod(new MethodStringFirstIndexOfChars(miniScript)); + } + { + // + class MethodStringLastIndexOfChars: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodStringLastIndexOfChars(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "endIndex", .optional = true, .reference = false, .nullable = false } + }, + MiniScript::TYPE_INTEGER + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "String::lastIndexOfChars"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string stringValue; + string what; + int64_t endIndex = -1; + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, what, false) == false || + MiniScript::getIntegerValue(arguments, 2, endIndex, true) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + returnValue.setValue( + static_cast( + UTF8StringTools::lastIndexOfChars( + stringValue, + what, + endIndex, + arguments[0].getStringValueCache(), + arguments[1].getStringValueCache() + ) + ) + ); } } }; - miniScript->registerMethod(new ScriptMethodStringLastIndexOf(miniScript)); + miniScript->registerMethod(new MethodStringLastIndexOfChars(miniScript)); } { // - class ScriptMethodStringSubString: public MiniScript::ScriptMethod { + class MethodStringSubString: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringSubString(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringSubString(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_INTEGER, .name = "beginIndex", .optional = false, .reference = false, .nullable = false }, @@ -441,44 +431,33 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.substring"; + return "String::substring"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; int64_t beginIndex; - int64_t endIndex = -1; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getIntegerValue(argumentValues, 1, beginIndex, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, endIndex, true) == false) { + int64_t endIndex = string::npos; + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getIntegerValue(arguments, 1, beginIndex, false) == false || + MiniScript::getIntegerValue(arguments, 2, endIndex, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { // utf8 character iterator - UTF8CharacterIterator u8It(stringValue, argumentValues[0].getStringValueCache()); - u8It.seekCharacterPosition(beginIndex); - auto u8BeginIndex = u8It.getBinaryPosition(); - // - if (endIndex == -1) { - returnValue.setValue(StringTools::substring(stringValue, u8BeginIndex)); - } else { - u8It.seekCharacterPosition(endIndex); - auto u8EndIndex = u8It.getBinaryPosition(); - // - returnValue.setValue(StringTools::substring(stringValue, u8BeginIndex, u8EndIndex)); - } + returnValue.setValue(UTF8StringTools::substring(stringValue, beginIndex, endIndex)); } } }; - miniScript->registerMethod(new ScriptMethodStringSubString(miniScript)); + miniScript->registerMethod(new MethodStringSubString(miniScript)); } { // - class ScriptMethodStringEqualsIgnoreCase: public MiniScript::ScriptMethod { + class MethodStringEqualsIgnoreCase: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringEqualsIgnoreCase(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringEqualsIgnoreCase(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "other", .optional = false, .reference = false, .nullable = false }, @@ -487,30 +466,30 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.equalsIgnoreCase"; + return "String::equalsIgnoreCase"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string other; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, other, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, other, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(StringTools::equalsIgnoreCase(stringValue, other)); + returnValue.setValue(UTF8StringTools::equalsIgnoreCase(stringValue, other, arguments[0].getStringValueCache(), arguments[1].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringEqualsIgnoreCase(miniScript)); + miniScript->registerMethod(new MethodStringEqualsIgnoreCase(miniScript)); } { // - class ScriptMethodStringTrim: public MiniScript::ScriptMethod { + class MethodStringTrim: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringTrim(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringTrim(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, }, @@ -518,28 +497,28 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.trim"; + return "String::trim"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(StringTools::trim(stringValue)); + returnValue.setValue(UTF8StringTools::trim(stringValue, arguments[0].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringTrim(miniScript)); + miniScript->registerMethod(new MethodStringTrim(miniScript)); } { // - class ScriptMethodStringRegexMatch: public MiniScript::ScriptMethod { + class MethodStringRegexMatch: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringRegexMatch(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringRegexMatch(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "pattern", .optional = false, .reference = false, .nullable = false }, @@ -548,30 +527,30 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.regexMatch"; + return "String::regexMatch"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string pattern; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, pattern, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, pattern, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(StringTools::regexMatch(stringValue, pattern)); + returnValue.setValue(UTF8StringTools::regexMatch(stringValue, pattern)); } } }; - miniScript->registerMethod(new ScriptMethodStringRegexMatch(miniScript)); + miniScript->registerMethod(new MethodStringRegexMatch(miniScript)); } { // - class ScriptMethodStringRegexReplace: public MiniScript::ScriptMethod { + class MethodStringRegexReplace: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringRegexReplace(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringRegexReplace(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "pattern", .optional = false, .reference = false, .nullable = false }, @@ -581,32 +560,32 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.regexReplace"; + return "String::regexReplace"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string pattern; string by; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, pattern, false) == false || - MiniScript::getStringValue(argumentValues, 2, by, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, pattern, false) == false || + MiniScript::getStringValue(arguments, 2, by, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - returnValue.setValue(StringTools::regexReplace(stringValue, pattern, by)); + returnValue.setValue(UTF8StringTools::regexReplace(stringValue, pattern, by)); } } }; - miniScript->registerMethod(new ScriptMethodStringRegexReplace(miniScript)); + miniScript->registerMethod(new MethodStringRegexReplace(miniScript)); } { // - class ScriptMethodStringTokenize: public MiniScript::ScriptMethod { + class MethodStringTokenize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringTokenize(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringTokenize(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "delimiters", .optional = false, .reference = false, .nullable = false }, @@ -615,17 +594,17 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.tokenize"; + return "String::tokenize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string delimiters; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, delimiters, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, delimiters, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto tokenizedStringVector = StringMethods::tokenize(stringValue, delimiters); + auto tokenizedStringVector = UTF8StringTools::tokenize(stringValue, delimiters); // returnValue.setType(MiniScript::TYPE_ARRAY); for (const auto& tokenizedString: tokenizedStringVector) { @@ -634,53 +613,93 @@ void StringMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodStringTokenize(miniScript)); + miniScript->registerMethod(new MethodStringTokenize(miniScript)); } { // - class ScriptMethodStringSpace: public MiniScript::ScriptMethod { + class MethodStringGenerate: public MiniScript::Method { private: - MiniScript* miniScript { nullptr }; + MiniScript *miniScript { nullptr }; public: - ScriptMethodStringSpace(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringGenerate(MiniScript *miniScript) : + MiniScript::Method( { - { .type = MiniScript::TYPE_INTEGER, .name = "spaces", .optional = true, .reference = false, .nullable = false } + { .type = MiniScript::TYPE_STRING, .name = "what", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "count", .optional = true, .reference = false, .nullable = false } }, MiniScript::TYPE_STRING ), - miniScript(miniScript) {} + miniScript(miniScript) { + // + } const string getMethodName() override { - return "string.space"; + return "String::generate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { - int64_t spaces = 1; - if (MiniScript::getIntegerValue(argumentValues, 0, spaces, true) == false) { + void executeMethod(span &arguments, MiniScript::Variable &returnValue, const MiniScript::Statement &statement) override { + string what; + int64_t count = 1; + if (MiniScript::getStringValue(arguments, 0, what, false) == false || + MiniScript::getIntegerValue(arguments, 1, count, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - string spacesString; - for (auto i = 0; i < spaces; i++) spacesString+= " "; - returnValue.setValue(spacesString); + returnValue.setValue(UTF8StringTools::generate(what, count)); } } }; - miniScript->registerMethod(new ScriptMethodStringSpace(miniScript)); + miniScript->registerMethod(new MethodStringGenerate(miniScript)); } { // - class ScriptMethodStringConcatenate: public MiniScript::ScriptMethod { + class MethodStringIndent: public MiniScript::Method { + private: + MiniScript *miniScript { nullptr }; + public: + MethodStringIndent(MiniScript *miniScript) : + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "src", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_STRING, .name = "with", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::TYPE_INTEGER, .name = "count", .optional = false, .reference = false, .nullable = false } + }, + MiniScript::TYPE_STRING + ), + miniScript(miniScript) { + // + } + const string getMethodName() override { + return "String::indent"; + } + void executeMethod(span &arguments, MiniScript::Variable &returnValue, const MiniScript::Statement &statement) override { + string src; + string with; + int64_t count = 1; + if (MiniScript::getStringValue(arguments, 0, src, false) == false || + MiniScript::getStringValue(arguments, 1, with, false) == false || + MiniScript::getIntegerValue(arguments, 2, count, true) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + returnValue.setValue(UTF8StringTools::indent(src, with, count)); + } + } + }; + miniScript->registerMethod(new MethodStringIndent(miniScript)); + } + { + // + class MethodStringConcatenate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringConcatenate(MiniScript* miniScript): MiniScript::ScriptMethod({}, MiniScript::TYPE_STRING), miniScript(miniScript) {} + MethodStringConcatenate(MiniScript* miniScript): MiniScript::Method({}, MiniScript::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { - return "string.concatenate"; + return "String::concatenate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string result; - for (const auto& argumentValue: argumentValues) { - result+= argumentValue.getValueAsString(); + for (const auto& argument: arguments) { + result+= argument.getValueAsString(); } returnValue.setValue(result); } @@ -688,16 +707,16 @@ void StringMethods::registerMethods(MiniScript* miniScript) { return true; } }; - miniScript->registerMethod(new ScriptMethodStringConcatenate(miniScript)); + miniScript->registerMethod(new MethodStringConcatenate(miniScript)); } { // - class ScriptMethodToStringUpperCase: public MiniScript::ScriptMethod { + class MethodToStringUpperCase: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodToStringUpperCase(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodToStringUpperCase(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -705,28 +724,28 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.toUpperCase"; + return "String::toUpperCase"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { - returnValue.setValue(StringTools::toUpperCase(stringValue)); + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { + returnValue.setValue(UTF8StringTools::toUpperCase(stringValue, arguments[0].getStringValueCache())); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } } }; - miniScript->registerMethod(new ScriptMethodToStringUpperCase(miniScript)); + miniScript->registerMethod(new MethodToStringUpperCase(miniScript)); } { // - class ScriptMethodToStringLowerCase: public MiniScript::ScriptMethod { + class MethodToStringLowerCase: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodToStringLowerCase(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodToStringLowerCase(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -734,28 +753,28 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.toLowerCase"; + return "String::toLowerCase"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { - returnValue.setValue(StringTools::toLowerCase(stringValue)); + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { + returnValue.setValue(UTF8StringTools::toLowerCase(stringValue, arguments[0].getStringValueCache())); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } } }; - miniScript->registerMethod(new ScriptMethodToStringLowerCase(miniScript)); + miniScript->registerMethod(new MethodToStringLowerCase(miniScript)); } { // - class ScriptMethodStringIsEmpty: public MiniScript::ScriptMethod { + class MethodStringIsEmpty: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringIsEmpty(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringIsEmpty(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -763,11 +782,11 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.isEmpty"; + return "String::isEmpty"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { returnValue.setValue(stringValue.empty()); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -775,16 +794,16 @@ void StringMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodStringIsEmpty(miniScript)); + miniScript->registerMethod(new MethodStringIsEmpty(miniScript)); } { // - class ScriptMethodStringIsFloat: public MiniScript::ScriptMethod { + class MethodStringIsFloat: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringIsFloat(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringIsFloat(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -792,11 +811,11 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.isFloat"; + return "String::isFloat"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { returnValue.setValue(Float::is(stringValue)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -804,16 +823,16 @@ void StringMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodStringIsFloat(miniScript)); + miniScript->registerMethod(new MethodStringIsFloat(miniScript)); } { // - class ScriptMethodStringIsInteger: public MiniScript::ScriptMethod { + class MethodStringIsInteger: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringIsInteger(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringIsInteger(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false } }, @@ -821,11 +840,11 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.isInteger"; + return "String::isInteger"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == true) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == true) { returnValue.setValue(Integer::is(stringValue)); } else { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -833,16 +852,16 @@ void StringMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodStringIsInteger(miniScript)); + miniScript->registerMethod(new MethodStringIsInteger(miniScript)); } { // - class ScriptMethodStringPadLeft: public MiniScript::ScriptMethod { + class MethodStringPadLeft: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringPadLeft(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringPadLeft(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "by", .optional = false, .reference = false, .nullable = false }, @@ -852,36 +871,32 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.padLeft"; + return "String::padLeft"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string by; int64_t toLength; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, by, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, toLength, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, by, false) == false || + MiniScript::getIntegerValue(arguments, 2, toLength, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // - auto result = stringValue; - while (StringMethods::getLength(result) < toLength) result = by + result; - // - returnValue.setValue(result); + returnValue.setValue(UTF8StringTools::padLeft(stringValue, by, toLength, arguments[0].getStringValueCache())); } } }; - miniScript->registerMethod(new ScriptMethodStringPadLeft(miniScript)); + miniScript->registerMethod(new MethodStringPadLeft(miniScript)); } { // - class ScriptMethodStringPadRight: public MiniScript::ScriptMethod { + class MethodStringPadRight: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodStringPadRight(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodStringPadRight(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_STRING, .name = "by", .optional = false, .reference = false, .nullable = false }, @@ -891,26 +906,84 @@ void StringMethods::registerMethods(MiniScript* miniScript) { ), miniScript(miniScript) {} const string getMethodName() override { - return "string.padRight"; + return "String::padRight"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string stringValue; string by; int64_t toLength; - if (MiniScript::getStringValue(argumentValues, 0, stringValue, false) == false || - MiniScript::getStringValue(argumentValues, 1, by, false) == false || - MiniScript::getIntegerValue(argumentValues, 2, toLength, false) == false) { + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false || + MiniScript::getStringValue(arguments, 1, by, false) == false || + MiniScript::getIntegerValue(arguments, 2, toLength, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - // - auto result = stringValue; - while (StringMethods::getLength(result) < toLength) result = result + by; - // - returnValue.setValue(result); + returnValue.setValue(UTF8StringTools::padRight(stringValue, by, toLength, arguments[0].getStringValueCache())); + } + } + }; + miniScript->registerMethod(new MethodStringPadRight(miniScript)); + } + { + // + class MethodStringToByteArray: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodStringToByteArray(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_STRING, .name = "string", .optional = false, .reference = false, .nullable = false }, + }, + MiniScript::TYPE_BYTEARRAY + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "String::toByteArray"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string stringValue; + if (MiniScript::getStringValue(arguments, 0, stringValue, false) == false) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + returnValue.setType(MiniScript::TYPE_BYTEARRAY); + for (auto i = 0; i < stringValue.size(); i++) returnValue.pushByteArrayEntry(stringValue[i]); + } + } + }; + miniScript->registerMethod(new MethodStringToByteArray(miniScript)); + } + { + // + class MethodStringFromByteArray: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodStringFromByteArray(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_BYTEARRAY, .name = "byteArray", .optional = false, .reference = false, .nullable = false }, + }, + MiniScript::TYPE_STRING + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "String::fromByteArray"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + string stringValue; + if (arguments.size() != 1 || arguments[0].getType() != MiniScript::TYPE_BYTEARRAY) { + Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); + miniScript->startErrorScript(); + } else { + auto byteArrayPointer = arguments[0].getByteArrayPointer(); + if (byteArrayPointer != nullptr) { + returnValue.setValue(string((const char*)(byteArrayPointer->data()), byteArrayPointer->size())); + } } } }; - miniScript->registerMethod(new ScriptMethodStringPadRight(miniScript)); + miniScript->registerMethod(new MethodStringFromByteArray(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/StringMethods.h b/ext/miniscript/src/miniscript/miniscript/StringMethods.h index 973232cc3..f745f6edd 100644 --- a/ext/miniscript/src/miniscript/miniscript/StringMethods.h +++ b/ext/miniscript/src/miniscript/miniscript/StringMethods.h @@ -19,17 +19,6 @@ class miniscript::miniscript::StringMethods { */ static void registerMethods(MiniScript* miniScript); - /** - * Get length aka character count - * @param stringValue string value - */ - static int getLength(const string& stringValue) { - UTF8CharacterIterator u8It(stringValue); - u8It.seekCharacterPosition(2147483647); // 2 ^ 31 - 1 - // - return u8It.getCharacterPosition(); - } - /** * Tokenize * @param stringValue string value diff --git a/ext/miniscript/src/miniscript/miniscript/TimeMethods.cpp b/ext/miniscript/src/miniscript/miniscript/TimeMethods.cpp index 00c66facb..ddd018b9f 100644 --- a/ext/miniscript/src/miniscript/miniscript/TimeMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/TimeMethods.cpp @@ -18,30 +18,30 @@ void TimeMethods::registerMethods(MiniScript* miniScript) { // time { // - class ScriptMethodTimeGetCurrentMillis: public MiniScript::ScriptMethod { + class MethodTimeGetCurrentMillis: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodTimeGetCurrentMillis(MiniScript* miniScript): - MiniScript::ScriptMethod({}, MiniScript::TYPE_INTEGER), + MethodTimeGetCurrentMillis(MiniScript* miniScript): + MiniScript::Method({}, MiniScript::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "time.getCurrentMillis"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { returnValue.setValue(Time::getCurrentMillis()); } }; - miniScript->registerMethod(new ScriptMethodTimeGetCurrentMillis(miniScript)); + miniScript->registerMethod(new MethodTimeGetCurrentMillis(miniScript)); } { // - class ScriptMethodTimeGetAsString: public MiniScript::ScriptMethod { + class MethodTimeGetAsString: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodTimeGetAsString(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodTimeGetAsString(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "format", .optional = true, .reference = false, .nullable = false } }, @@ -51,9 +51,9 @@ void TimeMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "time.getAsString"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { string format = "%Y-%m-%d %H:%M:%S"; - if (MiniScript::getStringValue(argumentValues, 0, format, true) == false) { + if (MiniScript::getStringValue(arguments, 0, format, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -61,6 +61,6 @@ void TimeMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodTimeGetAsString(miniScript)); + miniScript->registerMethod(new MethodTimeGetAsString(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/miniscript/Transpiler.cpp b/ext/miniscript/src/miniscript/miniscript/Transpiler.cpp index c3207a722..f31fce47b 100644 --- a/ext/miniscript/src/miniscript/miniscript/Transpiler.cpp +++ b/ext/miniscript/src/miniscript/miniscript/Transpiler.cpp @@ -27,31 +27,30 @@ using miniscript::utilities::Console; using miniscript::utilities::Integer; using miniscript::utilities::StringTools; -const unordered_set Transpiler::getAllMethodNames(MiniScript* miniScript) { +const unordered_set Transpiler::getAllClassesMethodNames(MiniScript* miniScript) { unordered_set allMethods; for (auto scriptMethod: miniScript->getMethods()) { string className; - if (scriptMethod->getMethodName().rfind('.') != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind('.')); + if (scriptMethod->getMethodName().rfind("::") != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind("::")); + if (className.empty() == true) continue; string method = StringTools::substring( scriptMethod->getMethodName(), - className.empty() == true?0:className.size() + 1, + className.size() + 2, scriptMethod->getMethodName().size()); // first argument name of method must equal the name of the class if (scriptMethod->getArgumentTypes().empty() == true || - scriptMethod->getArgumentTypes()[0].name != className) continue; + scriptMethod->getArgumentTypes()[0].name != StringTools::toLowerCase(className)) continue; // first argument of method must be of type of the class - if (className != MiniScript::ScriptVariable::getClassName(scriptMethod->getArgumentTypes()[0].type) || - className != scriptMethod->getArgumentTypes()[0].name) continue; - // + if (className != MiniScript::Variable::getTypeAsString(scriptMethod->getArgumentTypes()[0].type)) continue; // allMethods.insert(method); } // return allMethods; } -const vector Transpiler::getAllMethodNamesSorted(MiniScript* miniScript) { - auto allMethods = getAllMethodNames(miniScript); +const vector Transpiler::getAllClassesMethodNamesSorted(MiniScript* miniScript) { + auto allMethods = getAllClassesMethodNames(miniScript); // vector result; for (auto method: allMethods) result.push_back(method); @@ -60,22 +59,22 @@ const vector Transpiler::getAllMethodNamesSorted(MiniScript* miniScript) return result; } -const unordered_map> Transpiler::getAllClassesMethodNames(MiniScript* miniScript) { +const unordered_map> Transpiler::getClassesMethodNames(MiniScript* miniScript) { unordered_map> methodByClasses; for (auto scriptMethod: miniScript->getMethods()) { string className; - if (scriptMethod->getMethodName().rfind('.') != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind('.')); + if (scriptMethod->getMethodName().rfind("::") != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind("::")); + if (className.empty() == true) continue; string method = StringTools::substring( scriptMethod->getMethodName(), - className.empty() == true?0:className.size() + 1, + className.size() + 2, scriptMethod->getMethodName().size()); // first argument name of method must equal the name of the class if (scriptMethod->getArgumentTypes().empty() == true || - scriptMethod->getArgumentTypes()[0].name != className) continue; + scriptMethod->getArgumentTypes()[0].name != StringTools::toLowerCase(className)) continue; // first argument of method must be of type of the class - if (className != MiniScript::ScriptVariable::getClassName(scriptMethod->getArgumentTypes()[0].type) || - className != scriptMethod->getArgumentTypes()[0].name) continue; + if (className != MiniScript::Variable::getTypeAsString(scriptMethod->getArgumentTypes()[0].type)) continue; // methodByClasses[className].push_back(method); } @@ -236,8 +235,8 @@ void Transpiler::generateArrayAccessMethods( string& generatedDefinitions, const string& miniScriptClassName, const string& methodName, - const MiniScript::ScriptSyntaxTreeNode& syntaxTree, - const MiniScript::ScriptStatement& statement, + const MiniScript::SyntaxTreeNode& syntaxTree, + const MiniScript::Statement& statement, const unordered_map>& methodCodeMap, const unordered_set& allMethods, bool condition, @@ -249,11 +248,11 @@ void Transpiler::generateArrayAccessMethods( // switch (syntaxTree.type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { if (syntaxTree.value.getValueAsString() == "getVariable" || syntaxTree.value.getValueAsString() == "getVariableReference" || @@ -304,7 +303,7 @@ void Transpiler::generateArrayAccessMethods( continue; } // check if literal - MiniScript::ScriptVariable arrayAccessStatementAsScriptVariable; + MiniScript::Variable arrayAccessStatementAsScriptVariable; // arrayAccessStatementAsScriptVariable.setImplicitTypedValue(arrayAccessStatementString, miniScript, statement); switch (arrayAccessStatementAsScriptVariable.getType()) { @@ -317,8 +316,8 @@ void Transpiler::generateArrayAccessMethods( generatedDeclarations+= headerIndent + " * @param statement statement" + "\n"; generatedDeclarations+= headerIndent + " * @return array index" + "\n"; generatedDeclarations+= headerIndent + " */" + "\n"; - generatedDeclarations+= headerIndent + "inline ScriptVariable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const ScriptStatement& statement) {" + "\n"; - generatedDeclarations+= headerIndent + " return ScriptVariable(" + (booleanValue == true?"true":"false") + ");" + "\n"; + generatedDeclarations+= headerIndent + "inline Variable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const Statement& statement) {" + "\n"; + generatedDeclarations+= headerIndent + " return Variable(" + (booleanValue == true?"true":"false") + ");" + "\n"; generatedDeclarations+= headerIndent + "}" + "\n\n"; } // literals @@ -335,8 +334,8 @@ void Transpiler::generateArrayAccessMethods( generatedDeclarations+= headerIndent + " * @param statement statement" + "\n"; generatedDeclarations+= headerIndent + " * @return array index" + "\n"; generatedDeclarations+= headerIndent + " */" + "\n"; - generatedDeclarations+= headerIndent + "inline ScriptVariable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const ScriptStatement& statement) {" + "\n"; - generatedDeclarations+= headerIndent + " return ScriptVariable(static_cast(" + to_string(integerValue) + "ll));" + "\n"; + generatedDeclarations+= headerIndent + "inline Variable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const Statement& statement) {" + "\n"; + generatedDeclarations+= headerIndent + " return Variable(static_cast(" + to_string(integerValue) + "ll));" + "\n"; generatedDeclarations+= headerIndent + "}" + "\n\n"; } // literals @@ -353,8 +352,8 @@ void Transpiler::generateArrayAccessMethods( generatedDeclarations+= headerIndent + " * @param statement statement" + "\n"; generatedDeclarations+= headerIndent + " * @return array index" + "\n"; generatedDeclarations+= headerIndent + " */" + "\n"; - generatedDeclarations+= headerIndent + "inline ScriptVariable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const ScriptStatement& statement) {" + "\n"; - generatedDeclarations+= headerIndent + " return ScriptVariable(static_cast(" + to_string(static_cast(floatValue)) + "ll));" + "\n"; + generatedDeclarations+= headerIndent + "inline Variable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const Statement& statement) {" + "\n"; + generatedDeclarations+= headerIndent + " return Variable(static_cast(" + to_string(static_cast(floatValue)) + "ll));" + "\n"; generatedDeclarations+= headerIndent + "}" + "\n\n"; } // literals @@ -372,7 +371,7 @@ void Transpiler::generateArrayAccessMethods( vector arrayAccessArguments; string accessObjectMemberStatement; // create a pseudo statement (information) - MiniScript::ScriptStatement arrayAccessStatement( + MiniScript::Statement arrayAccessStatement( statement.line, statement.statementIdx, arrayAccessStatementString, @@ -380,12 +379,12 @@ void Transpiler::generateArrayAccessMethods( MiniScript::STATEMENTIDX_NONE ); // parse script statement - if (miniScript->parseScriptStatement(string_view(arrayAccessStatementString), arrayAccessMethodName, arrayAccessArguments, arrayAccessStatement, accessObjectMemberStatement) == false) { + if (miniScript->parseStatement(string_view(arrayAccessStatementString), arrayAccessMethodName, arrayAccessArguments, arrayAccessStatement, accessObjectMemberStatement) == false) { break; } // create syntax tree for this array access - MiniScript::ScriptSyntaxTreeNode arrayAccessSyntaxTree; - if (miniScript->createScriptStatementSyntaxTree(arrayAccessMethodName, arrayAccessArguments, arrayAccessStatement, arrayAccessSyntaxTree) == false) { + MiniScript::SyntaxTreeNode arrayAccessSyntaxTree; + if (miniScript->createStatementSyntaxTree(arrayAccessMethodName, arrayAccessArguments, arrayAccessStatement, arrayAccessSyntaxTree) == false) { break; } @@ -410,7 +409,7 @@ void Transpiler::generateArrayAccessMethods( enabledNamedConditions, 0, {}, - "ScriptVariable()", + "Variable()", "return returnValue;" ); generatedDeclarations+= headerIndent + "/**\n"; @@ -418,8 +417,8 @@ void Transpiler::generateArrayAccessMethods( generatedDeclarations+= headerIndent + " * @param statement statement" + "\n"; generatedDeclarations+= headerIndent + " * @return array index" + "\n"; generatedDeclarations+= headerIndent + " */" + "\n"; - generatedDeclarations+= headerIndent + "ScriptVariable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const ScriptStatement& statement);" + "\n\n"; - generatedDefinitions+= string() + "inline MiniScript::ScriptVariable " + miniScriptClassName + "::" + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const ScriptStatement& statement) {" + "\n"; + generatedDeclarations+= headerIndent + "Variable " + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const Statement& statement);" + "\n\n"; + generatedDefinitions+= string() + "inline MiniScript::Variable " + miniScriptClassName + "::" + methodName + "_array_access_statement_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(nextArgumentIndices, "_") + "_" + to_string(arrayAccessStatementIdx) + "(const Statement& statement) {" + "\n"; generatedDefinitions+= string() + " // Miniscript setup" + "\n"; generatedDefinitions+= string() + " auto miniScript = this;" + "\n"; generatedDefinitions+= string() + " //" + "\n";; @@ -458,7 +457,7 @@ void Transpiler::generateArrayAccessMethods( } } break; - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { auto argumentIdx = 1; for (const auto& argument: syntaxTree.arguments) { @@ -498,8 +497,8 @@ void Transpiler::generateMiniScriptEvaluateMemberAccessArrays( ) { // auto scriptMethods = miniScript->getMethods(); - auto allMethods = Transpiler::getAllMethodNamesSorted(miniScript); - auto methodsByClasses = Transpiler::getAllClassesMethodNames(miniScript); + auto allMethods = Transpiler::getAllClassesMethodNamesSorted(miniScript); + auto methodsByClasses = Transpiler::getClassesMethodNames(miniScript); generatedDeclarations.push_back("// evaluate member access constants"); generatedDeclarations.push_back("static constexpr int EVALUATEMEMBERACCESSARRAYIDX_NONE { -1 };"); auto methodIdx = 0; @@ -510,7 +509,7 @@ void Transpiler::generateMiniScriptEvaluateMemberAccessArrays( generatedDeclarations.push_back(""); generatedDeclarations.push_back("// evaluate member access arrays"); generatedDeclarations.push_back( - "array, " + to_string((static_cast(MiniScript::TYPE_PSEUDO_CUSTOM_DATATYPES + MiniScript::getDataTypes().size()) - static_cast(MiniScript::TYPE_STRING))) + @@ -519,7 +518,7 @@ void Transpiler::generateMiniScriptEvaluateMemberAccessArrays( generatedDeclarations.push_back("// evaluate member access arrays"); generatedDefinitions.push_back("evaluateMemberAccessArrays = {};"); for (auto typeIdx = static_cast(MiniScript::TYPE_STRING); typeIdx < static_cast(MiniScript::TYPE_PSEUDO_CUSTOM_DATATYPES + MiniScript::getDataTypes().size()); typeIdx++) { - const auto& className = MiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& className = MiniScript::Variable::getTypeAsString(static_cast(typeIdx)); const auto& methods = methodsByClasses[className]; auto methodIdx = 0; for (const auto& method: allMethods) { @@ -529,7 +528,7 @@ void Transpiler::generateMiniScriptEvaluateMemberAccessArrays( continue; } // - generatedDefinitions.push_back("evaluateMemberAccessArrays[" + to_string(typeIdx - static_cast(MiniScript::TYPE_STRING)) + "][" + "EVALUATEMEMBERACCESSARRAYIDX_" + StringTools::toUpperCase(method) + "] = getMethod(\"" + className + "." + method + "\");"); + generatedDefinitions.push_back("evaluateMemberAccessArrays[" + to_string(typeIdx - static_cast(MiniScript::TYPE_STRING)) + "][" + "EVALUATEMEMBERACCESSARRAYIDX_" + StringTools::toUpperCase(method) + "] = getMethod(\"" + className + "::" + method + "\");"); methodIdx++; } } @@ -537,7 +536,7 @@ void Transpiler::generateMiniScriptEvaluateMemberAccessArrays( void Transpiler::generateArrayMapSetVariable( MiniScript* miniScript, - const MiniScript::ScriptVariable& variable, + const MiniScript::Variable& variable, const unordered_map>& methodCodeMap, const unordered_set& allMethods, const string& methodName, @@ -556,7 +555,7 @@ void Transpiler::generateArrayMapSetVariable( case MiniScript::TYPE_NULL: { generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + ";" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + ";" + "\n"; generatedDefinitions+= indent + "\t" + postStatement + "\n"; generatedDefinitions+= indent + "}" + "\n"; } @@ -566,7 +565,7 @@ void Transpiler::generateArrayMapSetVariable( bool value; variable.getBooleanValue(value); generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + "(" + (value == true?"true":"false") + ");" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + "(" + (value == true?"true":"false") + ");" + "\n"; generatedDefinitions+= indent + "\t" + postStatement + "\n"; generatedDefinitions+= indent + "}" + "\n"; } @@ -576,7 +575,7 @@ void Transpiler::generateArrayMapSetVariable( int64_t value; variable.getIntegerValue(value); generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + "(static_cast(" + to_string(value) + "ll));" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + "(static_cast(" + to_string(value) + "ll));" + "\n"; generatedDefinitions+= indent + "\t" + postStatement + "\n"; generatedDefinitions+= indent + "}" + "\n"; } @@ -586,7 +585,7 @@ void Transpiler::generateArrayMapSetVariable( float value; variable.getFloatValue(value); generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + "(" + to_string(value) + "f);" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + "(" + to_string(value) + "f);" + "\n"; generatedDefinitions+= indent + "\t" + postStatement + "\n"; generatedDefinitions+= indent + "}" + "\n"; } @@ -615,7 +614,7 @@ void Transpiler::generateArrayMapSetVariable( enabledNamedConditions, 0, {}, - "ScriptVariable()", + "Variable()", "const auto& variableD" + to_string(initializerDepth) + " = returnValue; " + postStatement + "\n", 1 ); generatedDefinitions+= transpiledCode; @@ -628,7 +627,7 @@ void Transpiler::generateArrayMapSetVariable( value = StringTools::replace(StringTools::replace(value, "\\", "\\\\"), "\"", "\\\""); // generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + ";" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + ";" + "\n"; generatedDefinitions+= indent + "\t" + "variableD" + to_string(initializerDepth) + ".setFunctionAssignment(\"" + value + "\");" + "\n"; generatedDefinitions+= indent + "\t" + postStatement + "\n"; generatedDefinitions+= indent + "}" + "\n"; @@ -641,7 +640,7 @@ void Transpiler::generateArrayMapSetVariable( value = StringTools::replace(StringTools::replace(value, "\\", "\\\\"), "\"", "\\\""); // generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + "(string(\"" + value + "\"));" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + "(string(\"" + value + "\"));" + "\n"; generatedDefinitions+= indent + "\t" + postStatement + "\n"; generatedDefinitions+= indent + "}" + "\n"; } @@ -649,7 +648,7 @@ void Transpiler::generateArrayMapSetVariable( case MiniScript::TYPE_ARRAY: { generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + ";" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + ";" + "\n"; generatedDefinitions+= indent + "\t" + "variableD" + to_string(initializerDepth) + ".setType(TYPE_ARRAY);" + "\n"; const auto arrayValue = variable.getArrayPointer(); for (const auto arrayEntry: *arrayValue) { @@ -675,7 +674,7 @@ void Transpiler::generateArrayMapSetVariable( case MiniScript::TYPE_MAP: { generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + ";" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + ";" + "\n"; generatedDefinitions+= indent + "\t" + "variableD" + to_string(initializerDepth) + ".setType(TYPE_MAP);" + "\n"; const auto mapValue = variable.getMapPointer(); for (const auto& [mapEntryName, mapEntryValue]: *mapValue) { @@ -702,7 +701,7 @@ void Transpiler::generateArrayMapSetVariable( case MiniScript::TYPE_SET: { generatedDefinitions+= indent + "{" + "\n"; - generatedDefinitions+= indent + "\t" + "ScriptVariable variableD" + to_string(initializerDepth) + ";" + "\n"; + generatedDefinitions+= indent + "\t" + "Variable variableD" + to_string(initializerDepth) + ";" + "\n"; generatedDefinitions+= indent + "\t" + "variableD" + to_string(initializerDepth) + ".setType(TYPE_SET);" + "\n"; const auto setValue = variable.getSetPointer(); for (const auto& key: *setValue) { @@ -722,8 +721,8 @@ void Transpiler::generateArrayMapSetInitializer( string& generatedDefinitions, const string& miniScriptClassName, const string& methodName, - const MiniScript::ScriptSyntaxTreeNode& syntaxTree, - const MiniScript::ScriptStatement& statement, + const MiniScript::SyntaxTreeNode& syntaxTree, + const MiniScript::Statement& statement, const unordered_map>& methodCodeMap, const unordered_set& allMethods, bool condition, @@ -735,7 +734,7 @@ void Transpiler::generateArrayMapSetInitializer( // switch (syntaxTree.type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { switch(syntaxTree.value.getType()) { case MiniScript::TYPE_ARRAY: @@ -747,7 +746,7 @@ void Transpiler::generateArrayMapSetInitializer( generatedDeclarations+= headerIndent + " * @param statement statement" + "\n"; generatedDeclarations+= headerIndent + " * @return initialized variable" + "\n"; generatedDeclarations+= headerIndent + " */" + "\n"; - generatedDeclarations+= headerIndent + "ScriptVariable " + methodName + "_initializer_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(argumentIndices, "_") + "(const ScriptStatement& statement);" + "\n\n"; + generatedDeclarations+= headerIndent + "Variable " + methodName + "_initializer_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(argumentIndices, "_") + "(const Statement& statement);" + "\n\n"; // string generatedInitializerDeclarations; string generatedInitializerDefinitions; @@ -768,7 +767,7 @@ void Transpiler::generateArrayMapSetInitializer( ); // generatedDefinitions+= "\n"; - generatedDefinitions+= string() + "inline MiniScript::ScriptVariable " + miniScriptClassName + "::" + methodName + "_initializer_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(argumentIndices, "_") + "(const ScriptStatement& statement) {" + "\n"; + generatedDefinitions+= string() + "inline MiniScript::Variable " + miniScriptClassName + "::" + methodName + "_initializer_" + (condition == true?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + MiniScript::getArgumentIndicesAsString(argumentIndices, "_") + "(const Statement& statement) {" + "\n"; generatedDefinitions+= string() + " // Miniscript setup" + "\n"; generatedDefinitions+= string() + " auto miniScript = this;" + "\n"; generatedDefinitions+= string() + " //" + "\n";; @@ -782,7 +781,7 @@ void Transpiler::generateArrayMapSetInitializer( // break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { auto argumentIdx = 0; for (const auto& argument: syntaxTree.arguments) { @@ -809,7 +808,7 @@ void Transpiler::generateArrayMapSetInitializer( } break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { auto argumentIdx = 1; // TODO: check me! for (const auto& argument: syntaxTree.arguments) { @@ -845,8 +844,8 @@ void Transpiler::generateArrayMapSetInitializer( bool Transpiler::transpileScriptStatement( MiniScript* miniScript, string& generatedCode, - const MiniScript::ScriptSyntaxTreeNode& syntaxTree, - const MiniScript::ScriptStatement& statement, + const MiniScript::SyntaxTreeNode& syntaxTree, + const MiniScript::Statement& statement, int scriptConditionIdx, int scriptIdx, int& statementIdx, @@ -896,18 +895,18 @@ bool Transpiler::transpileScriptStatement( // switch (syntaxTree.type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { // check script user functions - auto scriptFunctionsIdx = miniScript->getFunctionScriptIdx(syntaxTree.value.getValueAsString()); - if (scriptFunctionsIdx != MiniScript::SCRIPTIDX_NONE) { + auto functionsIdx = syntaxTree.getFunctionScriptIdx(); + if (functionsIdx != MiniScript::SCRIPTIDX_NONE) { // have a wrapping script.call call - MiniScript::ScriptSyntaxTreeNode callSyntaxTreeNode; - callSyntaxTreeNode.type = MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD; + MiniScript::SyntaxTreeNode callSyntaxTreeNode; + callSyntaxTreeNode.type = MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD; callSyntaxTreeNode.value = MiniScript::METHOD_SCRIPTCALL; // construct argument for name of function - MiniScript::ScriptSyntaxTreeNode callArgumentSyntaxTreeNode; - callArgumentSyntaxTreeNode.type = MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + MiniScript::SyntaxTreeNode callArgumentSyntaxTreeNode; + callArgumentSyntaxTreeNode.type = MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; callArgumentSyntaxTreeNode.value = syntaxTree.value; // add argumnet for name of function callSyntaxTreeNode.arguments.push_back(callArgumentSyntaxTreeNode); @@ -921,7 +920,7 @@ bool Transpiler::transpileScriptStatement( Console::println("Transpiler::transpileScriptStatement(): method code not found: '" + callSyntaxTreeNode.value.getValueAsString() + "'"); return false; } - callSyntaxTreeNode.method = method; + callSyntaxTreeNode.setMethod(method); return transpileScriptStatement( miniScript, generatedCode, @@ -948,7 +947,7 @@ bool Transpiler::transpileScriptStatement( // break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: // if ((scriptConditionIdx != MiniScript::SCRIPTIDX_NONE || scriptIdx != MiniScript::SCRIPTIDX_NONE) && @@ -1074,23 +1073,23 @@ bool Transpiler::transpileScriptStatement( if (depth == 0) { generatedCode+= minIndentString + depthIndentString + "\t" + "// statement setup" + "\n"; if (scriptConditionIdx != MiniScript::SCRIPTIDX_NONE) { - generatedCode+= minIndentString + depthIndentString + "\t" + "const ScriptStatement& statement = scripts[" + to_string(scriptConditionIdx) + "].conditionStatement;" + "\n"; + generatedCode+= minIndentString + depthIndentString + "\t" + "const auto& statement = scripts[" + to_string(scriptConditionIdx) + "].conditionStatement;" + "\n"; } else if (scriptIdx != MiniScript::SCRIPTIDX_NONE) { - generatedCode+= minIndentString + depthIndentString + "\t" + "const ScriptStatement& statement = scripts[" + to_string(scriptIdx) + "].statements[" + to_string(statement.statementIdx) + "];" + "\n"; + generatedCode+= minIndentString + depthIndentString + "\t" + "const auto& statement = scripts[" + to_string(scriptIdx) + "].statements[" + to_string(statement.statementIdx) + "];" + "\n"; } generatedCode+= minIndentString + depthIndentString + "\t" + "getScriptState().statementIdx = statement.statementIdx;" + "\n"; } // construct argument values { - vector argumentValuesCode; + vector argumentsCode; if (depth > 0) { - argumentValuesCode.push_back("ScriptVariable& returnValue = argumentValuesD" + to_string(depth - 1) + (parentArgumentIdx != MiniScript::ARGUMENTIDX_NONE?"AIDX" + to_string(parentArgumentIdx):"") + "[" + to_string(argumentIdx) + "];"); + argumentsCode.push_back("auto& returnValue = argumentsD" + to_string(depth - 1) + (parentArgumentIdx != MiniScript::ARGUMENTIDX_NONE?"AIDX" + to_string(parentArgumentIdx):"") + "[" + to_string(argumentIdx) + "];"); } else { - argumentValuesCode.push_back("ScriptVariable returnValue;"); + argumentsCode.push_back("Variable returnValue;"); } - argumentValuesCode.push_back("array argumentValues {"); + argumentsCode.push_back("array arguments {"); // construct argument values if (syntaxTree.arguments.empty() == false) { @@ -1103,34 +1102,35 @@ bool Transpiler::transpileScriptStatement( // auto lastArgument = argumentIdx == syntaxTree.arguments.size() - 1; switch (argument.type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { switch (argument.value.getType()) { case MiniScript::TYPE_NULL: - argumentValuesCode.push_back(string() + "\t" + "ScriptVariable()" + (lastArgument == false?",":"")); + argumentsCode.push_back(string() + "\t" + "Variable()" + (lastArgument == false?",":"")); break; case MiniScript::TYPE_BOOLEAN: { bool value; argument.value.getBooleanValue(value); - argumentValuesCode.push_back(string() + "\t" + "ScriptVariable(" + (value == true?"true":"false") + ")" + (lastArgument == false?",":"")); + argumentsCode.push_back(string() + "\t" + "Variable(" + (value == true?"true":"false") + ")" + (lastArgument == false?",":"")); } break; case MiniScript::TYPE_INTEGER: { int64_t value; argument.value.getIntegerValue(value); - argumentValuesCode.push_back(string() + "\t" + + "ScriptVariable(static_cast(" + to_string(value) + "ll))" + (lastArgument == false?",":"")); + argumentsCode.push_back(string() + "\t" + + "Variable(static_cast(" + to_string(value) + "ll))" + (lastArgument == false?",":"")); } break; case MiniScript::TYPE_FLOAT: { float value; argument.value.getFloatValue(value); - argumentValuesCode.push_back(string() + "\t" + + "ScriptVariable(" + to_string(value) + "f)" + (lastArgument == false?",":"")); + argumentsCode.push_back(string() + "\t" + + "Variable(" + to_string(value) + "f)" + (lastArgument == false?",":"")); } break; case MiniScript::TYPE_STRING: + case MiniScript::TYPE_FUNCTION_ASSIGNMENT: { string value; argument.value.getStringValue(value); @@ -1147,7 +1147,7 @@ bool Transpiler::transpileScriptStatement( arrayAccessStatementOffset-= (arrayAccessStatement.rightIdx - (arrayAccessStatement.leftIdx + 1)) - arrayAccessStatementMethodCall.size(); } // - argumentValuesCode.push_back(string() + "\t" + + "ScriptVariable(string(\"" + value + "\"))" + (lastArgument == false?",":"")); + argumentsCode.push_back(string() + "\t" + + "Variable(string(\"" + value + "\"))" + (lastArgument == false?",":"")); } break; case MiniScript::TYPE_ARRAY: @@ -1168,7 +1168,7 @@ bool Transpiler::transpileScriptStatement( ); // auto initializerMethod = methodName + "_initializer_" + (scriptConditionIdx != MiniScript::SCRIPTIDX_NONE?"c":"s") + "_" + to_string(statement.statementIdx) + "_" + miniScript->getArgumentIndicesAsString(nextArgumentIndices, "_"); - argumentValuesCode.push_back(string() + "\t" + initializerMethod + "(statement)" + (lastArgument == false?",":"")); + argumentsCode.push_back(string() + "\t" + initializerMethod + "(statement)" + (lastArgument == false?",":"")); } break; default: @@ -1179,14 +1179,14 @@ bool Transpiler::transpileScriptStatement( } break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { - argumentValuesCode.push_back(string() + "\t" + "ScriptVariable()" + (lastArgument == false?",":"") + " // argumentValues[" + to_string(argumentIdx) + "] --> returnValue of " + argument.value.getValueAsString() + "(" + miniScript->getArgumentsAsString(argument.arguments) + ")"); + argumentsCode.push_back(string() + "\t" + "Variable()" + (lastArgument == false?",":"") + " // arguments[" + to_string(argumentIdx) + "] --> returnValue of " + argument.value.getValueAsString() + "(" + miniScript->getArgumentsAsString(argument.arguments) + ")"); break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { - argumentValuesCode.push_back(string() + "\t" + "ScriptVariable()" + (lastArgument == false?",":"") + " // argumentValues[" + to_string(argumentIdx) + "] --> returnValue of " + argument.value.getValueAsString() + "(" + miniScript->getArgumentsAsString(argument.arguments) + ")"); + argumentsCode.push_back(string() + "\t" + "Variable()" + (lastArgument == false?",":"") + " // arguments[" + to_string(argumentIdx) + "] --> returnValue of " + argument.value.getValueAsString() + "(" + miniScript->getArgumentsAsString(argument.arguments) + ")"); break; } default: @@ -1197,13 +1197,13 @@ bool Transpiler::transpileScriptStatement( } } // end of arguments initialization - argumentValuesCode.push_back("};"); + argumentsCode.push_back("};"); // - argumentValuesCode.push_back("array& argumentValuesD" + to_string(depth) + (argumentIdx != MiniScript::ARGUMENTIDX_NONE?"AIDX" + to_string(argumentIdx):"") + " = argumentValues;"); + argumentsCode.push_back("array& argumentsD" + to_string(depth) + (argumentIdx != MiniScript::ARGUMENTIDX_NONE?"AIDX" + to_string(argumentIdx):"") + " = arguments;"); // argument values header - for (const auto& codeLine: argumentValuesCode) { + for (const auto& codeLine: argumentsCode) { generatedCode+= minIndentString + depthIndentString + "\t" + codeLine + "\n"; } } @@ -1246,8 +1246,8 @@ bool Transpiler::transpileScriptStatement( auto argumentIdx = 0; for (const auto& argument: syntaxTree.arguments) { switch (argument.type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: { // auto nextArgumentIndices = argumentIndices; @@ -1399,7 +1399,7 @@ bool Transpiler::transpile(MiniScript* miniScript, string& generatedCode, int sc // unordered_set gotoStatementIdxSet; - for (const auto& scriptStatement: script.statements) gotoStatementIdxSet.insert(scriptStatement.gotoStatementIdx); + for (const auto& statement: script.statements) gotoStatementIdxSet.insert(statement.gotoStatementIdx); // auto statementIdx = MiniScript::STATEMENTIDX_FIRST; @@ -1515,11 +1515,11 @@ bool Transpiler::transpileScriptCondition(MiniScript* miniScript, string& genera return true; } -const string Transpiler::createSourceCode(const MiniScript::ScriptSyntaxTreeNode& syntaxTreeNode) { +const string Transpiler::createSourceCode(const MiniScript::SyntaxTreeNode& syntaxTreeNode) { // string result; switch (syntaxTreeNode.type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: { switch(syntaxTreeNode.value.getType()) { case MiniScript::TYPE_NULL: @@ -1547,8 +1547,8 @@ const string Transpiler::createSourceCode(const MiniScript::ScriptSyntaxTreeNode } break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { auto endElse = syntaxTreeNode.value.getValueAsString() == "end" || syntaxTreeNode.value.getValueAsString() == "else"; result+= syntaxTreeNode.value.getValueAsString(); @@ -1568,7 +1568,7 @@ const string Transpiler::createSourceCode(const MiniScript::ScriptSyntaxTreeNode return result; } -const string Transpiler::createSourceCode(MiniScript::Script::ScriptType scriptType, const string& condition, const vector& arguments, const string& name, const MiniScript::ScriptSyntaxTreeNode& conditionSyntaxTree, const vector& syntaxTree) { +const string Transpiler::createSourceCode(MiniScript::Script::ScriptType scriptType, const string& condition, const vector& functionArguments, const string& name, const MiniScript::SyntaxTreeNode& conditionSyntaxTree, const vector& syntaxTree) { // string result; // @@ -1580,7 +1580,7 @@ const string Transpiler::createSourceCode(MiniScript::Script::ScriptType scriptT } auto argumentIdx = 0; result+= "("; - for (const auto& argument: arguments) { + for (const auto& argument: functionArguments) { if (argumentIdx > 0) result+= ", "; if (argument.reference == true) result+= "="; result+= argument.name; @@ -1605,7 +1605,7 @@ const string Transpiler::createSourceCode(MiniScript::Script::ScriptType scriptT } } } - if (conditionSyntaxTree.type != MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE) + if (conditionSyntaxTree.type != MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE) result+= createSourceCode(conditionSyntaxTree); if (name.empty() == false) { result+= " := " + name + "\n"; @@ -1615,7 +1615,7 @@ const string Transpiler::createSourceCode(MiniScript::Script::ScriptType scriptT // auto indent = 1; for (const auto& syntaxTreeNode: syntaxTree) { - if (syntaxTreeNode.type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD) { + if (syntaxTreeNode.type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD) { if (syntaxTreeNode.value.getValueAsString() == "if") indent+= 0; else if (syntaxTreeNode.value.getValueAsString() == "elseif") indent-= 1; else if (syntaxTreeNode.value.getValueAsString() == "else") indent-= 1; else @@ -1625,7 +1625,7 @@ const string Transpiler::createSourceCode(MiniScript::Script::ScriptType scriptT } for (auto i = 0; i < indent; i++) result+= "\t"; result+= createSourceCode(syntaxTreeNode) + "\n"; - if (syntaxTreeNode.type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD) { + if (syntaxTreeNode.type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD) { if (syntaxTreeNode.value.getValueAsString() == "if") indent+= 1; else if (syntaxTreeNode.value.getValueAsString() == "elseif") indent+= 1; else if (syntaxTreeNode.value.getValueAsString() == "else") indent+= 1; else @@ -1641,7 +1641,7 @@ const string Transpiler::createSourceCode(MiniScript* miniScript) { string result; // create source code for (const auto& script: miniScript->getScripts()) { - result+= createSourceCode(script.scriptType, script.emitCondition == true?script.condition:string(), script.arguments, script.name, script.conditionSyntaxTree, script.syntaxTree); + result+= createSourceCode(script.scriptType, script.emitCondition == true?script.condition:string(), script.functionArguments, script.name, script.conditionSyntaxTree, script.syntaxTree); } // return result; diff --git a/ext/miniscript/src/miniscript/miniscript/Transpiler.h b/ext/miniscript/src/miniscript/miniscript/Transpiler.h index b79f0f1bf..1b935946a 100644 --- a/ext/miniscript/src/miniscript/miniscript/Transpiler.h +++ b/ext/miniscript/src/miniscript/miniscript/Transpiler.h @@ -22,25 +22,25 @@ class miniscript::miniscript::Transpiler { public: /** - * Get all method names + * Get all classes method names * @param miniScript MiniScript instance - * @return all method names + * @return all classes method names */ - static const unordered_set getAllMethodNames(MiniScript* miniScript); + static const unordered_set getAllClassesMethodNames(MiniScript* miniScript); /** - * Get all method names sorted + * Get all classes method names sorted * @param miniScript MiniScript instance - * @return all method names sorted + * @return all classes method names sorted */ - static const vector getAllMethodNamesSorted(MiniScript* miniScript); + static const vector getAllClassesMethodNamesSorted(MiniScript* miniScript); /** - * Get all method names by class name + * Get method names per classes * @param miniScript MiniScript instance - * @return all method names + * @return method names per classes */ - static const unordered_map> getAllClassesMethodNames(MiniScript* miniScript); + static const unordered_map> getClassesMethodNames(MiniScript* miniScript); /** * Gather method code @@ -77,8 +77,8 @@ class miniscript::miniscript::Transpiler { string& generatedDefinitions, const string& miniScriptClassName, const string& methodName, - const MiniScript::ScriptSyntaxTreeNode& syntaxTree, - const MiniScript::ScriptStatement& statement, + const MiniScript::SyntaxTreeNode& syntaxTree, + const MiniScript::Statement& statement, const unordered_map>& methodCodeMap, const unordered_set& allMethods, bool condition, @@ -115,7 +115,7 @@ class miniscript::miniscript::Transpiler { */ static void generateArrayMapSetVariable( MiniScript* miniScript, - const MiniScript::ScriptVariable& variable, + const MiniScript::Variable& variable, const unordered_map>& methodCodeMap, const unordered_set& allMethods, const string& methodName, @@ -149,8 +149,8 @@ class miniscript::miniscript::Transpiler { string& generatedDefinitions, const string& miniScriptClassName, const string& methodName, - const MiniScript::ScriptSyntaxTreeNode& syntaxTree, - const MiniScript::ScriptStatement& statement, + const MiniScript::SyntaxTreeNode& syntaxTree, + const MiniScript::Statement& statement, const unordered_map>& methodCodeMap, const unordered_set& allMethods, bool condition, @@ -181,8 +181,8 @@ class miniscript::miniscript::Transpiler { static bool transpileScriptStatement( MiniScript* miniScript, string& generatedCode, - const MiniScript::ScriptSyntaxTreeNode& syntaxTree, - const MiniScript::ScriptStatement& statement, + const MiniScript::SyntaxTreeNode& syntaxTree, + const MiniScript::Statement& statement, int scriptConditionIdx, int scriptIdx, int& statementIdx, @@ -241,13 +241,13 @@ class miniscript::miniscript::Transpiler { * Create source code for given syntax tree node * @param syntaxTreeNode syntax tree node */ - static const string createSourceCode(const MiniScript::ScriptSyntaxTreeNode& syntaxTreeNode); + static const string createSourceCode(const MiniScript::SyntaxTreeNode& syntaxTreeNode); /** * Create source code for given syntax tree * @param scriptType script type * @param condition condition - * @param arguments function arguments + * @param functionArguments function arguments * @param name name of named conditions * @param conditionSyntaxTree condition syntax tree * @param syntaxTree syntax tree @@ -255,10 +255,10 @@ class miniscript::miniscript::Transpiler { static const string createSourceCode( MiniScript::Script::ScriptType scriptType, const string& condition, - const vector& arguments, + const vector& functionArguments, const string& name, - const MiniScript::ScriptSyntaxTreeNode& conditionSyntaxTree, - const vector& syntaxTree + const MiniScript::SyntaxTreeNode& conditionSyntaxTree, + const vector& syntaxTree ); /** diff --git a/ext/miniscript/src/miniscript/miniscript/Version.cpp b/ext/miniscript/src/miniscript/miniscript/Version.cpp index 8b5b05521..34d6c6f1e 100644 --- a/ext/miniscript/src/miniscript/miniscript/Version.cpp +++ b/ext/miniscript/src/miniscript/miniscript/Version.cpp @@ -9,7 +9,7 @@ using std::string; using miniscript::miniscript::Version; string Version::getVersion() { - return "0.9.5 PRE-BETA"; + return "0.9.10 PRE-BETA"; } string Version::getCopyright() { diff --git a/ext/miniscript/src/miniscript/miniscript/XMLMethods.cpp b/ext/miniscript/src/miniscript/miniscript/XMLMethods.cpp index 2aa61da14..a77c7d3cb 100644 --- a/ext/miniscript/src/miniscript/miniscript/XMLMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/XMLMethods.cpp @@ -18,12 +18,12 @@ void XMLMethods::registerMethods(MiniScript* miniScript) { // xml { // - class ScriptMethodXMLCreateTag: public MiniScript::ScriptMethod { + class MethodXMLCreateTag: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: - ScriptMethodXMLCreateTag(MiniScript* miniScript): - MiniScript::ScriptMethod( + MethodXMLCreateTag(MiniScript* miniScript): + MiniScript::Method( { { .type = MiniScript::TYPE_STRING, .name = "name", .optional = false, .reference = false, .nullable = false }, { .type = MiniScript::TYPE_MAP, .name = "attributes", .optional = true, .reference = false, .nullable = false }, @@ -35,17 +35,17 @@ void XMLMethods::registerMethods(MiniScript* miniScript) { const string getMethodName() override { return "xml.createTag"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { // string name; string innerXML; - if (MiniScript::getStringValue(argumentValues, 0, name, false) == false || - (argumentValues.size() >= 2 && argumentValues[1].getType() != MiniScript::TYPE_MAP) || - MiniScript::getStringValue(argumentValues, 2, innerXML, true) == false) { + if (MiniScript::getStringValue(arguments, 0, name, false) == false || + (arguments.size() >= 2 && arguments[1].getType() != MiniScript::TYPE_MAP) || + MiniScript::getStringValue(arguments, 2, innerXML, true) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto mapPtr = argumentValues[1].getMapPointer(); + auto mapPtr = arguments[1].getMapPointer(); string xml; xml+= "<" + name; if (mapPtr != nullptr && mapPtr->empty() == false) { @@ -63,7 +63,7 @@ void XMLMethods::registerMethods(MiniScript* miniScript) { } } }; - miniScript->registerMethod(new ScriptMethodXMLCreateTag(miniScript)); + miniScript->registerMethod(new MethodXMLCreateTag(miniScript)); } } diff --git a/ext/miniscript/src/miniscript/network/httpclient/HTTPClient.cpp b/ext/miniscript/src/miniscript/network/httpclient/HTTPClient.cpp index 3ee86f812..72deab8ee 100644 --- a/ext/miniscript/src/miniscript/network/httpclient/HTTPClient.cpp +++ b/ext/miniscript/src/miniscript/network/httpclient/HTTPClient.cpp @@ -227,7 +227,7 @@ void HTTPClient::execute() { // socket->shutdown(); } catch (Exception& exception) { - socket->shutdown(); + if (socket != nullptr) socket->shutdown(); // Console::println(string("HTTPClient::execute(): performed HTTP request: FAILED: ") + exception.what()); // rethrow diff --git a/ext/miniscript/src/miniscript/network/httpclient/HTTPDownloadClient.cpp b/ext/miniscript/src/miniscript/network/httpclient/HTTPDownloadClient.cpp index 93054dc18..e701398cd 100644 --- a/ext/miniscript/src/miniscript/network/httpclient/HTTPDownloadClient.cpp +++ b/ext/miniscript/src/miniscript/network/httpclient/HTTPDownloadClient.cpp @@ -316,7 +316,7 @@ void HTTPDownloadClient::start() { downloadClient->finished = true; downloadClient->progress = 1.0f; } catch (Exception& exception) { - socket->shutdown(); + if (socket != nullptr) socket->shutdown(); downloadClient->finished = true; Console::println(string("HTTPDownloadClient::execute(): performed HTTP request: FAILED: ") + exception.what()); } diff --git a/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.cpp b/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.cpp index ce9fac0c9..af7944171 100644 --- a/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.cpp +++ b/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.cpp @@ -7,8 +7,6 @@ #include #include #include -#include -#include #ifndef OPENSSL_NO_CT #include #endif diff --git a/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.h b/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.h index d5d0b5f62..c158438e2 100644 --- a/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.h +++ b/ext/miniscript/src/miniscript/os/network/SecureTCPSocket.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/ext/miniscript/src/miniscript/tools/miniscript-main.cpp b/ext/miniscript/src/miniscript/tools/miniscript-main.cpp index 9a4f845c1..954d5604d 100644 --- a/ext/miniscript/src/miniscript/tools/miniscript-main.cpp +++ b/ext/miniscript/src/miniscript/tools/miniscript-main.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include @@ -14,10 +16,14 @@ #include #include #include +#include +#include +using std::cin; using std::exit; using std::make_unique; using std::string; +using std::tmpnam; using std::unique_ptr; using miniscript::miniscript::Context; @@ -26,12 +32,17 @@ using miniscript::miniscript::Version; using miniscript::os::filesystem::FileSystem; using miniscript::os::network::Network; using miniscript::utilities::Console; +using miniscript::utilities::Exception; +using miniscript::utilities::StringTools; static void printInformation() { Console::println(string("miniscript ") + Version::getVersion()); Console::println(Version::getCopyright()); Console::println(); - Console::println("Usage: miniscript [--version] [--verbose] path_to_script"); + Console::println("Usage: miniscript [--version] [--verbose] [path_to_script | < path_to_script]"); + Console::println(); + Console::println("If you do not provide a path to the script or do not pipe a script into the standard input stream,"); + Console::println("you get a prompt to enter your script. You can finish inputting by hitting Ctrl-D on Unix or Ctrl-Z on Windows."); exit(EXIT_FAILURE); } @@ -73,8 +84,48 @@ int main(int argc, char** argv) // EngineMiniScript::registerDataTypes(); unique_ptr script; unique_ptr context; + // if no file given, then read from input stream until Ctrl+D(Unix) or Ctrl+Z(Windows) was hit + // which is the standard behaviour of those kind of CLI apps + // we store the file as temporary one and reuse it for execution + string tmpFile; + if (pathToScript.empty() == true) { + // read from standard input + auto statementsOnly = true; + string scriptCode; + string line; + while (cin.eof() == false && getline(cin, line)) { + if (StringTools::startsWith(line, "on:") == true || + StringTools::startsWith(line, "on-enabled:") == true || + StringTools::startsWith(line, "function:") == true || + StringTools::startsWith(line, "callable:") == true) statementsOnly = false; + scriptCode+= line + "\n"; + } + pathToScript = tmpnam(nullptr); + // create the script + try { + if (statementsOnly == true) { + scriptCode = StringTools::replace( + FileSystem::getContentAsString("resources/templates/cli", "statements.tscript"), + "{$statements}", + scriptCode + ); + } + // + FileSystem::setContentFromString( + FileSystem::getPathName(pathToScript), + FileSystem::getFileName(pathToScript), + scriptCode + ); + // we want to delete the script later + tmpFile = pathToScript; + } catch (Exception& exception) { + pathToScript.clear(); + Console::println("An error occurred: " + string(exception.what())); + } + } + // do we have a script to run? if (pathToScript.empty() == false) { - // + // yes, go context = make_unique(); script = make_unique(); script->setContext(context.get()); @@ -110,6 +161,19 @@ int main(int argc, char** argv) exit(EXIT_SUCCESS); } + // delete temporary file if we have created any + if (tmpFile.empty() == false) { + try { + FileSystem::removeFile( + FileSystem::getPathName(tmpFile), + FileSystem::getFileName(tmpFile) + ); + } catch (Exception& exception) { + pathToScript.clear(); + Console::println("An error occurred: " + string(exception.what())); + } + } + // exit(script == nullptr || script->isValid() == false?EXIT_FAILURE:EXIT_SUCCESS); } diff --git a/ext/miniscript/src/miniscript/tools/miniscriptdocumentation-main.cpp b/ext/miniscript/src/miniscript/tools/miniscriptdocumentation-main.cpp index 547c477be..979c13c69 100644 --- a/ext/miniscript/src/miniscript/tools/miniscriptdocumentation-main.cpp +++ b/ext/miniscript/src/miniscript/tools/miniscriptdocumentation-main.cpp @@ -39,7 +39,7 @@ namespace tools { namespace cli { class MiniscriptDocumentation { public: -static void generateMiniScriptMethodsDocumentation(const string& heading, int mainHeadingIdx, MiniScript* miniScript, Properties& descriptions, const string& descriptionPrefix, unordered_set& categories, const set& allClassMethods, MiniScript* omitMiniScript = nullptr) { +static void generateMiniMethodsDocumentation(const string& heading, int mainHeadingIdx, MiniScript* miniScript, Properties& descriptions, const string& descriptionPrefix, unordered_set& categories, const set& allClassMethods, MiniScript* omitMiniScript = nullptr) { auto scriptMethods = miniScript->getMethods(); map>> methodMarkupByCategory; for (auto scriptMethod: scriptMethods) { @@ -68,7 +68,7 @@ static void generateMiniScriptMethodsDocumentation(const string& heading, int ma method+= "("; method+= scriptMethod->getArgumentsInformation(); method+= "): "; - method+= MiniScript::ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + method+= MiniScript::Variable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); method+= ""; while (method.size() < 99) method+= " "; method+= "|"; @@ -119,19 +119,19 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma auto scriptMethods = miniScript->getMethods(); // for (auto typeIdx = static_cast(MiniScript::TYPE_STRING); ; typeIdx++) { - const auto& className = MiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& className = MiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (className.empty() == true) break; allClassMethods.insert(className); } // for (auto scriptMethod: scriptMethods) { string className; - if (scriptMethod->getMethodName().rfind('.') != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind('.')); + if (scriptMethod->getMethodName().rfind("::") != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind("::")); if (className.empty() == true && allClassMethods.find(scriptMethod->getMethodName()) == allClassMethods.end()) continue; // auto _class = false; for (auto typeIdx = static_cast(MiniScript::TYPE_STRING); ; typeIdx++) { - const auto& classNameCandidate = MiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& classNameCandidate = MiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (classNameCandidate.empty() == true) break; if (classNameCandidate == className) { _class = true; @@ -143,13 +143,13 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma string method = StringTools::substring( scriptMethod->getMethodName(), - className.empty() == true?0:className.size() + 1, + className.empty() == true?0:className.size() + 2, scriptMethod->getMethodName().size()); // no arguments or no "this" argument auto _static = scriptMethod->getArgumentTypes().empty() == true || - scriptMethod->getArgumentTypes()[0].name != className || - MiniScript::ScriptVariable::getClassName(scriptMethod->getArgumentTypes()[0].type) != className; + scriptMethod->getArgumentTypes()[0].name != StringTools::toLowerCase(className) || + MiniScript::Variable::getTypeAsString(scriptMethod->getArgumentTypes()[0].type) != className; // allClassMethods.insert(scriptMethod->getMethodName()); } @@ -161,12 +161,12 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma // string result; string className; - if (scriptMethod->getMethodName().rfind('.') != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind('.')); + if (scriptMethod->getMethodName().rfind("::") != string::npos) className = StringTools::substring(scriptMethod->getMethodName(), 0, scriptMethod->getMethodName().rfind("::")); // constructors auto _static = false; if (className.empty() == true) { for (auto typeIdx = static_cast(MiniScript::TYPE_STRING); ; typeIdx++) { - const auto& classNameCandidate = MiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& classNameCandidate = MiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (classNameCandidate.empty() == true) break; if (scriptMethod->getMethodName() == classNameCandidate) { className = classNameCandidate; @@ -179,8 +179,8 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma if (_static == false) { _static = scriptMethod->getArgumentTypes().empty() == true || - scriptMethod->getArgumentTypes()[0].name != className || - MiniScript::ScriptVariable::getClassName(scriptMethod->getArgumentTypes()[0].type) != className; + scriptMethod->getArgumentTypes()[0].name != StringTools::toLowerCase(className) || + MiniScript::Variable::getTypeAsString(scriptMethod->getArgumentTypes()[0].type) != className; } // string description; @@ -194,11 +194,11 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma if (_static == true) { method+= "static "; } - method+= _static == true?scriptMethod->getMethodName():StringTools::substring(scriptMethod->getMethodName(), className.size() + 1, scriptMethod->getMethodName().size()); + method+= _static == true?scriptMethod->getMethodName():StringTools::substring(scriptMethod->getMethodName(), className.size() + 2, scriptMethod->getMethodName().size()); method+= "("; method+= scriptMethod->getArgumentsInformation(_static == true?0:1); method+= "): "; - method+= MiniScript::ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + method+= MiniScript::Variable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); method+= ""; while (method.size() < 99) method+= " "; method+= "|"; @@ -209,7 +209,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma // auto classIdx = 1; for (auto typeIdx = static_cast(MiniScript::TYPE_STRING); ; typeIdx++) { - const auto& className = MiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& className = MiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (className.empty() == true) break; auto classNameDescription = descriptions.get("miniscript.baseclass." + (className.empty() == true?"No class":className), "Not documented"); // @@ -269,7 +269,7 @@ int main(int argc, char** argv) // classes miniscript::tools::cli::MiniscriptDocumentation::generateMiniScriptClassesDocumentation("MiniScript Classes", 6, miniScript.get(), descriptions, "miniscript.basemethod.", allClassMethods); // base methods - miniscript::tools::cli::MiniscriptDocumentation::generateMiniScriptMethodsDocumentation("MiniScript Methods", 7, miniScript.get(), descriptions, "miniscript.basemethod.", baseMethodCategories, allClassMethods); + miniscript::tools::cli::MiniscriptDocumentation::generateMiniMethodsDocumentation("MiniScript Methods", 7, miniScript.get(), descriptions, "miniscript.basemethod.", baseMethodCategories, allClassMethods); // operators auto scriptOperatorMethods = miniScript->getOperatorMethods(); @@ -284,7 +284,7 @@ int main(int argc, char** argv) operatorString+= "("; operatorString+= scriptMethod->getArgumentsInformation(); operatorString+= "): "; - operatorString+= MiniScript::ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + operatorString+= MiniScript::Variable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); while (operatorString.size() < 99) operatorString+= " "; operatorString+= "|"; operators.push_back(operatorString); diff --git a/ext/miniscript/src/miniscript/tools/miniscripttranspiler-main.cpp b/ext/miniscript/src/miniscript/tools/miniscripttranspiler-main.cpp index 0396df35a..f5ce0f5cf 100644 --- a/ext/miniscript/src/miniscript/tools/miniscripttranspiler-main.cpp +++ b/ext/miniscript/src/miniscript/tools/miniscripttranspiler-main.cpp @@ -121,7 +121,7 @@ static void processFile(const string& scriptFileName, const string& transpilatio // unordered_map> methodCodeMap; - auto allMethods = Transpiler::getAllMethodNames(miniScript.get()); + auto allMethods = Transpiler::getAllClassesMethodNames(miniScript.get()); // vector transpilationUnitIncludes; @@ -303,7 +303,7 @@ static void processFile(const string& scriptFileName, const string& transpilatio initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + to_string(script.line) + "," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\"" + StringTools::replace(StringTools::replace(script.condition, "\\", "\\\\"), "\"", "\\\"") + "\"," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\"" + StringTools::replace(StringTools::replace(script.executableCondition, "\\", "\\\\"), "\"", "\\\"") + "\"," + "\n"; - initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "ScriptStatement(" + "\n"; + initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "Statement(" + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + to_string(script.conditionStatement.line) + "," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + to_string(script.conditionStatement.statementIdx) + "," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "\"" + StringTools::replace(StringTools::replace(StringTools::replace(script.conditionStatement.statement, "\\", "\\\\"), "\"", "\\\""), "\n", "\\n") + "\"," + "\n"; @@ -316,7 +316,7 @@ static void processFile(const string& scriptFileName, const string& transpilatio initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "{" + "\n"; auto statementIdx = MiniScript::STATEMENTIDX_FIRST; for (const auto& statement: script.statements) { - initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "ScriptStatement(" + "\n"; + initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "Statement(" + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "\t" + to_string(statement.line) + "," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "\t" + to_string(statement.statementIdx) + "," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "\t" + "\"" + StringTools::replace(StringTools::replace(StringTools::replace(statement.statement, "\\", "\\\\"), "\n", "\\n"), "\"", "\\\"") + "\"," + "\n"; @@ -327,14 +327,14 @@ static void processFile(const string& scriptFileName, const string& transpilatio } initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "}," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "{},\n"; - initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + (script.callable == true?"true":"false") + ",\n"; + initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + (script.callableFunction == true?"true":"false") + ",\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "{\n"; auto argumentIdx = 0; - for (const auto& argument: script.arguments) { + for (const auto& argument: script.functionArguments) { initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "Script::ScriptArgument(" + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "\t" + "\"" + argument.name + "\"," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" + "\t" + (argument.reference == true?"true":"false") + "\n"; - initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" ")" + (argumentIdx != script.arguments.size() - 1?",":"") + "\n"; + initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\t" ")" + (argumentIdx != script.functionArguments.size() - 1?",":"") + "\n"; argumentIdx++; } initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "}\n"; @@ -344,15 +344,15 @@ static void processFile(const string& scriptFileName, const string& transpilatio } initializeNativeDefinition+= methodCodeIndent + "\t" + "}" + "\n"; initializeNativeDefinition+= methodCodeIndent + ");" + "\n"; - initializeNativeDefinition+= methodCodeIndent + "setNativeScriptFunctions(" + "\n"; + initializeNativeDefinition+= methodCodeIndent + "setNativeFunctions(" + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "{" + "\n"; - auto scriptFunctionIdx = 0; - for (const auto& [functionName, functionIdx]: miniScript->scriptFunctions) { + auto functionItIdx = 0; + for (const auto& [functionName, functionIdx]: miniScript->functions) { initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "{" + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + "\"" + functionName + "\"," + "\n"; initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "\t" + to_string(functionIdx) + "\n"; - initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "}" + (scriptFunctionIdx != miniScript->scriptFunctions.size() - 1?",":"") + "\n"; - scriptFunctionIdx++; + initializeNativeDefinition+= methodCodeIndent + "\t" + "\t" + "}" + (functionItIdx != miniScript->functions.size() - 1?",":"") + "\n"; + functionItIdx++; } initializeNativeDefinition+= methodCodeIndent + "\t" + "}" + "\n"; initializeNativeDefinition+= methodCodeIndent + ");" + "\n"; diff --git a/ext/miniscript/src/miniscript/utilities/StringTools.cpp b/ext/miniscript/src/miniscript/utilities/StringTools.cpp index dd68bd342..96ccfa89a 100644 --- a/ext/miniscript/src/miniscript/utilities/StringTools.cpp +++ b/ext/miniscript/src/miniscript/utilities/StringTools.cpp @@ -7,6 +7,7 @@ #include #include +#include #include using std::find_if; @@ -21,16 +22,18 @@ using std::tolower; using std::toupper; using std::transform; -using miniscript::utilities::StringTokenizer; using miniscript::utilities::StringTools; -const string StringTools::replace(const string& src, const char what, const char by, int beginIndex) { +using miniscript::utilities::Character; +using miniscript::utilities::StringTokenizer; + +const string StringTools::replace(const string& src, const char what, const char by, int64_t beginIndex) { string result = src; std::replace(result.begin() + beginIndex, result.end(), what, by); return result; } -const string StringTools::replace(const string& src, const string& what, const string& by, int beginIndex) { +const string StringTools::replace(const string& src, const string& what, const string& by, int64_t beginIndex) { string result = src; if (what.empty()) return result; while ((beginIndex = result.find(what, beginIndex)) != std::string::npos) { @@ -74,12 +77,12 @@ const string StringTools::trim(const string& src) { } const string_view StringTools::viewTrim(const string_view& src) { - auto start = 0; - for (auto i = 0; i < src.size(); i++) { + int64_t start = 0; + for (int64_t i = 0; i < src.size(); i++) { if (isspace(src[i]) != 0) start++; else break; } - auto end = 0; - for (int i = src.size() - 1; i >= 0; i--) { + int64_t end = 0; + for (int64_t i = src.size() - 1; i >= 0; i--) { if (isspace(src[i]) != 0) end++; else break; } return string_view(&src[start], src.size() - start - end); @@ -116,3 +119,23 @@ const vector StringTools::tokenize(const string& str, const string& deli t.tokenize(str, delimiters, emptyTokens); return t.getTokens(); } + +int64_t StringTools::getUTF8Length(const string& str) { + UTF8CharacterIterator u8It(str); + u8It.seekCharacterPosition(4611686018427387903); // 2 ^ 62 - 1 + return u8It.getCharacterPosition(); +} + +const string StringTools::getUTF8CharAt(const string& str, int64_t index) { + // utf8 character iterator + UTF8CharacterIterator u8It(str); + u8It.seekCharacterPosition(index); + // + return u8It.hasNext() == true?::miniscript::utilities::Character::toString(u8It.next()):string(); +} + +int64_t StringTools::getUTF8BinaryIndex(const string& str, int64_t charIdx) { + UTF8CharacterIterator u8It(str); + u8It.seekCharacterPosition(charIdx); + return u8It.getBinaryPosition(); +} diff --git a/ext/miniscript/src/miniscript/utilities/StringTools.h b/ext/miniscript/src/miniscript/utilities/StringTools.h index 2b49c18c5..79e593913 100644 --- a/ext/miniscript/src/miniscript/utilities/StringTools.h +++ b/ext/miniscript/src/miniscript/utilities/StringTools.h @@ -21,239 +21,284 @@ class miniscript::utilities::StringTools final public: /** * Checks if string starts with prefix - * @param src source string + * @param str string * @param prefix prefix string - * @return bool + * @return if string starts with prefix */ - inline static const bool startsWith(const string& src, const string& prefix) { - return src.find(prefix) == 0; + inline static const bool startsWith(const string& str, const string& prefix) { + return str.find(prefix) == 0; } /** * Checks if string starts with prefix - * @param src source string + * @param str string * @param prefix prefix string - * @return bool + * @return if string starts with prefix */ - inline static const bool viewStartsWith(const string_view& src, const string& prefix) { - return src.find(prefix) == 0; + inline static const bool viewStartsWith(const string_view& str, const string& prefix) { + return str.find(prefix) == 0; } /** * Checks if string ends with suffix - * @param src source string + * @param str string * @param suffix suffix string - * @return bool + * @return if string ends with suffix */ - inline static const bool endsWith(const string& src, const string& suffix) { + inline static const bool endsWith(const string& str, const string& suffix) { return - src.size() >= suffix.size() && - src.compare(src.size() - suffix.size(), suffix.size(), suffix) == 0; + str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } /** * Checks if string ends with suffix - * @param src source string + * @param str string * @param suffix suffix string - * @return bool + * @return if string ends with suffix */ - inline static const bool viewEndsWith(const string_view& src, const string& suffix) { + inline static const bool viewEndsWith(const string_view& str, const string& suffix) { return - src.size() >= suffix.size() && - src.compare(src.size() - suffix.size(), suffix.size(), suffix) == 0; + str.size() >= suffix.size() && + str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } /** * Replace char with another char - * @param src source string to be processed + * @param str string * @param what what to replace * @param by to replace by * @param beginIndex index to begin with - * @return new string + * @return replace result */ - static const string replace(const string& src, const char what, const char by, int beginIndex = 0); + static const string replace(const string& str, const char what, const char by, int64_t beginIndex = 0); /** * Replace string with another string - * @param src source string to be processed + * @param str string * @param what what to replace * @param by to replace by * @param beginIndex index to begin with - * @return new string + * @return replace result */ - static const string replace(const string& src, const string& what, const string& by, int beginIndex = 0); + static const string replace(const string& str, const string& what, const string& by, int64_t beginIndex = 0); /** - * Finds index of given character - * @param src source string + * Finds first index of given character + * @param str string * @param what what - * @param beginIndex index to begin with - * @return index or -1 if not found + * @param beginIndex begin index + * @return index or string::npos if not found */ - inline static int32_t indexOf(const string& src, char what, int beginIndex = 0) { - return src.find(what, beginIndex); + inline static int64_t indexOf(const string& str, char what, int64_t beginIndex = 0) { + return str.find(what, beginIndex); } /** * Finds first index of given string - * @param src source string + * @param str string * @param what what - * @param beginIndex index to begin with - * @return index or -1 if not found + * @param beginIndex begin index + * @return index or string::npos if not found */ - inline static int32_t indexOf(const string& src, const string& what, int beginIndex = 0) { - return src.find(what, beginIndex); + inline static int64_t indexOf(const string& str, const string& what, int64_t beginIndex = 0) { + return str.find(what, beginIndex); } /** * Finds first index of given character - * @param src source string + * @param str string * @param what what - * @param beginIndex index to begin with - * @return index or -1 if not found + * @param beginIndex begin index + * @return index or string::npos if not found */ - inline static int32_t firstIndexOf(const string& src, char what, int beginIndex = 0) { - return src.find_first_of(what, beginIndex); + inline static int64_t firstIndexOf(const string& str, char what, int64_t beginIndex = 0) { + return indexOf(str, what, beginIndex); } /** - * Finds first index of characters provided within given string - * @param src source string + * Finds first index of given string + * @param str string * @param what what - * @param beginIndex index to begin with - * @return index or -1 if not found + * @param beginIndex begin index + * @return index or string::npos if not found */ - inline static int32_t firstIndexOf(const string& src, const string& what, int beginIndex = 0) { - return src.find_first_of(what, beginIndex); + inline static int64_t firstIndexOf(const string& str, const string& what, int64_t beginIndex = 0) { + return indexOf(str, what, beginIndex); } /** * Finds last index of given character - * @param src source string + * @param str string * @param what what - * @param beginIndex index to begin with - * @return index or -1 if not found + * @param endIndex end index or string::npos + * @return index or string::npos if not found + */ + inline static int64_t lastIndexOf(const string& str, const char what, int64_t endIndex = string::npos) { + return str.rfind(what, endIndex); + } + + /** + * Finds last index of given string + * @param str string + * @param what what + * @param endIndex end index or string::npos + * @return index or string::npos if not found + */ + inline static int64_t lastIndexOf(const string& str, const string& what, int64_t endIndex = string::npos) { + return str.rfind(what, endIndex); + } + + /** + * Finds first index of character provided within given string + * @param str string + * @param what what + * @param beginIndex begin index + * @return index or string::npos if not found */ - inline static int32_t lastIndexOf(const string& src, char what, int beginIndex = -1) { - return src.find_last_of(what, beginIndex); + inline static int64_t firstIndexOfChar(const string& str, char what, int64_t beginIndex = 0) { + return str.find_first_of(what, beginIndex); + } + + /** + * Finds first index of characters provided within given string + * @param str string + * @param what what + * @param beginIndex begin index + * @return index or string::npos if not found + */ + inline static int64_t firstIndexOfChars(const string& str, const string& what, int64_t beginIndex = 0) { + return str.find_first_of(what, beginIndex); + } + + /** + * Finds last index of character provided within given string + * @param str string + * @param what what + * @param endIndex end index or string::npos + * @return index or string::npos if not found + */ + inline static int64_t lastIndexOfChar(const string& str, char what, int64_t endIndex = string::npos) { + return str.find_last_of(what, endIndex); } /** * Finds last index of characters provided within given string - * @param src source string + * @param str string * @param what what - * @param beginIndex index to begin with - * @return index or -1 if not found + * @param endIndex end index or string::npos + * @return index or string::npos if not found */ - inline static int32_t lastIndexOf(const string& src, const string& what, int beginIndex = -1) { - return src.find_last_of(what, beginIndex); + inline static int64_t lastIndexOfChars(const string& str, const string& what, int64_t endIndex = string::npos) { + return str.find_last_of(what, endIndex); } /** * Returns substring of given string from begin index - * @param src source string + * @param str string * @param beginIndex begin index - * @return new string + * @return substring result */ - inline static const string substring(const string& src, int32_t beginIndex) { - return src.substr(beginIndex); + inline static const string substring(const string& str, int64_t beginIndex) { + return str.substr(beginIndex); } /** * Returns substring of given string from begin index - * @param src source string + * @param str string * @param beginIndex begin index - * @return new string + * @return substring result */ - inline static const string_view viewSubstring(const string_view& src, int32_t beginIndex) { - return src.substr(beginIndex); + inline static const string_view viewSubstring(const string_view& str, int64_t beginIndex) { + return str.substr(beginIndex); } /** * Returns substring of given string from begin index to end index - * @param src source string + * @param str string * @param beginIndex begin index * @param endIndex end index - * @return new string + * @return substring result */ - inline static const string substring(const string& src, int32_t beginIndex, int32_t endIndex) { - return src.substr(beginIndex, endIndex - beginIndex); + inline static const string substring(const string& str, int64_t beginIndex, int64_t endIndex) { + return str.substr(beginIndex, endIndex - beginIndex); } /** * Returns substring of given string from begin index to end index - * @param src source string + * @param str string * @param beginIndex begin index * @param endIndex end index - * @return new string + * @return substring result */ - inline static const string_view viewSubstring(const string_view& src, int32_t beginIndex, int32_t endIndex) { - return src.substr(beginIndex, endIndex - beginIndex); + inline static const string_view viewSubstring(const string_view& str, int64_t beginIndex, int64_t endIndex) { + return str.substr(beginIndex, endIndex - beginIndex); } /** - * Checks if string equals ignoring case + * Checks if strings equal ignoring case * @param string1 string 1 * @param string2 string 2 - * @return equals + * @return equality */ static bool equalsIgnoreCase(const string& string1, const string& string2); /** * Trim string - * @param src source string + * @param str string * @return trimmed string */ - static const string trim(const string& src); + static const string trim(const string& str); /** * Trim string - * @param src source string + * @param str string * @return trimmed string */ - static const string_view viewTrim(const string_view& src); + static const string_view viewTrim(const string_view& str); /** * Transform string to lower case - * @param src source string - * @return transformed string + * @param str string + * @return lowercase string */ - static const string toLowerCase(const string& src); + static const string toLowerCase(const string& str); /** * Transform string to upper case - * @param src source string - * @return transformed string + * @param str string + * @return uppercase string */ - static const string toUpperCase(const string& src); + static const string toUpperCase(const string& str); /** * Check if pattern matches whole string - * @param src source string to test + * @param str string * @param pattern pattern * @return if pattern matches whole string */ - static bool regexMatch(const string& src, const string& pattern); + static bool regexMatch(const string& str, const string& pattern); /** * Do regex pattern search - * @param src source string to test + * @param str string * @param pattern pattern * @return if search was successful */ - static bool regexSearch(const string& src, const string& pattern); + static bool regexSearch(const string& str, const string& pattern); /** * Replace regex pattern with given string - * @param src source string to operate on - * @param pattern pattern to search - * @param by string that will replace pattern occurrances + * @param str string + * @param pattern pattern + * @param by replace string + * @return replace result */ - static const string regexReplace(const string& src, const string& pattern, const string& by); + static const string regexReplace(const string& str, const string& pattern, const string& by); /** * Tokenize - * @param str string to tokenize + * @param str string * @param delimiters delimiters * @param emptyTokens include empty tokens * @return tokens @@ -262,62 +307,77 @@ class miniscript::utilities::StringTools final /** * Pad a string left - * @param src source + * @param str string * @param by by * @param toSize to size + * @return padded string */ - inline static const string padLeft(const string& src, const string& by, int toSize) { - auto result = src; + inline static const string padLeft(const string& str, const string& by, int64_t toSize) { + auto result = str; while (result.size() < toSize) result = by + result; return result; } /** * Pad a string right - * @param src source + * @param str string * @param by by * @param toSize to size + * @return padded string */ - inline static const string padRight(const string& src, const string& by, int toSize) { - auto result = src; + inline static const string padRight(const string& str, const string& by, int64_t toSize) { + auto result = str; while (result.size() < toSize) result = result + by; return result; } /** * Indent a string - * @param src source + * @param str string * @param with with * @param count count + * @return resulting string */ - inline static const string indent(const string& src, const string& with, int count) { + inline static const string indent(const string& str, const string& with, int64_t count) { string indentString; for (auto i = 0; i < count; i++) indentString+= with; - return indentString + src; + return indentString + str; } /** - * Get Utf8 string length - * @param str string - * @return utf8 string length + * Generate a string + * @param what what + * @param count count + * @return resulting string */ - inline static int getUtf8Length(const string& str) { - ::miniscript::utilities::UTF8CharacterIterator u8It(str); - while (u8It.hasNext() == true) u8It.next(); - return u8It.getCharacterPosition(); + inline static const string generate(const string& what, int64_t count = 1) { + string result; + for (auto i = 0; i < count; i++) result+= what; + return result; } /** - * Get Utf8 binary buffer index + * Get UTF8 string length + * @param str string + * @return UTF8 string length + */ + static int64_t getUTF8Length(const string& str); + + /** + * Get UTF8 character at given index + * @param str string + * @param index index + * @param cache UTF8 position cache + */ + static const string getUTF8CharAt(const string& str, int64_t index); + + /** + * Get UTF8 binary buffer index * @param str string * @param charIdx character index * @return UTF binary buffer position from given character/code point index */ - inline static int getUtf8BinaryIndex(const string& str, int charIdx) { - ::miniscript::utilities::UTF8CharacterIterator u8It(str); - u8It.seekCharacterPosition(charIdx); - return u8It.getBinaryPosition(); - } + static int64_t getUTF8BinaryIndex(const string& str, int64_t charIdx); }; diff --git a/ext/miniscript/src/miniscript/utilities/UTF8CharacterIterator.h b/ext/miniscript/src/miniscript/utilities/UTF8CharacterIterator.h index 8af962fd9..c297d65e4 100644 --- a/ext/miniscript/src/miniscript/utilities/UTF8CharacterIterator.h +++ b/ext/miniscript/src/miniscript/utilities/UTF8CharacterIterator.h @@ -1,13 +1,14 @@ #pragma once #include +#include #include #include #include #include -using std::string; +using std::string_view; using std::to_string; using std::vector; @@ -22,7 +23,7 @@ class miniscript::utilities::UTF8CharacterIterator { class UTF8PositionCache { friend class UTF8CharacterIterator; public: - static constexpr int CACHE_ENTRY_SIZE { 100 }; + static constexpr int64_t CACHE_ENTRY_SIZE { 100 }; /** * Remove cache @@ -36,7 +37,7 @@ class miniscript::utilities::UTF8CharacterIterator { * Remove from cache by binary index * @param idx binary index */ - inline void removeCache(int binaryIdx, int characterIdx) { + inline void removeCache(int64_t binaryIdx, int64_t characterIdx) { // Console::println("MutableString::removeCache(): binary: " + to_string(binaryIdx) + ", character: " + to_string(characterIdx)); // remove succeeding entries from binary cache if (binaryIdx >= UTF8CharacterIterator::UTF8PositionCache::CACHE_ENTRY_SIZE) { @@ -65,14 +66,14 @@ class miniscript::utilities::UTF8CharacterIterator { private: struct UTF8PositionCacheEntry { UTF8PositionCacheEntry( - int binaryPosition, - int characterPosition + int64_t binaryPosition, + int64_t characterPosition ): binaryPosition(binaryPosition), characterPosition(characterPosition) {} - int binaryPosition; - int characterPosition; + int64_t binaryPosition; + int64_t characterPosition; }; vector binaryCache; vector characterCache; @@ -83,11 +84,10 @@ class miniscript::utilities::UTF8CharacterIterator { /** * Public constructor - * @param stringReference string reference + * @param stringView string view * @param cache UTF8 position cache or nullptr if UTF8 positions should not be cached */ - inline UTF8CharacterIterator(const string& stringReference, UTF8PositionCache* cache = nullptr): stringReference(stringReference), cache(cache) { - // + inline UTF8CharacterIterator(const string_view& stringView, UTF8PositionCache* cache = nullptr): stringView(stringView), cache(cache) { } /** @@ -101,7 +101,7 @@ class miniscript::utilities::UTF8CharacterIterator { /** * @return underlying binary buffer position */ - inline int getBinaryPosition() const { + inline int64_t getBinaryPosition() const { return binaryPosition; } @@ -109,7 +109,7 @@ class miniscript::utilities::UTF8CharacterIterator { * Set underlying binary buffer position * @param position underlying buffer position */ - inline void seekBinaryPosition(int position) const { + inline void seekBinaryPosition(int64_t position) const { reset(); // seeking in cache first if (position >= UTF8PositionCache::CACHE_ENTRY_SIZE && cache != nullptr && cache->binaryCache.empty() == false) { @@ -120,14 +120,15 @@ class miniscript::utilities::UTF8CharacterIterator { } // while (hasNext() == true && binaryPosition < position) { - if (hasNext() == true) next(); + if (hasNext() == false) break; + next(); } } /** * @return character position */ - inline int getCharacterPosition() const { + inline int64_t getCharacterPosition() const { return characterPosition; } @@ -135,7 +136,7 @@ class miniscript::utilities::UTF8CharacterIterator { * Seek character position * @param position character position */ - inline void seekCharacterPosition(int position) const { + inline void seekCharacterPosition(int64_t position) const { reset(); // seeking in cache first if (position >= UTF8PositionCache::CACHE_ENTRY_SIZE && cache != nullptr && cache->characterCache.empty() == false) { @@ -146,7 +147,7 @@ class miniscript::utilities::UTF8CharacterIterator { } // auto seekCount = position - characterPosition; - for (auto i = 0; i < seekCount; i++) { + for (int64_t i = 0; i < seekCount; i++) { if (hasNext() == false) break; next(); } @@ -156,16 +157,16 @@ class miniscript::utilities::UTF8CharacterIterator { * @return next character available */ inline bool hasNext() const { - return binaryPosition < stringReference.size(); + return binaryPosition < stringView.size(); } /** * @return next character or -1 if an error occurred or no string left */ inline int next() const { // see: http://www.zedwood.com/article/cpp-utf8-char-to-codepoint - int l = stringReference.size() - binaryPosition; + int64_t l = stringView.size() - binaryPosition; if (l < 1) return -1; - unsigned char u0 = stringReference[binaryPosition + 0]; + unsigned char u0 = stringView[binaryPosition + 0]; if (u0 >= 0 && u0 <= 127) { addCacheEntry(); binaryPosition++; @@ -178,7 +179,7 @@ class miniscript::utilities::UTF8CharacterIterator { characterPosition++; return -1; } - unsigned char u1 = stringReference[binaryPosition + 1]; + unsigned char u1 = stringView[binaryPosition + 1]; if (u0 >= 192 && u0 <= 223) { addCacheEntry(); binaryPosition+= 2; @@ -197,7 +198,7 @@ class miniscript::utilities::UTF8CharacterIterator { characterPosition++; return -1; } - unsigned char u2 = stringReference[binaryPosition + 2]; + unsigned char u2 = stringView[binaryPosition + 2]; if (u0 >= 224 && u0 <= 239) { addCacheEntry(); binaryPosition+= 3; @@ -210,7 +211,7 @@ class miniscript::utilities::UTF8CharacterIterator { characterPosition++; return -1; } - unsigned char u3 = stringReference[binaryPosition + 3]; + unsigned char u3 = stringView[binaryPosition + 3]; if (u0 >= 240 && u0 <= 247) { addCacheEntry(); binaryPosition+= 4; @@ -226,9 +227,9 @@ class miniscript::utilities::UTF8CharacterIterator { } private: - const string& stringReference; - mutable int binaryPosition { 0 }; - mutable int characterPosition { 0 }; + const string_view stringView; + mutable int64_t binaryPosition { 0 }; + mutable int64_t characterPosition { 0 }; mutable UTF8PositionCache* cache; /** diff --git a/ext/miniscript/src/miniscript/utilities/fwd-miniscript.h b/ext/miniscript/src/miniscript/utilities/fwd-miniscript.h index 9c93eb5ca..8037c217b 100644 --- a/ext/miniscript/src/miniscript/utilities/fwd-miniscript.h +++ b/ext/miniscript/src/miniscript/utilities/fwd-miniscript.h @@ -16,5 +16,7 @@ namespace utilities { class StringTools; class Time; class UTF8CharacterIterator; + class UTF8StringTokenizer; + class UTF8StringTools; } // namespace utilities } // namespace miniscript diff --git a/src/tdme/engine/logics/Logic.h b/src/tdme/engine/logics/Logic.h index 2f6ae5a27..aa8e54e52 100644 --- a/src/tdme/engine/logics/Logic.h +++ b/src/tdme/engine/logics/Logic.h @@ -60,10 +60,10 @@ class tdme::engine::logics::Logic { struct SignalStruct { SignalStruct( const string& signal, - const vector& arguments + const vector& arguments ): signal(signal), arguments(arguments) {} string signal; - vector arguments; + vector arguments; }; vector signals; @@ -211,7 +211,7 @@ class tdme::engine::logics::Logic { * @param signal signal * @param arguments arguments */ - inline void addSignal(const string& signal, const vector& arguments) { + inline void addSignal(const string& signal, const vector& arguments) { signals.emplace_back( signal, arguments @@ -240,9 +240,9 @@ class tdme::engine::logics::Logic { * Get signal argument * @return signal argument at given index */ - inline EngineMiniScript::ScriptVariable getSignalArgument(int idx) { - if (signals.empty() == true) return EngineMiniScript::ScriptVariable(); - if (idx >= signals[0].arguments.size()) return EngineMiniScript::ScriptVariable(); + inline EngineMiniScript::Variable getSignalArgument(int idx) { + if (signals.empty() == true) return EngineMiniScript::Variable(); + if (idx >= signals[0].arguments.size()) return EngineMiniScript::Variable(); return signals[0].arguments[idx]; } diff --git a/src/tdme/engine/logics/LogicMiniScript.cpp b/src/tdme/engine/logics/LogicMiniScript.cpp index 3407bac6f..781cc782c 100644 --- a/src/tdme/engine/logics/LogicMiniScript.cpp +++ b/src/tdme/engine/logics/LogicMiniScript.cpp @@ -131,142 +131,142 @@ void LogicMiniScript::registerMethods() { EngineMiniScript::registerMethods(); { // - class ScriptMethodApplicationRunsInEditor: public ScriptMethod { + class MethodApplicationRunsInEditor: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodApplicationRunsInEditor(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodApplicationRunsInEditor(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "application.runsInEditor"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->isRunningInEditor()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodApplicationRunsInEditor(this)); + registerMethod(new MethodApplicationRunsInEditor(this)); } { // - class ScriptMethodApplicationIsFullScreen: public ScriptMethod { + class MethodApplicationIsFullScreen: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodApplicationIsFullScreen(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodApplicationIsFullScreen(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "application.isFullScreen"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, Editor::getInstance() != nullptr?Editor::getInstance()->isFullScreen():false); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodApplicationIsFullScreen(this)); + registerMethod(new MethodApplicationIsFullScreen(this)); } { // - class ScriptMethodLogicGetId: public ScriptMethod { + class MethodLogicGetId: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicGetId(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodLogicGetId(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "logic.getId"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getId()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINELOGIC; } }; - registerMethod(new ScriptMethodLogicGetId(this)); + registerMethod(new MethodLogicGetId(this)); } { // - class ScriptMethodLogicGetHierarchyId: public ScriptMethod { + class MethodLogicGetHierarchyId: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicGetHierarchyId(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodLogicGetHierarchyId(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "logic.getHierarchyId"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getHierarchyId()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINELOGIC; } }; - registerMethod(new ScriptMethodLogicGetHierarchyId(this)); + registerMethod(new MethodLogicGetHierarchyId(this)); } { // - class ScriptMethodLogicGetHierarchyParentId: public ScriptMethod { + class MethodLogicGetHierarchyParentId: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicGetHierarchyParentId(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodLogicGetHierarchyParentId(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "logic.getHierarchyParentId"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getHierarchyParentId()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINELOGIC; } }; - registerMethod(new ScriptMethodLogicGetHierarchyParentId(this)); + registerMethod(new MethodLogicGetHierarchyParentId(this)); } { // - class ScriptMethodLogicGetLogicIds: public ScriptMethod { + class MethodLogicGetLogicIds: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicGetLogicIds(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_ARRAY), + MethodLogicGetLogicIds(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_ARRAY), miniScript(miniScript) {} const string getMethodName() override { return "logic.getLogicIds"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { const auto& contextLogics = miniScript->logic->getContext()->getLogics(); returnValue.setType(EngineMiniScript::TYPE_ARRAY); for (auto contextLogic: contextLogics) { - returnValue.pushArrayEntry(EngineMiniScript::ScriptVariable(contextLogic->getId())); + returnValue.pushArrayEntry(EngineMiniScript::Variable(contextLogic->getId())); } } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodLogicGetLogicIds(this)); + registerMethod(new MethodLogicGetLogicIds(this)); } { // - class ScriptMethodAudioGetListenerPosition: public ScriptMethod { + class MethodAudioGetListenerPosition: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioGetListenerPosition(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioGetListenerPosition(LogicMiniScript* miniScript): + Method( {}, TYPE_VECTOR3 ), @@ -274,33 +274,33 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "audio.getListenerPosition"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getContext()->getAudio()->getListenerPosition()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioGetListenerPosition(this)); + registerMethod(new MethodAudioGetListenerPosition(this)); } { // - class ScriptMethodAudioSetListenerPosition: public ScriptMethod { + class MethodAudioSetListenerPosition: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioSetListenerPosition(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioSetListenerPosition(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "position", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "audio.setListenerPosition"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 position; if (miniScript->getVector3Value(argumentValues, 0, position) == true) { miniScript->logic->getContext()->getAudio()->setListenerPosition(position); @@ -313,16 +313,16 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioSetListenerPosition(this)); + registerMethod(new MethodAudioSetListenerPosition(this)); } { // - class ScriptMethodAudioGetListenerOrientationUp: public ScriptMethod { + class MethodAudioGetListenerOrientationUp: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioGetListenerOrientationUp(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioGetListenerOrientationUp(LogicMiniScript* miniScript): + Method( {}, TYPE_VECTOR3 ), @@ -330,33 +330,33 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "audio.getListenerOrientationUp"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getContext()->getAudio()->getListenerOrientationUp()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioGetListenerOrientationUp(this)); + registerMethod(new MethodAudioGetListenerOrientationUp(this)); } { // - class ScriptMethodAudioSetListenerOrientationUp: public ScriptMethod { + class MethodAudioSetListenerOrientationUp: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioSetListenerOrientationUp(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioSetListenerOrientationUp(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "orientation", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "audio.setListenerOrientationUp"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 orientation; if (miniScript->getVector3Value(argumentValues, 0, orientation) == true) { miniScript->logic->getContext()->getAudio()->setListenerOrientationUp(orientation); @@ -369,16 +369,16 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioSetListenerOrientationUp(this)); + registerMethod(new MethodAudioSetListenerOrientationUp(this)); } { // - class ScriptMethodAudioGetListenerOrientationAt: public ScriptMethod { + class MethodAudioGetListenerOrientationAt: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioGetListenerOrientationAt(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioGetListenerOrientationAt(LogicMiniScript* miniScript): + Method( {}, TYPE_VECTOR3 ), @@ -386,33 +386,33 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "audio.getListenerOrientationAt"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getContext()->getAudio()->getListenerOrientationAt()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioGetListenerOrientationAt(this)); + registerMethod(new MethodAudioGetListenerOrientationAt(this)); } { // - class ScriptMethodAudioSetListenerOrientationAt: public ScriptMethod { + class MethodAudioSetListenerOrientationAt: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioSetListenerOrientationAt(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioSetListenerOrientationAt(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "orientation", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "audio.setListenerOrientationAt"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 orientation; if (miniScript->getVector3Value(argumentValues, 0, orientation) == true) { miniScript->logic->getContext()->getAudio()->setListenerOrientationAt(orientation); @@ -425,30 +425,30 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioSetListenerOrientationAt(this)); + registerMethod(new MethodAudioSetListenerOrientationAt(this)); } { // - class ScriptMethodAudioPlaySound: public ScriptMethod { + class MethodAudioPlaySound: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioPlaySound(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioPlaySound(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "delay", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "gain", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "pitch", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "ignoreIfPlaying", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "delay", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "gain", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "pitch", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "ignoreIfPlaying", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "audio.play"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string id; int64_t delay = 0; auto gain = 1.0f; @@ -469,31 +469,31 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioPlaySound(this)); + registerMethod(new MethodAudioPlaySound(this)); } { // - class ScriptMethodAudioPlaySoundAtPosition: public ScriptMethod { + class MethodAudioPlaySoundAtPosition: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodAudioPlaySoundAtPosition(LogicMiniScript* miniScript): - ScriptMethod( + MethodAudioPlaySoundAtPosition(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "position", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "delay", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "gain", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "pitch", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "ignoreIfPlaying", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "delay", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "gain", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "pitch", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "ignoreIfPlaying", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "audio.playAtPosition"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string id; Vector3 position; int64_t delay = 0; @@ -516,24 +516,24 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodAudioPlaySoundAtPosition(this)); + registerMethod(new MethodAudioPlaySoundAtPosition(this)); } { // - class ScriptMethodLogicSignalSend: public ScriptMethod { + class MethodLogicSignalSend: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicSignalSend(LogicMiniScript* miniScript): - ScriptMethod({ - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "signal", .optional = false, .reference = false, .nullable = false } + MethodLogicSignalSend(LogicMiniScript* miniScript): + Method({ + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "signal", .optional = false, .reference = false, .nullable = false } }), miniScript(miniScript) {} const string getMethodName() override { return "logic.signal.send"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string logicId; string signal; if (miniScript->getStringValue(argumentValues, 0, logicId) == true && @@ -543,7 +543,7 @@ void LogicMiniScript::registerMethods() { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": no logic with given id: " + logicId); miniScript->startErrorScript(); } else { - vector arguments(argumentValues.size() - 2); + vector arguments(argumentValues.size() - 2); for (auto i = 2; i < argumentValues.size(); i++) arguments.push_back(argumentValues[i]); logic->addSignal(signal, arguments); } @@ -559,27 +559,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodLogicSignalSend(this)); + registerMethod(new MethodLogicSignalSend(this)); } { // - class ScriptMethodLogicHas: public ScriptMethod { + class MethodLogicHas: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicHas(LogicMiniScript* miniScript): - ScriptMethod( + MethodLogicHas(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "logic.has"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string logicId; string callable; if (EngineMiniScript::getStringValue(argumentValues, 0, logicId) == false || @@ -593,7 +593,7 @@ void LogicMiniScript::registerMethods() { } else { auto logicMiniScript = logic->getMiniScript(); auto scriptIdx = logicMiniScript->getFunctionScriptIdx(callable); - if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callable == false) { + if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callableFunction == false) { miniScript->setValue(returnValue, false); } else { miniScript->setValue(returnValue, true); @@ -602,27 +602,27 @@ void LogicMiniScript::registerMethods() { } } }; - registerMethod(new ScriptMethodLogicHas(this)); + registerMethod(new MethodLogicHas(this)); } { // - class ScriptMethodLogicCall: public ScriptMethod { + class MethodLogicCall: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicCall(LogicMiniScript* miniScript): - ScriptMethod( + MethodLogicCall(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_PSEUDO_MIXED + VariableType::TYPE_PSEUDO_MIXED ), miniScript(miniScript) {} const string getMethodName() override { return "logic.call"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string logicId; string callable; if (EngineMiniScript::getStringValue(argumentValues, 0, logicId) == false || @@ -637,13 +637,13 @@ void LogicMiniScript::registerMethods() { } else { auto logicMiniScript = logic->getMiniScript(); auto scriptIdx = logicMiniScript->getFunctionScriptIdx(callable); - if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callable == false) { + if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callableFunction == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": callable not found: " + callable); miniScript->startErrorScript(); } else { #if defined (__APPLE__) // MACOSX currently does not support initializing span using begin and end iterators, - vector callArgumentValues(argumentValues.size() - 2); + vector callArgumentValues(argumentValues.size() - 2); for (auto i = 2; i < argumentValues.size(); i++) callArgumentValues[i - 2] = move(argumentValues[i]); // call span callArgumentValuesSpan(callArgumentValues); @@ -662,68 +662,68 @@ void LogicMiniScript::registerMethods() { return true; } }; - registerMethod(new ScriptMethodLogicCall(this)); + registerMethod(new MethodLogicCall(this)); } { // - class ScriptMethodLogicSignalHas: public ScriptMethod { + class MethodLogicSignalHas: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicSignalHas(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodLogicSignalHas(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "logic.signal.has"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->hasSignal()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodLogicSignalHas(this)); + registerMethod(new MethodLogicSignalHas(this)); } { // - class ScriptMethodLogicSignalGetName: public ScriptMethod { + class MethodLogicSignalGetName: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicSignalGetName(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodLogicSignalGetName(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "logic.signal.getName"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->logic->getSignalName()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodLogicSignalGetName(this)); + registerMethod(new MethodLogicSignalGetName(this)); } { // - class ScriptMethodLogicSignalGetArgument: public ScriptMethod { + class MethodLogicSignalGetArgument: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicSignalGetArgument(LogicMiniScript* miniScript): - ScriptMethod( + MethodLogicSignalGetArgument(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "argumentIndex", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "argumentIndex", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_PSEUDO_MIXED + VariableType::TYPE_PSEUDO_MIXED ), miniScript(miniScript) {} const string getMethodName() override { return "logic.signal.getArgument"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t argumentIndex; if (miniScript->getIntegerValue(argumentValues, 0, argumentIndex) == true) { returnValue = miniScript->logic->getSignalArgument(argumentIndex); @@ -736,573 +736,573 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodLogicSignalGetArgument(this)); + registerMethod(new MethodLogicSignalGetArgument(this)); } { // - class ScriptMethodLogicSignalNext: public ScriptMethod { + class MethodLogicSignalNext: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicSignalNext(LogicMiniScript* miniScript): - ScriptMethod(), + MethodLogicSignalNext(LogicMiniScript* miniScript): + Method(), miniScript(miniScript) {} const string getMethodName() override { return "logic.signal.next"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->logic->removeSignal(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodLogicSignalNext(this)); + registerMethod(new MethodLogicSignalNext(this)); } // keyboard input { // - class ScriptMethodInputKeyboardKEYCODE_LEFT: public ScriptMethod { + class MethodInputKeyboardKEYCODE_LEFT: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_LEFT(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_LEFT(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_LEFT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_LEFT); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_LEFT(this)); + registerMethod(new MethodInputKeyboardKEYCODE_LEFT(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_RIGHT: public ScriptMethod { + class MethodInputKeyboardKEYCODE_RIGHT: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_RIGHT(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_RIGHT(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_RIGHT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_RIGHT); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_RIGHT(this)); + registerMethod(new MethodInputKeyboardKEYCODE_RIGHT(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_UP: public ScriptMethod { + class MethodInputKeyboardKEYCODE_UP: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_UP(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_UP(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_UP"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_UP); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_UP(this)); + registerMethod(new MethodInputKeyboardKEYCODE_UP(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_DOWN: public ScriptMethod { + class MethodInputKeyboardKEYCODE_DOWN: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_DOWN(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_DOWN(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_DOWN"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_DOWN); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_DOWN(this)); + registerMethod(new MethodInputKeyboardKEYCODE_DOWN(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_POS1: public ScriptMethod { + class MethodInputKeyboardKEYCODE_POS1: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_POS1(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_POS1(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_POS1"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_POS1); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_POS1(this)); + registerMethod(new MethodInputKeyboardKEYCODE_POS1(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_END: public ScriptMethod { + class MethodInputKeyboardKEYCODE_END: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_END(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_END(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_END"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_END); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_END(this)); + registerMethod(new MethodInputKeyboardKEYCODE_END(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_PAGEUP: public ScriptMethod { + class MethodInputKeyboardKEYCODE_PAGEUP: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_PAGEUP(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_PAGEUP(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_PAGEUP"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_PAGE_UP); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_PAGEUP(this)); + registerMethod(new MethodInputKeyboardKEYCODE_PAGEUP(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_PAGEDOWN: public ScriptMethod { + class MethodInputKeyboardKEYCODE_PAGEDOWN: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_PAGEDOWN(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_PAGEDOWN(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_PAGEDOWN"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_PAGE_DOWN); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_PAGEDOWN(this)); + registerMethod(new MethodInputKeyboardKEYCODE_PAGEDOWN(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_BACKSPACE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_BACKSPACE: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_BACKSPACE(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_BACKSPACE(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_BACKSPACE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_BACKSPACE); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_BACKSPACE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_BACKSPACE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_DELETE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_DELETE: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_DELETE(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_DELETE(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_DELETE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_DELETE); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_DELETE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_DELETE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_SPACE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_SPACE: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_SPACE(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_SPACE(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_SPACE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_SPACE); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_SPACE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_SPACE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_RETURN: public ScriptMethod { + class MethodInputKeyboardKEYCODE_RETURN: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_RETURN(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_RETURN(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_RETURN"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_RETURN); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_RETURN(this)); + registerMethod(new MethodInputKeyboardKEYCODE_RETURN(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_ESCAPE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_ESCAPE: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_ESCAPE(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_ESCAPE(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_ESCAPE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_ESCAPE); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_ESCAPE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_ESCAPE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F1: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F1: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F1(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F1(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F1"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F1); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F1(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F1(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F2: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F2: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F2(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F2(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F2"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F2); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F2(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F2(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F3: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F3: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F3(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F3(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F3"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F3); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F3(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F3(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F4: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F4: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F4(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F4(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F4"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F4); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F4(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F4(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F5: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F5: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F5(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F5(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F5"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F5); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F5(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F5(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F6: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F6: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F6(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F6(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F6"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F6); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F6(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F6(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F7: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F7: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F7(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F7(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F7"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F7); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F7(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F7(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F8: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F8: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F8(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F8(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F8"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F8); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F8(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F8(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F9: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F9: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F9(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F9(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F9"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F9); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F9(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F9(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F10: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F10: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F10(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F10(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F10"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F10); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F10(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F10(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F11: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F11: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F11(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F11(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F11"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F11); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F11(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F11(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F12: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F12: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F12(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F12(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F12"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F12); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F12(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F12(this)); } { // - class ScriptMethodInputKeyboardIsKeyDown: public ScriptMethod { + class MethodInputKeyboardIsKeyDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsKeyDown(LogicMiniScript* miniScript): - ScriptMethod( + MethodInputKeyboardIsKeyDown(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "keyCode", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "keyCode", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isKeyDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t keyCode; if (miniScript->getIntegerValue(argumentValues, 0, keyCode) == true) { returnValue = miniScript->keyboardKeys.find(keyCode) != miniScript->keyboardKeys.end(); @@ -1315,26 +1315,26 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardIsKeyDown(this)); + registerMethod(new MethodInputKeyboardIsKeyDown(this)); } { // - class ScriptMethodInputKeyboardIsCharDown: public ScriptMethod { + class MethodInputKeyboardIsCharDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsCharDown(LogicMiniScript* miniScript): - ScriptMethod( + MethodInputKeyboardIsCharDown(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "charAsString", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "charAsString", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isCharDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string charAsString; if (miniScript->getStringValue(argumentValues, 0, charAsString) == true) { UTF8CharacterIterator u8It(charAsString); @@ -1349,194 +1349,194 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardIsCharDown(this)); + registerMethod(new MethodInputKeyboardIsCharDown(this)); } { // - class ScriptMethodInputKeyboardGetTypedString: public ScriptMethod { + class MethodInputKeyboardGetTypedString: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardGetTypedString(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodInputKeyboardGetTypedString(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.getTypedString"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardTypedChars; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardGetTypedString(this)); + registerMethod(new MethodInputKeyboardGetTypedString(this)); } { // - class ScriptMethodInputKeyboardIsControlDown: public ScriptMethod { + class MethodInputKeyboardIsControlDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsControlDown(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsControlDown(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isControlDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardControlDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardIsControlDown(this)); + registerMethod(new MethodInputKeyboardIsControlDown(this)); } { // - class ScriptMethodInputKeyboardIsMetaDown: public ScriptMethod { + class MethodInputKeyboardIsMetaDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsMetaDown(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsMetaDown(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isMetaDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardControlDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardIsMetaDown(this)); + registerMethod(new MethodInputKeyboardIsMetaDown(this)); } { // - class ScriptMethodInputKeyboardIsAltDown: public ScriptMethod { + class MethodInputKeyboardIsAltDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsAltDown(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsAltDown(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isAltDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardAltDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardIsAltDown(this)); + registerMethod(new MethodInputKeyboardIsAltDown(this)); } { // - class ScriptMethodInputKeyboardIsShiftDown: public ScriptMethod { + class MethodInputKeyboardIsShiftDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsShiftDown(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsShiftDown(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isShiftDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardShiftDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputKeyboardIsShiftDown(this)); + registerMethod(new MethodInputKeyboardIsShiftDown(this)); } // mouse input { // - class ScriptMethodInputMouseBUTTON_LEFT: public ScriptMethod { + class MethodInputMouseBUTTON_LEFT: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseBUTTON_LEFT(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseBUTTON_LEFT(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.BUTTON_LEFT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIMouseEvent::MOUSEEVENT_BUTTON_LEFT - 1); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseBUTTON_LEFT(this)); + registerMethod(new MethodInputMouseBUTTON_LEFT(this)); } { // - class ScriptMethodInputMouseBUTTON_MIDDLE: public ScriptMethod { + class MethodInputMouseBUTTON_MIDDLE: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseBUTTON_MIDDLE(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseBUTTON_MIDDLE(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.BUTTON_MIDDLE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIMouseEvent::MOUSEEVENT_BUTTON_MIDDLE - 1); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseBUTTON_MIDDLE(this)); + registerMethod(new MethodInputMouseBUTTON_MIDDLE(this)); } { // - class ScriptMethodInputMouseBUTTON_RIGHT: public ScriptMethod { + class MethodInputMouseBUTTON_RIGHT: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseBUTTON_RIGHT(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseBUTTON_RIGHT(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.BUTTON_RIGHT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIMouseEvent::MOUSEEVENT_BUTTON_RIGHT - 1); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseBUTTON_RIGHT(this)); + registerMethod(new MethodInputMouseBUTTON_RIGHT(this)); } { // - class ScriptMethodInputMouseIsButtonDown: public ScriptMethod { + class MethodInputMouseIsButtonDown: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseIsButtonDown(LogicMiniScript* miniScript): - ScriptMethod( + MethodInputMouseIsButtonDown(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN), + VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.isButtonDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t button; if (miniScript->getIntegerValue(argumentValues, 0, button) == true) { returnValue = button >= 0 && button <= 3?miniScript->mouseDown[button]:false; @@ -1549,25 +1549,25 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseIsButtonDown(this)); + registerMethod(new MethodInputMouseIsButtonDown(this)); } { // - class ScriptMethodInputMouseIsButtonUp: public ScriptMethod { + class MethodInputMouseIsButtonUp: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseIsButtonUp(LogicMiniScript* miniScript): - ScriptMethod( + MethodInputMouseIsButtonUp(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN), + VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.isButtonUp"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t button; if (miniScript->getIntegerValue(argumentValues, 0, button) == true) { returnValue = button >= 0 && button <= 3?miniScript->mouseUp[button]:false; @@ -1580,25 +1580,25 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseIsButtonUp(this)); + registerMethod(new MethodInputMouseIsButtonUp(this)); } { // - class ScriptMethodInputMouseIsDragging: public ScriptMethod { + class MethodInputMouseIsDragging: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseIsDragging(LogicMiniScript* miniScript): - ScriptMethod( + MethodInputMouseIsDragging(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN), + VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.isDragging"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t button; if (miniScript->getIntegerValue(argumentValues, 0, button) == true) { returnValue = button >= 0 && button <= 3?miniScript->mouseDragging[button]:false; @@ -1611,216 +1611,216 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseIsDragging(this)); + registerMethod(new MethodInputMouseIsDragging(this)); } { // - class ScriptMethodInputMouseHasMoved: public ScriptMethod { + class MethodInputMouseHasMoved: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseHasMoved(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputMouseHasMoved(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.hasMoved"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseMoved; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseHasMoved(this)); + registerMethod(new MethodInputMouseHasMoved(this)); } { // - class ScriptMethodInputMouseGetX: public ScriptMethod { + class MethodInputMouseGetX: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetX(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetX(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getX"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseX); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetX(this)); + registerMethod(new MethodInputMouseGetX(this)); } { // - class ScriptMethodInputMouseGetXUnscaled: public ScriptMethod { + class MethodInputMouseGetXUnscaled: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetXUnscaled(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetXUnscaled(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getXUnscaled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseXUnscaled); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetXUnscaled(this)); + registerMethod(new MethodInputMouseGetXUnscaled(this)); } { // - class ScriptMethodInputMouseGetY: public ScriptMethod { + class MethodInputMouseGetY: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetY(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetY(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getY"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseY); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetY(this)); + registerMethod(new MethodInputMouseGetY(this)); } { // - class ScriptMethodInputMouseGetYUnscaled: public ScriptMethod { + class MethodInputMouseGetYUnscaled: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetYUnscaled(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetYUnscaled(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getYUnscaled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseYUnscaled); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetYUnscaled(this)); + registerMethod(new MethodInputMouseGetYUnscaled(this)); } { // - class ScriptMethodInputMouseGetWheelX: public ScriptMethod { + class MethodInputMouseGetWheelX: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetWheelX(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodInputMouseGetWheelX(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getWheelX"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseWheelX; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetWheelX(this)); + registerMethod(new MethodInputMouseGetWheelX(this)); } { // - class ScriptMethodInputMouseGetWheelY: public ScriptMethod { + class MethodInputMouseGetWheelY: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetWheelY(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodInputMouseGetWheelY(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getWheelY"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseWheelY; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetWheelY(this)); + registerMethod(new MethodInputMouseGetWheelY(this)); } { // - class ScriptMethodInputMouseGetWheelZ: public ScriptMethod { + class MethodInputMouseGetWheelZ: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetWheelZ(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodInputMouseGetWheelZ(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getWheelZ"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseWheelZ; } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodInputMouseGetWheelZ(this)); + registerMethod(new MethodInputMouseGetWheelZ(this)); } // camera { // - class ScriptMethodCameraGetLookFrom: public ScriptMethod { + class MethodCameraGetLookFrom: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraGetLookFrom(LogicMiniScript* miniScript): - ScriptMethod({}, TYPE_VECTOR3), + MethodCameraGetLookFrom(LogicMiniScript* miniScript): + Method({}, TYPE_VECTOR3), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.getLookFrom"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->context->getEngine()->getCamera()->getLookFrom()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraGetLookFrom(this)); + registerMethod(new MethodCameraGetLookFrom(this)); } { // - class ScriptMethodCameraSetLookFrom: public ScriptMethod { + class MethodCameraSetLookFrom: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraSetLookFrom(LogicMiniScript* miniScript): - ScriptMethod( + MethodCameraSetLookFrom(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "lookFrom", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.setLookFrom"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 lookFrom; if (miniScript->getVector3Value(argumentValues, 0, lookFrom) == true) { miniScript->context->getEngine()->getCamera()->setLookFrom(lookFrom); @@ -1833,47 +1833,47 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraSetLookFrom(this)); + registerMethod(new MethodCameraSetLookFrom(this)); } { // - class ScriptMethodCameraGetLookAt: public ScriptMethod { + class MethodCameraGetLookAt: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraGetLookAt(LogicMiniScript* miniScript): - ScriptMethod({}, TYPE_VECTOR3), + MethodCameraGetLookAt(LogicMiniScript* miniScript): + Method({}, TYPE_VECTOR3), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.getLookAt"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->context->getEngine()->getCamera()->getLookAt()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraGetLookAt(this)); + registerMethod(new MethodCameraGetLookAt(this)); } { // - class ScriptMethodCameraSetLookAt: public ScriptMethod { + class MethodCameraSetLookAt: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraSetLookAt(LogicMiniScript* miniScript): - ScriptMethod( + MethodCameraSetLookAt(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "lookAt", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.setLookAt"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 lookAt; if (miniScript->getVector3Value(argumentValues, 0, lookAt) == true) { miniScript->context->getEngine()->getCamera()->setLookAt(lookAt); @@ -1886,47 +1886,47 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraSetLookAt(this)); + registerMethod(new MethodCameraSetLookAt(this)); } { // - class ScriptMethodCameraGetUpVector: public ScriptMethod { + class MethodCameraGetUpVector: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraGetUpVector(LogicMiniScript* miniScript): - ScriptMethod({}, TYPE_VECTOR3), + MethodCameraGetUpVector(LogicMiniScript* miniScript): + Method({}, TYPE_VECTOR3), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.getUpVector"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->context->getEngine()->getCamera()->getUpVector()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraGetUpVector(this)); + registerMethod(new MethodCameraGetUpVector(this)); } { // - class ScriptMethodCameraSetUpVector: public ScriptMethod { + class MethodCameraSetUpVector: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraSetUpVector(LogicMiniScript* miniScript): - ScriptMethod( + MethodCameraSetUpVector(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "upVector", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.setUpVector"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 upVector; if (miniScript->getVector3Value(argumentValues, 0, upVector) == true) { miniScript->context->getEngine()->getCamera()->setUpVector(upVector); @@ -1939,16 +1939,16 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraSetUpVector(this)); + registerMethod(new MethodCameraSetUpVector(this)); } { // - class ScriptMethodCameraComputeUpVector: public ScriptMethod { + class MethodCameraComputeUpVector: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraComputeUpVector(LogicMiniScript* miniScript): - ScriptMethod( + MethodCameraComputeUpVector(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "lookFrom", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "lookAt", .optional = false, .reference = false, .nullable = false } @@ -1959,7 +1959,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.camera.computeUpVector"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 lookFrom; Vector3 lookAt; if (miniScript->getVector3Value(argumentValues, 0, lookFrom) == true && @@ -1974,47 +1974,47 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraComputeUpVector(this)); + registerMethod(new MethodCameraComputeUpVector(this)); } { // - class ScriptMethodCameraGetFovX: public ScriptMethod { + class MethodCameraGetFovX: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraGetFovX(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodCameraGetFovX(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.getFovX"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->context->getEngine()->getCamera()->getFovX(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraGetFovX(this)); + registerMethod(new MethodCameraGetFovX(this)); } { // - class ScriptMethodCameraSetFovX: public ScriptMethod { + class MethodCameraSetFovX: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodCameraSetFovX(LogicMiniScript* miniScript): - ScriptMethod( + MethodCameraSetFovX(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_FLOAT, .name = "fovX", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_FLOAT, .name = "fovX", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.camera.setFovX"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { float fovX; if (miniScript->getFloatValue(argumentValues, 0, fovX) == true) { miniScript->context->getEngine()->getCamera()->setFovX(fovX); @@ -2027,112 +2027,112 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodCameraSetFovX(this)); + registerMethod(new MethodCameraSetFovX(this)); } // timing { // - class ScriptMethodTimingGetDeltaTime: public ScriptMethod { + class MethodTimingGetDeltaTime: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodTimingGetDeltaTime(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodTimingGetDeltaTime(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "engine.timing.getDeltaTime"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->context->getEngine()->getTiming()->getDeltaTime(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodTimingGetDeltaTime(this)); + registerMethod(new MethodTimingGetDeltaTime(this)); } { // - class ScriptMethodTimingGetDeltaTimeSeconds: public ScriptMethod { + class MethodTimingGetDeltaTimeSeconds: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodTimingGetDeltaTimeSeconds(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodTimingGetDeltaTimeSeconds(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "engine.timing.getDeltaTimeSeconds"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->context->getEngine()->getTiming()->getDeltaTimeSeconds(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodTimingGetDeltaTimeSeconds(this)); + registerMethod(new MethodTimingGetDeltaTimeSeconds(this)); } { // - class ScriptMethodTimingGetAvarageFPS: public ScriptMethod { + class MethodTimingGetAvarageFPS: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodTimingGetAvarageFPS(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodTimingGetAvarageFPS(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "engine.timing.getAvarageFPS"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->context->getEngine()->getTiming()->getAvarageFPS(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodTimingGetAvarageFPS(this)); + registerMethod(new MethodTimingGetAvarageFPS(this)); } // engine { // - class ScriptMethodEngineGetAnimationComputationReduction1Distance: public ScriptMethod { + class MethodEngineGetAnimationComputationReduction1Distance: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineGetAnimationComputationReduction1Distance(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodEngineGetAnimationComputationReduction1Distance(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "engine.getAnimationComputationReduction1Distance"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, Engine::getAnimationComputationReduction1Distance()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineGetAnimationComputationReduction1Distance(this)); + registerMethod(new MethodEngineGetAnimationComputationReduction1Distance(this)); } { // - class ScriptMethodEngineSetAnimationComputationReduction1Distance: public ScriptMethod { + class MethodEngineSetAnimationComputationReduction1Distance: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineSetAnimationComputationReduction1Distance(LogicMiniScript* miniScript): - ScriptMethod( + MethodEngineSetAnimationComputationReduction1Distance(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_FLOAT, .name = "animationComputationReduction1Distance", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_FLOAT, .name = "animationComputationReduction1Distance", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.setAnimationComputationReduction1Distance"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { float animationComputationReduction1Distance; if (miniScript->getFloatValue(argumentValues, 0, animationComputationReduction1Distance) == true) { Engine::setAnimationComputationReduction1Distance(animationComputationReduction1Distance); @@ -2146,47 +2146,47 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineSetAnimationComputationReduction1Distance(this)); + registerMethod(new MethodEngineSetAnimationComputationReduction1Distance(this)); } { // - class ScriptMethodEngineGetAnimationComputationReduction2Distance: public ScriptMethod { + class MethodEngineGetAnimationComputationReduction2Distance: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineGetAnimationComputationReduction2Distance(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodEngineGetAnimationComputationReduction2Distance(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "engine.getAnimationComputationReduction2Distance"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, Engine::getAnimationComputationReduction2Distance()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineGetAnimationComputationReduction2Distance(this)); + registerMethod(new MethodEngineGetAnimationComputationReduction2Distance(this)); } { // - class ScriptMethodEngineSetAnimationComputationReduction2Distance: public ScriptMethod { + class MethodEngineSetAnimationComputationReduction2Distance: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineSetAnimationComputationReduction2Distance(LogicMiniScript* miniScript): - ScriptMethod( + MethodEngineSetAnimationComputationReduction2Distance(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_FLOAT, .name = "animationComputationReduction2Distance", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_FLOAT, .name = "animationComputationReduction2Distance", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.setAnimationComputationReduction2Distance"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { float animationComputationReduction2Distance; if (miniScript->getFloatValue(argumentValues, 0, animationComputationReduction2Distance) == true) { Engine::setAnimationComputationReduction2Distance(animationComputationReduction2Distance); @@ -2200,111 +2200,111 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineSetAnimationComputationReduction2Distance(this)); + registerMethod(new MethodEngineSetAnimationComputationReduction2Distance(this)); } { // - class ScriptMethodEngineGetWidth: public ScriptMethod { + class MethodEngineGetWidth: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineGetWidth(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodEngineGetWidth(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "engine.getWidth"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->context->getEngine()->getWidth()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineGetWidth(this)); + registerMethod(new MethodEngineGetWidth(this)); } { // - class ScriptMethodEngineGetHeight: public ScriptMethod { + class MethodEngineGetHeight: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineGetHeight(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodEngineGetHeight(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "engine.getHeight"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->context->getEngine()->getHeight()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineGetHeight(this)); + registerMethod(new MethodEngineGetHeight(this)); } { // - class ScriptMethodEngineDumpEntities: public ScriptMethod { + class MethodEngineDumpEntities: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineDumpEntities(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_NULL), + MethodEngineDumpEntities(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_NULL), miniScript(miniScript) {} const string getMethodName() override { return "engine.dumpEntities"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->context->getEngine()->dumpEntities(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineDumpEntities(this)); + registerMethod(new MethodEngineDumpEntities(this)); } { // - class ScriptMethodEngineDumpShaders: public ScriptMethod { + class MethodEngineDumpShaders: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineDumpShaders(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_NULL), + MethodEngineDumpShaders(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_NULL), miniScript(miniScript) {} const string getMethodName() override { return "engine.dumpShaders"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->context->getEngine()->dumpShaders(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineDumpShaders(this)); + registerMethod(new MethodEngineDumpShaders(this)); } { // - class ScriptMethodEngineGetEntityIdByMousePosition: public ScriptMethod { + class MethodEngineGetEntityIdByMousePosition: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineGetEntityIdByMousePosition(LogicMiniScript* miniScript): - ScriptMethod( + MethodEngineGetEntityIdByMousePosition(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "mouseX", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "mouseY", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "mouseX", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "mouseY", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_STRING + VariableType::TYPE_STRING ), miniScript(miniScript) {} const string getMethodName() override { return "engine.getEntityIdByMousePosition"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t mouseX; int64_t mouseY; if (miniScript->getIntegerValue(argumentValues, 0, mouseX) == true && @@ -2320,19 +2320,19 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineGetEntityIdByMousePosition(this)); + registerMethod(new MethodEngineGetEntityIdByMousePosition(this)); } { // - class ScriptMethodEngineComputeWorldCoordinateByMousePosition: public ScriptMethod { + class MethodEngineComputeWorldCoordinateByMousePosition: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineComputeWorldCoordinateByMousePosition(LogicMiniScript* miniScript): - ScriptMethod( + MethodEngineComputeWorldCoordinateByMousePosition(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "mouseX", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "mouseY", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "mouseX", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "mouseY", .optional = false, .reference = false, .nullable = false } }, TYPE_VECTOR3 ), @@ -2340,7 +2340,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.computeWorldCoordinateByMousePosition"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t mouseX; int64_t mouseY; if (miniScript->getIntegerValue(argumentValues, 0, mouseX) == true && @@ -2355,27 +2355,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineComputeWorldCoordinateByMousePosition(this)); + registerMethod(new MethodEngineComputeWorldCoordinateByMousePosition(this)); } { // - class ScriptMethodEngineComputeScreenCoordinateByWorldCoordinate: public ScriptMethod { + class MethodEngineComputeScreenCoordinateByWorldCoordinate: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEngineComputeScreenCoordinateByWorldCoordinate(LogicMiniScript* miniScript): - ScriptMethod( + MethodEngineComputeScreenCoordinateByWorldCoordinate(LogicMiniScript* miniScript): + Method( { { .type = TYPE_VECTOR3, .name = "worldCoodinate", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR2, .name = "screenCoordinate", .optional = false, .reference = true, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "engine.computeScreenCoordinateByWorldCoordinate"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { Vector3 worldCoodinate; if (argumentValues.size() == 2 && miniScript->getVector3Value(argumentValues, 0, worldCoodinate) == true) { @@ -2395,19 +2395,19 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEngineComputeScreenCoordinateByWorldCoordinate(this)); + registerMethod(new MethodEngineComputeScreenCoordinateByWorldCoordinate(this)); } { // - class ScriptMethodEntityGetTransform: public ScriptMethod { + class MethodEntityGetTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, TYPE_TRANSFORM ), @@ -2415,7 +2415,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.entity.getTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2435,28 +2435,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetTransform(this)); + registerMethod(new MethodEntityGetTransform(this)); } { // - class ScriptMethodEntitySetTransform: public ScriptMethod { + class MethodEntitySetTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; Transform transform; string childEntityId; @@ -2478,27 +2478,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetTransform(this)); + registerMethod(new MethodEntitySetTransform(this)); } { // - class ScriptMethodEntityIsEnabled: public ScriptMethod { + class MethodEntityIsEnabled: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityIsEnabled(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityIsEnabled(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.isEnabled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2518,28 +2518,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityIsEnabled(this)); + registerMethod(new MethodEntityIsEnabled(this)); } { // - class ScriptMethodEntitySetEnabled: public ScriptMethod { + class MethodEntitySetEnabled: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetEnabled(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetEnabled(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_BOOLEAN, .name = "enabled", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_BOOLEAN, .name = "enabled", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setEnabled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; bool enabled; string childEntityId; @@ -2561,27 +2561,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetEnabled(this)); + registerMethod(new MethodEntitySetEnabled(this)); } { // - class ScriptMethodEntityIsPickable: public ScriptMethod { + class MethodEntityIsPickable: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityIsPickable(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityIsPickable(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.isPickable"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2601,28 +2601,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityIsPickable(this)); + registerMethod(new MethodEntityIsPickable(this)); } { // - class ScriptMethodEntitySetPickable: public ScriptMethod { + class MethodEntitySetPickable: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetPickable(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetPickable(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_BOOLEAN, .name = "pickable", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_BOOLEAN, .name = "pickable", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setPickable"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; bool pickable; string childEntityId; @@ -2644,19 +2644,19 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetPickable(this)); + registerMethod(new MethodEntitySetPickable(this)); } { // - class ScriptMethodEntityGetEffectColorMul: public ScriptMethod { + class MethodEntityGetEffectColorMul: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetEffectColorMul(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetEffectColorMul(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, TYPE_VECTOR4 ), @@ -2664,7 +2664,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.entity.getEffectColorMul"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2685,28 +2685,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetEffectColorMul(this)); + registerMethod(new MethodEntityGetEffectColorMul(this)); } { // - class ScriptMethodEntitySetEffectColorMul: public ScriptMethod { + class MethodEntitySetEffectColorMul: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetEffectColorMul(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetEffectColorMul(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR4, .name = "effectColorMul", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setEffectColorMul"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; Vector4 effectColorMul; string childEntityId; @@ -2728,19 +2728,19 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetEffectColorMul(this)); + registerMethod(new MethodEntitySetEffectColorMul(this)); } { // - class ScriptMethodEntityGetEffectColorAdd: public ScriptMethod { + class MethodEntityGetEffectColorAdd: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetEffectColorAdd(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetEffectColorAdd(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, TYPE_VECTOR4 ), @@ -2748,7 +2748,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.entity.getEffectColorAdd"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2769,28 +2769,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetEffectColorAdd(this)); + registerMethod(new MethodEntityGetEffectColorAdd(this)); } { // - class ScriptMethodEntitySetEffectColorAdd: public ScriptMethod { + class MethodEntitySetEffectColorAdd: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetEffectColorAdd(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetEffectColorAdd(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR4, .name = "effectColorAdd", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setEffectColorAdd"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; Vector4 effectColorAdd; string childEntityId; @@ -2812,27 +2812,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetEffectColorAdd(this)); + registerMethod(new MethodEntitySetEffectColorAdd(this)); } { // - class ScriptMethodEntityGetAnimation: public ScriptMethod { + class MethodEntityGetAnimation: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetAnimation(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetAnimation(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_STRING + VariableType::TYPE_STRING ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.getAnimation"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2852,29 +2852,29 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetAnimation(this)); + registerMethod(new MethodEntityGetAnimation(this)); } { // - class ScriptMethodEntitySetAnimation: public ScriptMethod { + class MethodEntitySetAnimation: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetAnimation(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetAnimation(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "speed", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "speed", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setAnimation"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string animation; float speed = 1.0f; @@ -2898,28 +2898,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetAnimation(this)); + registerMethod(new MethodEntitySetAnimation(this)); } { // - class ScriptMethodEntitySetAnimationSpeed: public ScriptMethod { + class MethodEntitySetAnimationSpeed: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetAnimationSpeed(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetAnimationSpeed(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "speed", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "speed", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setAnimationSpeed"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; float speed; string childEntityId; @@ -2941,27 +2941,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetAnimationSpeed(this)); + registerMethod(new MethodEntitySetAnimationSpeed(this)); } { // - class ScriptMethodEntityGetAnimationTime: public ScriptMethod { + class MethodEntityGetAnimationTime: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetAnimationTime(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetAnimationTime(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_FLOAT + VariableType::TYPE_FLOAT ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.getAnimationTime"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -2981,28 +2981,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetAnimationTime(this)); + registerMethod(new MethodEntityGetAnimationTime(this)); } { // - class ScriptMethodEntityHasOverlayAnimation: public ScriptMethod { + class MethodEntityHasOverlayAnimation: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityHasOverlayAnimation(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityHasOverlayAnimation(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.hasOverlayAnimation"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string animation; string childEntityId; @@ -3024,28 +3024,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityHasOverlayAnimation(this)); + registerMethod(new MethodEntityHasOverlayAnimation(this)); } { // - class ScriptMethodEntityAddOverlayAnimation: public ScriptMethod { + class MethodEntityAddOverlayAnimation: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityAddOverlayAnimation(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityAddOverlayAnimation(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.addOverlayAnimation"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string animation; string childEntityId; @@ -3067,28 +3067,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityAddOverlayAnimation(this)); + registerMethod(new MethodEntityAddOverlayAnimation(this)); } { // - class ScriptMethodEntityRemoveOverlayAnimation: public ScriptMethod { + class MethodEntityRemoveOverlayAnimation: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityRemoveOverlayAnimation(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityRemoveOverlayAnimation(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.removeOverlayAnimation"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string animation; string childEntityId; @@ -3110,27 +3110,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityRemoveOverlayAnimation(this)); + registerMethod(new MethodEntityRemoveOverlayAnimation(this)); } { // - class ScriptMethodEntityRemoveFinishedOverlayAnimations: public ScriptMethod { + class MethodEntityRemoveFinishedOverlayAnimations: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityRemoveFinishedOverlayAnimations(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityRemoveFinishedOverlayAnimations(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.removeFinishedOverlayAnimations"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -3150,27 +3150,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityRemoveFinishedOverlayAnimations(this)); + registerMethod(new MethodEntityRemoveFinishedOverlayAnimations(this)); } { // - class ScriptMethodEntityRemoveOverlayAnimations: public ScriptMethod { + class MethodEntityRemoveOverlayAnimations: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityRemoveOverlayAnimations(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityRemoveOverlayAnimations(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.removeOverlayAnimations"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -3190,28 +3190,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityRemoveOverlayAnimations(this)); + registerMethod(new MethodEntityRemoveOverlayAnimations(this)); } { // - class ScriptMethodEntityGetOverlayAnimationTime: public ScriptMethod { + class MethodEntityGetOverlayAnimationTime: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetOverlayAnimationTime(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetOverlayAnimationTime(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "animation", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_FLOAT + VariableType::TYPE_FLOAT ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.getOverlayAnimationTime"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string animation; string childEntityId; @@ -3233,20 +3233,20 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetOverlayAnimationTime(this)); + registerMethod(new MethodEntityGetOverlayAnimationTime(this)); } { // - class ScriptMethodEntityGetNodeTransformMatrix: public ScriptMethod { + class MethodEntityGetNodeTransformMatrix: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetNodeTransformMatrix(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetNodeTransformMatrix(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, TYPE_MATRIX4x4 ), @@ -3254,7 +3254,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.entity.getNodeTransformMatrix"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string nodeId; string childEntityId; @@ -3276,20 +3276,20 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetNodeTransformMatrix(this)); + registerMethod(new MethodEntityGetNodeTransformMatrix(this)); } { // - class ScriptMethodEntityGetNodeTransform: public ScriptMethod { + class MethodEntityGetNodeTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityGetNodeTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityGetNodeTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, TYPE_TRANSFORM ), @@ -3297,7 +3297,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "engine.entity.getNodeTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string nodeId; string childEntityId; @@ -3321,29 +3321,29 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityGetNodeTransform(this)); + registerMethod(new MethodEntityGetNodeTransform(this)); } { // - class ScriptMethodEntitySetNodeTransformMatrix: public ScriptMethod { + class MethodEntitySetNodeTransformMatrix: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetNodeTransformMatrix(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetNodeTransformMatrix(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_MATRIX4x4, .name = "matrix", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setNodeTransformMatrix"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string nodeId; Matrix4x4 matrix; @@ -3367,29 +3367,29 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetNodeTransformMatrix(this)); + registerMethod(new MethodEntitySetNodeTransformMatrix(this)); } { // - class ScriptMethodEntitySetNodeTransform: public ScriptMethod { + class MethodEntitySetNodeTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntitySetNodeTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntitySetNodeTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.setNodeTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string nodeId; Transform transform; @@ -3413,28 +3413,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntitySetNodeTransform(this)); + registerMethod(new MethodEntitySetNodeTransform(this)); } { // - class ScriptMethodEntityUnsetNodeTransformMatrix: public ScriptMethod { + class MethodEntityUnsetNodeTransformMatrix: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityUnsetNodeTransformMatrix(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityUnsetNodeTransformMatrix(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.unsetNodeTransformMatrix"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string nodeId; string childEntityId; @@ -3456,28 +3456,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityUnsetNodeTransformMatrix(this)); + registerMethod(new MethodEntityUnsetNodeTransformMatrix(this)); } { // - class ScriptMethodEntityUnsetNodeTransform: public ScriptMethod { + class MethodEntityUnsetNodeTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityUnsetNodeTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityUnsetNodeTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.unsetNodeTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string nodeId; string childEntityId; @@ -3499,27 +3499,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityUnsetNodeTransform(this)); + registerMethod(new MethodEntityUnsetNodeTransform(this)); } { // - class ScriptMethodEntityEmitParticles: public ScriptMethod { + class MethodEntityEmitParticles: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodEntityEmitParticles(LogicMiniScript* miniScript): - ScriptMethod( + MethodEntityEmitParticles(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "entityId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "childEntityId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_INTEGER + VariableType::TYPE_INTEGER ), miniScript(miniScript) {} const string getMethodName() override { return "engine.entity.emitParticles"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string entityId; string childEntityId; if (miniScript->getStringValue(argumentValues, 0, entityId) == true && @@ -3539,468 +3539,468 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_ENGINE; } }; - registerMethod(new ScriptMethodEntityEmitParticles(this)); + registerMethod(new MethodEntityEmitParticles(this)); } // physics { // - class ScriptMethodBodyTYPE_STATIC: public ScriptMethod { + class MethodBodyTYPE_STATIC: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyTYPE_STATIC(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyTYPE_STATIC(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.TYPE_STATIC"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::BODYTYPE_STATIC); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyTYPE_STATIC(this)); + registerMethod(new MethodBodyTYPE_STATIC(this)); } { // - class ScriptMethodBodyTYPE_DYNAMIC: public ScriptMethod { + class MethodBodyTYPE_DYNAMIC: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyTYPE_DYNAMIC(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyTYPE_DYNAMIC(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.TYPE_DYNAMIC"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::BODYTYPE_DYNAMIC); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyTYPE_DYNAMIC(this)); + registerMethod(new MethodBodyTYPE_DYNAMIC(this)); } { // - class ScriptMethodBodyTYPE_COLLISIONSTATIC: public ScriptMethod { + class MethodBodyTYPE_COLLISIONSTATIC: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyTYPE_COLLISIONSTATIC(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyTYPE_COLLISIONSTATIC(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.TYPE_COLLISION_STATIC"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::BODYTYPE_COLLISION_STATIC); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyTYPE_COLLISIONSTATIC(this)); + registerMethod(new MethodBodyTYPE_COLLISIONSTATIC(this)); } { // - class ScriptMethodBodyTYPE_COLLISIONDYNAMIC: public ScriptMethod { + class MethodBodyTYPE_COLLISIONDYNAMIC: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyTYPE_COLLISIONDYNAMIC(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyTYPE_COLLISIONDYNAMIC(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.TYPE_COLLISION_DYNAMIC"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::BODYTYPE_COLLISION_DYNAMIC); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyTYPE_COLLISIONDYNAMIC(this)); + registerMethod(new MethodBodyTYPE_COLLISIONDYNAMIC(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_STATIC: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_STATIC: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_STATIC(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_STATIC(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_STATIC"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_STATIC); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_STATIC(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_STATIC(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_DYNAMIC: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_DYNAMIC: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_DYNAMIC(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_DYNAMIC(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_DYNAMIC"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_DYNAMIC); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_DYNAMIC(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_DYNAMIC(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_3: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_3: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_3(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_3(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_3"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_3); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_3(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_3(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_4: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_4: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_4(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_4(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_4"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_4); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_4(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_4(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_5: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_5: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_5(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_5(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_5"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_5); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_5(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_5(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_6: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_6: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_6(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_6(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_6"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_6); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_6(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_6(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_7: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_7: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_7(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_7(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_7"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_7); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_7(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_7(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_8: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_8: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_8(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_8(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_8"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_8); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_8(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_8(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_9: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_9: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_9(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_9(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_9"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_9); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_9(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_9(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_10: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_10: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_10(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_10(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_10"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_10); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_10(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_10(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_11: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_11: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_11(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_11(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_11"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_11); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_11(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_11(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_12: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_12: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_12(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_12(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_12"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_12); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_12(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_12(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_13: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_13: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_13(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_13(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_13"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_13); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_13(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_13(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_14: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_14: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_14(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_14(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_14"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_14); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_14(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_14(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_15: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_15: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_15(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_15(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_15"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_15); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_15(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_15(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_16: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_16: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_16(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_16(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_16"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_16); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_16(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_16(this)); } { // - class ScriptMethodBodyCOLLISION_TYPEID_ALL: public ScriptMethod { + class MethodBodyCOLLISION_TYPEID_ALL: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyCOLLISION_TYPEID_ALL(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodBodyCOLLISION_TYPEID_ALL(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "world.body.COLLISION_TYPEID_ALL"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Body::COLLISION_TYPEID_ALL); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyCOLLISION_TYPEID_ALL(this)); + registerMethod(new MethodBodyCOLLISION_TYPEID_ALL(this)); } { // - class ScriptMethodBodyIsEnabled: public ScriptMethod { + class MethodBodyIsEnabled: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyIsEnabled(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyIsEnabled(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.isEnabled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4018,27 +4018,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyIsEnabled(this)); + registerMethod(new MethodBodyIsEnabled(this)); } { // - class ScriptMethodBodySetEnabled: public ScriptMethod { + class MethodBodySetEnabled: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetEnabled(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetEnabled(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_BOOLEAN, .name = "enabled", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_BOOLEAN, .name = "enabled", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setEnabled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; bool enabled; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4058,26 +4058,26 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetEnabled(this)); + registerMethod(new MethodBodySetEnabled(this)); } { // - class ScriptMethodBodyGetType: public ScriptMethod { + class MethodBodyGetType: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetType(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetType(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_INTEGER + VariableType::TYPE_INTEGER ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.getType"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4095,26 +4095,26 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetType(this)); + registerMethod(new MethodBodyGetType(this)); } { // - class ScriptMethodBodyGetCollisionTypeId: public ScriptMethod { + class MethodBodyGetCollisionTypeId: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetCollisionTypeId(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetCollisionTypeId(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_INTEGER + VariableType::TYPE_INTEGER ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.getCollisionTypeId"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4132,27 +4132,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetCollisionTypeId(this)); + registerMethod(new MethodBodyGetCollisionTypeId(this)); } { // - class ScriptMethodBodySetCollisionTypeId: public ScriptMethod { + class MethodBodySetCollisionTypeId: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetCollisionTypeId(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetCollisionTypeId(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "collisionTypeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "collisionTypeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setCollisionTypeId"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; int64_t collisionTypeId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4172,26 +4172,26 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetCollisionTypeId(this)); + registerMethod(new MethodBodySetCollisionTypeId(this)); } { // - class ScriptMethodBodyGetCollisionTypeIds: public ScriptMethod { + class MethodBodyGetCollisionTypeIds: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetCollisionTypeIds(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetCollisionTypeIds(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_INTEGER + VariableType::TYPE_INTEGER ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.getCollisionTypeIds"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4209,27 +4209,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetCollisionTypeIds(this)); + registerMethod(new MethodBodyGetCollisionTypeIds(this)); } { // - class ScriptMethodBodySetCollisionTypeIds: public ScriptMethod { + class MethodBodySetCollisionTypeIds: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetCollisionTypeIds(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetCollisionTypeIds(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setCollisionTypeIds"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; int64_t collisionTypeIds; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4249,26 +4249,26 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetCollisionTypeIds(this)); + registerMethod(new MethodBodySetCollisionTypeIds(this)); } { // - class ScriptMethodBodyGetLinearDamping: public ScriptMethod { + class MethodBodyGetLinearDamping: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetLinearDamping(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetLinearDamping(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_FLOAT + VariableType::TYPE_FLOAT ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.getLinearDamping"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4286,27 +4286,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetLinearDamping(this)); + registerMethod(new MethodBodyGetLinearDamping(this)); } { // - class ScriptMethodBodySetLinearDamping: public ScriptMethod { + class MethodBodySetLinearDamping: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetLinearDamping(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetLinearDamping(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "linearDamping", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "linearDamping", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setLinearDamping"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; float linearDamping; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4326,26 +4326,26 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetLinearDamping(this)); + registerMethod(new MethodBodySetLinearDamping(this)); } { // - class ScriptMethodBodyGetAngularDamping: public ScriptMethod { + class MethodBodyGetAngularDamping: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetAngularDamping(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetAngularDamping(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_FLOAT + VariableType::TYPE_FLOAT ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.getAngularDamping"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4363,27 +4363,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetAngularDamping(this)); + registerMethod(new MethodBodyGetAngularDamping(this)); } { // - class ScriptMethodBodySetAngularDamping: public ScriptMethod { + class MethodBodySetAngularDamping: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetAngularDamping(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetAngularDamping(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "angularDamping", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "angularDamping", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setAngularDamping"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; float angularDamping; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4403,18 +4403,18 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetAngularDamping(this)); + registerMethod(new MethodBodySetAngularDamping(this)); } { // - class ScriptMethodBodyGetLinearVelocity: public ScriptMethod { + class MethodBodyGetLinearVelocity: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetLinearVelocity(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetLinearVelocity(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, TYPE_VECTOR3 ), @@ -4422,7 +4422,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "world.body.getLinearVelocity"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4440,27 +4440,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetLinearVelocity(this)); + registerMethod(new MethodBodyGetLinearVelocity(this)); } { // - class ScriptMethodBodySetLinearVelocity: public ScriptMethod { + class MethodBodySetLinearVelocity: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetLinearVelocity(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetLinearVelocity(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "linearVelocity", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setLinearVelocity"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; Vector3 linearVelocity; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4480,18 +4480,18 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetLinearVelocity(this)); + registerMethod(new MethodBodySetLinearVelocity(this)); } { // - class ScriptMethodBodyGetAngularVelocity: public ScriptMethod { + class MethodBodyGetAngularVelocity: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetAngularVelocity(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetAngularVelocity(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, TYPE_VECTOR3 ), @@ -4499,7 +4499,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "world.body.getAngularVelocity"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4517,27 +4517,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetAngularVelocity(this)); + registerMethod(new MethodBodyGetAngularVelocity(this)); } { // - class ScriptMethodBodySetAngularVelocity: public ScriptMethod { + class MethodBodySetAngularVelocity: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetAngularVelocity(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetAngularVelocity(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "angularVelocity", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setAngularVelocity"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; Vector3 angularVelocity; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4557,28 +4557,28 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetAngularVelocity(this)); + registerMethod(new MethodBodySetAngularVelocity(this)); } { // - class ScriptMethodBodyAddForce: public ScriptMethod { + class MethodBodyAddForce: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyAddForce(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyAddForce(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "force", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "origin", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.addForce"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; Vector3 force; Vector3 forceOrigin; @@ -4608,27 +4608,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyAddForce(this)); + registerMethod(new MethodBodyAddForce(this)); } { // - class ScriptMethodBodyAddTorque: public ScriptMethod { + class MethodBodyAddTorque: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyAddTorque(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyAddTorque(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "torque", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.addTorque"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; Vector3 torque; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4648,18 +4648,18 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyAddTorque(this)); + registerMethod(new MethodBodyAddTorque(this)); } { // - class ScriptMethodBodyGetTransform: public ScriptMethod { + class MethodBodyGetTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodyGetTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodyGetTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, TYPE_TRANSFORM ), @@ -4667,7 +4667,7 @@ void LogicMiniScript::registerMethods() { const string getMethodName() override { return "world.body.getTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true) { auto body = miniScript->context->getWorld()->getBody(bodyId); @@ -4697,27 +4697,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodyGetTransform(this)); + registerMethod(new MethodBodyGetTransform(this)); } { // - class ScriptMethodBodySetTransform: public ScriptMethod { + class MethodBodySetTransform: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodBodySetTransform(LogicMiniScript* miniScript): - ScriptMethod( + MethodBodySetTransform(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "world.body.setTransform"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId; Transform transform; if (miniScript->getStringValue(argumentValues, 0, bodyId) == true && @@ -4737,32 +4737,32 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodBodySetTransform(this)); + registerMethod(new MethodBodySetTransform(this)); } { // - class ScriptMethodWorldDetermineHeight: public ScriptMethod { + class MethodWorldDetermineHeight: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodWorldDetermineHeight(LogicMiniScript* miniScript): - ScriptMethod( + MethodWorldDetermineHeight(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "stepUpMax", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "stepUpMax", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "point", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "heightPoint", .optional = false, .reference = true, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = true, .reference = true, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "minHeight", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_FLOAT, .name = "maxHeight", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = true, .reference = true, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "minHeight", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_FLOAT, .name = "maxHeight", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "world.determineHeight"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t collisionTypeIds; float stepUpMax; Vector3 point; @@ -4792,31 +4792,31 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodWorldDetermineHeight(this)); + registerMethod(new MethodWorldDetermineHeight(this)); } { // - class ScriptMethodWorldDoRayCasting: public ScriptMethod { + class MethodWorldDoRayCasting: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodWorldDoRayCasting(LogicMiniScript* miniScript): - ScriptMethod( + MethodWorldDoRayCasting(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "start", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "end", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "hitPoint", .optional = false, .reference = true, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = true, .reference = true, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "actorId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = true, .reference = true, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "actorId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "world.doRayCasting"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t collisionTypeIds; Vector3 start; Vector3 end; @@ -4843,27 +4843,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodWorldDoRayCasting(this)); + registerMethod(new MethodWorldDoRayCasting(this)); } { // - class ScriptMethodWorldDoCollide: public ScriptMethod { + class MethodWorldDoCollide: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodWorldDoCollide(LogicMiniScript* miniScript): - ScriptMethod( + MethodWorldDoCollide(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId1", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId2", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "bodyId1", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId2", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "world.doCollide"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string bodyId1; string bodyId2; if (miniScript->getStringValue(argumentValues, 0, bodyId1) == true && @@ -4887,27 +4887,27 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodWorldDoCollide(this)); + registerMethod(new MethodWorldDoCollide(this)); } { // - class ScriptMethodWorldDoesCollideWith: public ScriptMethod { + class MethodWorldDoesCollideWith: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodWorldDoesCollideWith(LogicMiniScript* miniScript): - ScriptMethod( + MethodWorldDoesCollideWith(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "collisionTypeIds", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "bodyId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_ARRAY + VariableType::TYPE_ARRAY ), miniScript(miniScript) {} const string getMethodName() override { return "world.doesCollideWith"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t collisionTypeIds; string bodyId; if (miniScript->getIntegerValue(argumentValues, 0, collisionTypeIds) == true && @@ -4932,156 +4932,156 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodWorldDoesCollideWith(this)); + registerMethod(new MethodWorldDoesCollideWith(this)); } // path finding { // - class ScriptMethodPathFindingSTATE_IDLE: public ScriptMethod { + class MethodPathFindingSTATE_IDLE: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingSTATE_IDLE(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodPathFindingSTATE_IDLE(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.STATE_IDLE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Context::PathFindingThread::STATE_IDLE); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingSTATE_IDLE(this)); + registerMethod(new MethodPathFindingSTATE_IDLE(this)); } { // - class ScriptMethodPathFindingSTATE_TRYLOCK_FAILED: public ScriptMethod { + class MethodPathFindingSTATE_TRYLOCK_FAILED: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingSTATE_TRYLOCK_FAILED(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodPathFindingSTATE_TRYLOCK_FAILED(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.STATE_TRYLOCK_FAILED"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Context::PathFindingThread::STATE_TRYLOCK_FAILED); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingSTATE_TRYLOCK_FAILED(this)); + registerMethod(new MethodPathFindingSTATE_TRYLOCK_FAILED(this)); } { // - class ScriptMethodPathFindingSTATE_PATHFINDING_OTHER: public ScriptMethod { + class MethodPathFindingSTATE_PATHFINDING_OTHER: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingSTATE_PATHFINDING_OTHER(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodPathFindingSTATE_PATHFINDING_OTHER(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.STATE_PATHFINDING_OTHER"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Context::PathFindingThread::STATE_PATHFINDING_OTHER); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingSTATE_PATHFINDING_OTHER(this)); + registerMethod(new MethodPathFindingSTATE_PATHFINDING_OTHER(this)); } { // - class ScriptMethodPathFindingSTATE_PATHFINDING: public ScriptMethod { + class MethodPathFindingSTATE_PATHFINDING: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingSTATE_PATHFINDING(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodPathFindingSTATE_PATHFINDING(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.STATE_PATHFINDING"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Context::PathFindingThread::STATE_PATHFINDING); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingSTATE_PATHFINDING(this)); + registerMethod(new MethodPathFindingSTATE_PATHFINDING(this)); } { // - class ScriptMethodPathFindingSTATE_PATHFINDING_FAILED: public ScriptMethod { + class MethodPathFindingSTATE_PATHFINDING_FAILED: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingSTATE_PATHFINDING_FAILED(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodPathFindingSTATE_PATHFINDING_FAILED(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.STATE_PATHFINDING_FAILED"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Context::PathFindingThread::STATE_PATHFINDING_FAILED); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingSTATE_PATHFINDING_FAILED(this)); + registerMethod(new MethodPathFindingSTATE_PATHFINDING_FAILED(this)); } { // - class ScriptMethodPathFindingSTATE_PATHFINDING_SUCCESS: public ScriptMethod { + class MethodPathFindingSTATE_PATHFINDING_SUCCESS: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingSTATE_PATHFINDING_SUCCESS(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodPathFindingSTATE_PATHFINDING_SUCCESS(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.STATE_PATHFINDING_SUCCESS"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(Context::PathFindingThread::STATE_PATHFINDING_SUCCESS); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingSTATE_PATHFINDING_SUCCESS(this)); + registerMethod(new MethodPathFindingSTATE_PATHFINDING_SUCCESS(this)); } { // - class ScriptMethodPathFindingFindPath: public ScriptMethod { + class MethodPathFindingFindPath: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodPathFindingFindPath(LogicMiniScript* miniScript): - ScriptMethod( + MethodPathFindingFindPath(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "startPosition", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "endPosition", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_ARRAY, .name = "path", .optional = false, .reference = true, .nullable = false }, + { .type = VariableType::TYPE_ARRAY, .name = "path", .optional = false, .reference = true, .nullable = false }, }, - ScriptVariableType::TYPE_INTEGER + VariableType::TYPE_INTEGER ), miniScript(miniScript) {} const string getMethodName() override { return "pathfinding.findPath"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string logicId; Vector3 startPosition; Vector3 endPosition; @@ -5094,7 +5094,7 @@ void LogicMiniScript::registerMethods() { auto pathFindingState = miniScript->context->getPathFinding()->findPath(logicId, logicId, startPosition, endPosition, path); returnValue = static_cast(pathFindingState); for (const auto& position: path) { - MiniScript::ScriptVariable positionVariable; + MiniScript::Variable positionVariable; miniScript->setValue(positionVariable, position); argumentValues[3].pushArrayEntry(positionVariable); }; @@ -5107,96 +5107,96 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodPathFindingFindPath(this)); + registerMethod(new MethodPathFindingFindPath(this)); } // scene { // - class ScriptMethodSceneGetWidth: public ScriptMethod { + class MethodSceneGetWidth: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodSceneGetWidth(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodSceneGetWidth(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "scene.getWidth"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->setValue(returnValue, miniScript->context->getScene()->getBoundingBox()->getDimensions().getX()); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodSceneGetWidth(this)); + registerMethod(new MethodSceneGetWidth(this)); } { // - class ScriptMethodSceneGetHeight: public ScriptMethod { + class MethodSceneGetHeight: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodSceneGetHeight(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodSceneGetHeight(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "scene.getHeight"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->context->getScene()->getBoundingBox()->getDimensions().getY(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodSceneGetHeight(this)); + registerMethod(new MethodSceneGetHeight(this)); } { // - class ScriptMethodSceneGetDepth: public ScriptMethod { + class MethodSceneGetDepth: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodSceneGetDepth(LogicMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodSceneGetDepth(LogicMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "scene.getDepth"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->context->getScene()->getBoundingBox()->getDimensions().getZ(); } const vector& getContextFunctions() { return CONTEXTFUNCTIONS_ALL; } }; - registerMethod(new ScriptMethodSceneGetDepth(this)); + registerMethod(new MethodSceneGetDepth(this)); } // sceneconnector { // - class ScriptMethodSceneConnectorSpawnPrototype: public ScriptMethod { + class MethodSceneConnectorSpawnPrototype: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodSceneConnectorSpawnPrototype(LogicMiniScript* miniScript): - ScriptMethod( + MethodSceneConnectorSpawnPrototype(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "hierarchyId", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "hierarchyParentId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "hierarchyId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "hierarchyParentId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "sceneconnector.spawnPrototype"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string pathName; string fileName; string id; @@ -5248,7 +5248,7 @@ void LogicMiniScript::registerMethods() { ); } catch (Exception& exception) { miniScript->prototypesToAddMutex.unlock(); - Console::println("ScriptMethodSceneConnectorSpawnPrototype::executeMethod(): An error occurred: " + string(exception.what())); + Console::println("MethodSceneConnectorSpawnPrototype::executeMethod(): An error occurred: " + string(exception.what())); miniScript->startErrorScript(); } miniScript->prototypesToAddMutex.unlock(); @@ -5261,31 +5261,31 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodSceneConnectorSpawnPrototype(this)); + registerMethod(new MethodSceneConnectorSpawnPrototype(this)); } { // - class ScriptMethodSceneConnectorAttachPrototype: public ScriptMethod { + class MethodSceneConnectorAttachPrototype: public Method { private: LogicMiniScript* miniScript { nullptr }; public: - ScriptMethodSceneConnectorAttachPrototype(LogicMiniScript* miniScript): - ScriptMethod( + MethodSceneConnectorAttachPrototype(LogicMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "attachNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "pathName", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "id", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "attachNodeId", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "parentId", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "parentId", .optional = true, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "sceneconnector.attachPrototype"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string pathName; string fileName; string id; @@ -5337,7 +5337,7 @@ void LogicMiniScript::registerMethods() { ); } catch (Exception& exception) { miniScript->prototypesToAddMutex.unlock(); - Console::println("ScriptMethodSceneConnectorAttachPrototype::executeMethod(): An error occurred: " + string(exception.what())); + Console::println("MethodSceneConnectorAttachPrototype::executeMethod(): An error occurred: " + string(exception.what())); miniScript->startErrorScript(); } miniScript->prototypesToAddMutex.unlock(); @@ -5350,7 +5350,7 @@ void LogicMiniScript::registerMethods() { return CONTEXTFUNCTIONS_LOGIC; } }; - registerMethod(new ScriptMethodSceneConnectorAttachPrototype(this)); + registerMethod(new MethodSceneConnectorAttachPrototype(this)); } } diff --git a/src/tdme/engine/logics/MiniScriptLogic.h b/src/tdme/engine/logics/MiniScriptLogic.h index 4d1cd92b6..b3b59c441 100644 --- a/src/tdme/engine/logics/MiniScriptLogic.h +++ b/src/tdme/engine/logics/MiniScriptLogic.h @@ -177,8 +177,8 @@ class tdme::engine::logics::MiniScriptLogic: public Logic { SceneConnector::addSounds(context->getAudio(), prototypeIt->second, id); } // execute initializeEngine() function - vector argumentValues(0); - EngineMiniScript::ScriptVariable returnValue; + vector argumentValues(0); + EngineMiniScript::Variable returnValue; span argumentValuesSpan(argumentValues); if (miniScript->call("initializeEngine", argumentValuesSpan, returnValue) == false) { // Console::println("MiniScriptLogic::updateEngine(): Failed to call initializeEngine() function"); @@ -187,8 +187,8 @@ class tdme::engine::logics::MiniScriptLogic: public Logic { engineInitialized = true; } // execute updateEngine() function - vector argumentValues(0); - EngineMiniScript::ScriptVariable returnValue; + vector argumentValues(0); + EngineMiniScript::Variable returnValue; span argumentValuesSpan(argumentValues); if (miniScript->call("updateEngine", argumentValuesSpan, returnValue) == false) { // Console::println("MiniScriptLogic::updateEngine(): Failed to call updateEngine() function"); @@ -288,8 +288,8 @@ class tdme::engine::logics::MiniScriptLogic: public Logic { // if (logicInitialized == false) { // execute initializeLogic() function - vector argumentValues(0); - EngineMiniScript::ScriptVariable returnValue; + vector argumentValues(0); + EngineMiniScript::Variable returnValue; span argumentValuesSpan(argumentValues); if (miniScript->call("initializeLogic", argumentValuesSpan, returnValue) == false) { // Console::println("MiniScriptLogic::updateLogic(): Failed to call initializeLogic() function"); @@ -300,8 +300,8 @@ class tdme::engine::logics::MiniScriptLogic: public Logic { // execute on: nothing and other event polling and execution miniScript->execute(); // execute updateLogic() function - vector argumentValues(0); - EngineMiniScript::ScriptVariable returnValue; + vector argumentValues(0); + EngineMiniScript::Variable returnValue; span argumentValuesSpan(argumentValues); if (miniScript->call("updateLogic", argumentValuesSpan, returnValue) == false) { // Console::println("MiniScriptLogic::updateLogic(): Failed to call updateLogic() function"); @@ -310,8 +310,8 @@ class tdme::engine::logics::MiniScriptLogic: public Logic { inline void onLogicAdded() override { // execute onLogicAdded() function - vector argumentValues(0); - EngineMiniScript::ScriptVariable returnValue; + vector argumentValues(0); + EngineMiniScript::Variable returnValue; span argumentValuesSpan(argumentValues); if (miniScript->call("onLogicAdded", argumentValuesSpan, returnValue) == false) { // Console::println("MiniScriptLogic::onLogicAdded(): Failed to call onLogicAdded() function"); @@ -320,8 +320,8 @@ class tdme::engine::logics::MiniScriptLogic: public Logic { inline void onLogicsProcessed() override { // execute onLogicsProcessed() function - vector argumentValues(0); - EngineMiniScript::ScriptVariable returnValue; + vector argumentValues(0); + EngineMiniScript::Variable returnValue; span argumentValuesSpan(argumentValues); if (miniScript->call("onLogicsProcessed", argumentValuesSpan, returnValue) == false) { // Console::println("MiniScriptLogic::onLogicsProcessed(): Failed to call onLogicsProcessed() function"); diff --git a/src/tdme/gui/GUIParser.cpp b/src/tdme/gui/GUIParser.cpp index 801473fef..b6005354b 100644 --- a/src/tdme/gui/GUIParser.cpp +++ b/src/tdme/gui/GUIParser.cpp @@ -184,12 +184,12 @@ const string GUIParser::getRootNode(const string& xml) { return rootNode; } -GUIScreenNode* GUIParser::parse(const string& pathName, const string& fileName, const unordered_map& variables, const MiniScript::ScriptVariable& miniScriptArguments, Context* context) +GUIScreenNode* GUIParser::parse(const string& pathName, const string& fileName, const unordered_map& variables, const MiniScript::Variable& miniScriptArguments, Context* context) { return parse(FileSystem::getInstance()->getContentAsString(pathName, fileName), variables, pathName, fileName, miniScriptArguments, context); } -GUIScreenNode* GUIParser::parse(const string& xml, const unordered_map& variables, const string& pathName, const string& fileName, const MiniScript::ScriptVariable& miniScriptArguments, Context* context) +GUIScreenNode* GUIParser::parse(const string& xml, const unordered_map& variables, const string& pathName, const string& fileName, const MiniScript::Variable& miniScriptArguments, Context* context) { auto applicationRootPath = Tools::getApplicationRootPathName(pathName); auto applicationSubPathName = Tools::getApplicationSubPathName(pathName); diff --git a/src/tdme/gui/GUIParser.h b/src/tdme/gui/GUIParser.h index 8a0bd279f..28912978c 100644 --- a/src/tdme/gui/GUIParser.h +++ b/src/tdme/gui/GUIParser.h @@ -89,7 +89,7 @@ class tdme::gui::GUIParser final * @throws tdme::gui::GUIParserException * @throws tdme::os::filesystem::FileSystemException */ - static GUIScreenNode* parse(const string& pathName, const string& fileName, const unordered_map& variables = {}, const EngineMiniScript::ScriptVariable& miniScriptArguments = EngineMiniScript::ScriptVariable(), Context* context = nullptr); + static GUIScreenNode* parse(const string& pathName, const string& fileName, const unordered_map& variables = {}, const EngineMiniScript::Variable& miniScriptArguments = EngineMiniScript::Variable(), Context* context = nullptr); /** * Parses a GUI XML content @@ -103,7 +103,7 @@ class tdme::gui::GUIParser final * @throws tdme::gui::GUIParserException * @throws tdme::os::filesystem::FileSystemException */ - static GUIScreenNode* parse(const string& xml, const unordered_map& variables = {}, const string& pathName = string(), const string& fileName = string(), const EngineMiniScript::ScriptVariable& miniScriptArguments = EngineMiniScript::ScriptVariable(), Context* context = nullptr); + static GUIScreenNode* parse(const string& xml, const unordered_map& variables = {}, const string& pathName = string(), const string& fileName = string(), const EngineMiniScript::Variable& miniScriptArguments = EngineMiniScript::Variable(), Context* context = nullptr); /** * Parses a GUI XML file into parent node diff --git a/src/tdme/gui/nodes/GUIScreenNode.cpp b/src/tdme/gui/nodes/GUIScreenNode.cpp index 6f96b1f63..03311edc8 100644 --- a/src/tdme/gui/nodes/GUIScreenNode.cpp +++ b/src/tdme/gui/nodes/GUIScreenNode.cpp @@ -117,7 +117,7 @@ GUIScreenNode::GUIScreenNode( bool scrollable, bool popUp, const string& scriptFileName, - const EngineMiniScript::ScriptVariable& miniScriptArguments, + const EngineMiniScript::Variable& miniScriptArguments, Context* context ): GUIParentNode(this, nullptr, id, flow, overflowX, overflowY, alignments, requestedConstraints, backgroundColor, backgroundImage, backgroundImageScale9Grid, backgroundImageEffectColorMul, backgroundImageEffectColorAdd, border, padding, showOn, hideOn, tooltip) @@ -216,9 +216,9 @@ GUIScreenNode::~GUIScreenNode() { void GUIScreenNode::initializeMiniScript() { // if (script != nullptr && script->hasFunction("initialize") == true) { - vector argumentValues { miniScriptArguments }; + vector argumentValues { miniScriptArguments }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("initialize", argumentValuesSpan, returnValue); } } @@ -786,9 +786,9 @@ void GUIScreenNode::tick() { } // if (scriptOnTickAvailable == true) { - vector argumentValues(0); + vector argumentValues(0); span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onTick", argumentValuesSpan, returnValue); } } @@ -915,12 +915,12 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnActionAvailable == true) { - vector argumentValues { + vector argumentValues { static_cast(event.type), event.nodeId }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onAction", argumentValuesSpan, returnValue); } // @@ -935,11 +935,11 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnChangeAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onChange", argumentValuesSpan, returnValue); } // @@ -954,11 +954,11 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnMouseOverAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onMouseOver", argumentValuesSpan, returnValue); } // @@ -973,13 +973,13 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnContextMenuRequestAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId, static_cast(event.mouseX), static_cast(event.mouseY) }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onContextMenuRequest", argumentValuesSpan, returnValue); } // @@ -994,11 +994,11 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnFocusAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onFocus", argumentValuesSpan, returnValue); } // @@ -1013,11 +1013,11 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnUnfocusAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onUnfocus", argumentValuesSpan, returnValue); } // @@ -1032,11 +1032,11 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnMoveAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onMove", argumentValuesSpan, returnValue); } // @@ -1051,13 +1051,13 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnMoveReleaseAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId, static_cast(event.mouseX), static_cast(event.mouseY) }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onMoveRelease", argumentValuesSpan, returnValue); } // @@ -1072,13 +1072,13 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnTooltipShowRequestAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId, static_cast(event.mouseX), static_cast(event.mouseY) }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onTooltipShowRequest", argumentValuesSpan, returnValue); } // @@ -1091,9 +1091,9 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnTooltipCloseRequestAvailable == true) { - vector argumentValues(0); + vector argumentValues(0); span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onTooltipCloseRequest", argumentValuesSpan, returnValue); } // @@ -1109,13 +1109,13 @@ void GUIScreenNode::forwardEvents() { } // if (scriptOnDragRequestAvailable == true) { - vector argumentValues { + vector argumentValues { event.nodeId, static_cast(event.mouseX), static_cast(event.mouseY) }; span argumentValuesSpan(argumentValues); - EngineMiniScript::ScriptVariable returnValue; + EngineMiniScript::Variable returnValue; script->call("onDragRequest", argumentValuesSpan, returnValue); } // diff --git a/src/tdme/gui/nodes/GUIScreenNode.h b/src/tdme/gui/nodes/GUIScreenNode.h index b58471d68..a312f5075 100644 --- a/src/tdme/gui/nodes/GUIScreenNode.h +++ b/src/tdme/gui/nodes/GUIScreenNode.h @@ -179,7 +179,7 @@ class tdme::gui::nodes::GUIScreenNode final bool scriptOnDragRequestAvailable { false }; bool scriptOnTickAvailable { false }; - EngineMiniScript::ScriptVariable miniScriptArguments; + EngineMiniScript::Variable miniScriptArguments; Context* context { nullptr }; @@ -385,7 +385,7 @@ class tdme::gui::nodes::GUIScreenNode final bool scrollable, bool popUp, const string& scriptFileName, - const EngineMiniScript::ScriptVariable& miniScriptArguments, + const EngineMiniScript::Variable& miniScriptArguments, Context* context ); diff --git a/src/tdme/gui/scripting/GUIMiniScript.cpp b/src/tdme/gui/scripting/GUIMiniScript.cpp index b0dfe1554..f00bf127d 100644 --- a/src/tdme/gui/scripting/GUIMiniScript.cpp +++ b/src/tdme/gui/scripting/GUIMiniScript.cpp @@ -88,547 +88,547 @@ void GUIMiniScript::registerMethods() { // input { // - class ScriptMethodInputKeyboardKEYCODE_LEFT: public ScriptMethod { + class MethodInputKeyboardKEYCODE_LEFT: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_LEFT(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_LEFT(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_LEFT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_LEFT); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_LEFT(this)); + registerMethod(new MethodInputKeyboardKEYCODE_LEFT(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_RIGHT: public ScriptMethod { + class MethodInputKeyboardKEYCODE_RIGHT: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_RIGHT(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_RIGHT(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_RIGHT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_RIGHT); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_RIGHT(this)); + registerMethod(new MethodInputKeyboardKEYCODE_RIGHT(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_UP: public ScriptMethod { + class MethodInputKeyboardKEYCODE_UP: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_UP(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_UP(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_UP"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_UP); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_UP(this)); + registerMethod(new MethodInputKeyboardKEYCODE_UP(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_DOWN: public ScriptMethod { + class MethodInputKeyboardKEYCODE_DOWN: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_DOWN(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_DOWN(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_DOWN"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_DOWN); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_DOWN(this)); + registerMethod(new MethodInputKeyboardKEYCODE_DOWN(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_POS1: public ScriptMethod { + class MethodInputKeyboardKEYCODE_POS1: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_POS1(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_POS1(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_POS1"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_POS1); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_POS1(this)); + registerMethod(new MethodInputKeyboardKEYCODE_POS1(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_END: public ScriptMethod { + class MethodInputKeyboardKEYCODE_END: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_END(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_END(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_END"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_END); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_END(this)); + registerMethod(new MethodInputKeyboardKEYCODE_END(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_PAGEUP: public ScriptMethod { + class MethodInputKeyboardKEYCODE_PAGEUP: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_PAGEUP(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_PAGEUP(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_PAGEUP"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_PAGE_UP); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_PAGEUP(this)); + registerMethod(new MethodInputKeyboardKEYCODE_PAGEUP(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_PAGEDOWN: public ScriptMethod { + class MethodInputKeyboardKEYCODE_PAGEDOWN: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_PAGEDOWN(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_PAGEDOWN(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_PAGEDOWN"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_PAGE_DOWN); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_PAGEDOWN(this)); + registerMethod(new MethodInputKeyboardKEYCODE_PAGEDOWN(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_BACKSPACE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_BACKSPACE: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_BACKSPACE(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_BACKSPACE(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_BACKSPACE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_BACKSPACE); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_BACKSPACE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_BACKSPACE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_DELETE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_DELETE: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_DELETE(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_DELETE(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_DELETE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_DELETE); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_DELETE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_DELETE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_SPACE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_SPACE: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_SPACE(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_SPACE(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_SPACE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_SPACE); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_SPACE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_SPACE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_RETURN: public ScriptMethod { + class MethodInputKeyboardKEYCODE_RETURN: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_RETURN(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_RETURN(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_RETURN"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_RETURN); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_RETURN(this)); + registerMethod(new MethodInputKeyboardKEYCODE_RETURN(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_ESCAPE: public ScriptMethod { + class MethodInputKeyboardKEYCODE_ESCAPE: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_ESCAPE(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_ESCAPE(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_ESCAPE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_ESCAPE); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_ESCAPE(this)); + registerMethod(new MethodInputKeyboardKEYCODE_ESCAPE(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F1: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F1: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F1(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F1(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F1"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F1); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F1(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F1(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F2: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F2: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F2(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F2(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F2"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F2); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F2(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F2(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F3: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F3: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F3(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F3(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F3"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F3); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F3(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F3(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F4: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F4: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F4(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F4(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F4"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F4); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F4(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F4(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F5: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F5: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F5(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F5(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F5"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F5); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F5(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F5(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F6: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F6: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F6(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F6(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F6"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F6); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F6(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F6(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F7: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F7: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F7(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F7(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F7"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F7); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F7(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F7(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F8: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F8: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F8(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F8(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F8"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F8); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F8(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F8(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F9: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F9: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F9(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F9(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F9"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F9); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F9(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F9(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F10: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F10: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F10(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F10(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F10"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F10); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F10(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F10(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F11: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F11: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F11(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F11(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F11"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F11); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F11(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F11(this)); } { // - class ScriptMethodInputKeyboardKEYCODE_F12: public ScriptMethod { + class MethodInputKeyboardKEYCODE_F12: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardKEYCODE_F12(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputKeyboardKEYCODE_F12(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.KEYCODE_F12"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIKeyboardEvent::KEYCODE_F12); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardKEYCODE_F12(this)); + registerMethod(new MethodInputKeyboardKEYCODE_F12(this)); } { // - class ScriptMethodInputKeyboardIsKeyDown: public ScriptMethod { + class MethodInputKeyboardIsKeyDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsKeyDown(GUIMiniScript* miniScript): - ScriptMethod( + MethodInputKeyboardIsKeyDown(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "keyCode", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "keyCode", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isKeyDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t keyCode; if (miniScript->getIntegerValue(argumentValues, 0, keyCode) == true) { returnValue = miniScript->keyboardKeys.find(keyCode) != miniScript->keyboardKeys.end(); @@ -641,26 +641,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardIsKeyDown(this)); + registerMethod(new MethodInputKeyboardIsKeyDown(this)); } { // - class ScriptMethodInputKeyboardIsCharDown: public ScriptMethod { + class MethodInputKeyboardIsCharDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsCharDown(GUIMiniScript* miniScript): - ScriptMethod( + MethodInputKeyboardIsCharDown(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "charAsString", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "charAsString", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isCharDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string charAsString; if (miniScript->getStringValue(argumentValues, 0, charAsString) == true) { UTF8CharacterIterator u8It(charAsString); @@ -675,194 +675,194 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardIsCharDown(this)); + registerMethod(new MethodInputKeyboardIsCharDown(this)); } { // - class ScriptMethodInputKeyboardGetTypedString: public ScriptMethod { + class MethodInputKeyboardGetTypedString: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardGetTypedString(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodInputKeyboardGetTypedString(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.getTypedString"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardTypedChars; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardGetTypedString(this)); + registerMethod(new MethodInputKeyboardGetTypedString(this)); } { // - class ScriptMethodInputKeyboardIsControlDown: public ScriptMethod { + class MethodInputKeyboardIsControlDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsControlDown(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsControlDown(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isControlDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardControlDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardIsControlDown(this)); + registerMethod(new MethodInputKeyboardIsControlDown(this)); } { // - class ScriptMethodInputKeyboardIsMetaDown: public ScriptMethod { + class MethodInputKeyboardIsMetaDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsMetaDown(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsMetaDown(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isMetaDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardControlDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardIsMetaDown(this)); + registerMethod(new MethodInputKeyboardIsMetaDown(this)); } { // - class ScriptMethodInputKeyboardIsAltDown: public ScriptMethod { + class MethodInputKeyboardIsAltDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsAltDown(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsAltDown(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isAltDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardAltDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardIsAltDown(this)); + registerMethod(new MethodInputKeyboardIsAltDown(this)); } { // - class ScriptMethodInputKeyboardIsShiftDown: public ScriptMethod { + class MethodInputKeyboardIsShiftDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputKeyboardIsShiftDown(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputKeyboardIsShiftDown(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.keyboard.isShiftDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->keyboardShiftDown == true; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputKeyboardIsShiftDown(this)); + registerMethod(new MethodInputKeyboardIsShiftDown(this)); } // mouse input { // - class ScriptMethodInputMouseBUTTON_LEFT: public ScriptMethod { + class MethodInputMouseBUTTON_LEFT: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseBUTTON_LEFT(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseBUTTON_LEFT(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.BUTTON_LEFT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIMouseEvent::MOUSEEVENT_BUTTON_LEFT - 1); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseBUTTON_LEFT(this)); + registerMethod(new MethodInputMouseBUTTON_LEFT(this)); } { // - class ScriptMethodInputMouseBUTTON_MIDDLE: public ScriptMethod { + class MethodInputMouseBUTTON_MIDDLE: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseBUTTON_MIDDLE(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseBUTTON_MIDDLE(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.BUTTON_MIDDLE"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIMouseEvent::MOUSEEVENT_BUTTON_MIDDLE - 1); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseBUTTON_MIDDLE(this)); + registerMethod(new MethodInputMouseBUTTON_MIDDLE(this)); } { // - class ScriptMethodInputMouseBUTTON_RIGHT: public ScriptMethod { + class MethodInputMouseBUTTON_RIGHT: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseBUTTON_RIGHT(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseBUTTON_RIGHT(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.BUTTON_RIGHT"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(GUIMouseEvent::MOUSEEVENT_BUTTON_RIGHT - 1); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseBUTTON_RIGHT(this)); + registerMethod(new MethodInputMouseBUTTON_RIGHT(this)); } { // - class ScriptMethodInputMouseIsButtonDown: public ScriptMethod { + class MethodInputMouseIsButtonDown: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseIsButtonDown(GUIMiniScript* miniScript): - ScriptMethod( + MethodInputMouseIsButtonDown(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN), + VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.isButtonDown"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t button; if (miniScript->getIntegerValue(argumentValues, 0, button) == true) { returnValue = button >= 0 && button <= 3?miniScript->mouseDown[button]:false; @@ -875,25 +875,25 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseIsButtonDown(this)); + registerMethod(new MethodInputMouseIsButtonDown(this)); } { // - class ScriptMethodInputMouseIsButtonUp: public ScriptMethod { + class MethodInputMouseIsButtonUp: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseIsButtonUp(GUIMiniScript* miniScript): - ScriptMethod( + MethodInputMouseIsButtonUp(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN), + VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.isButtonUp"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t button; if (miniScript->getIntegerValue(argumentValues, 0, button) == true) { returnValue = button >= 0 && button <= 3?miniScript->mouseUp[button]:false; @@ -906,25 +906,25 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseIsButtonUp(this)); + registerMethod(new MethodInputMouseIsButtonUp(this)); } { // - class ScriptMethodInputMouseIsDragging: public ScriptMethod { + class MethodInputMouseIsDragging: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseIsDragging(GUIMiniScript* miniScript): - ScriptMethod( + MethodInputMouseIsDragging(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_INTEGER, .name = "button", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN), + VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.isDragging"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { int64_t button; if (miniScript->getIntegerValue(argumentValues, 0, button) == true) { returnValue = button >= 0 && button <= 3?miniScript->mouseDragging[button]:false; @@ -937,196 +937,196 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseIsDragging(this)); + registerMethod(new MethodInputMouseIsDragging(this)); } { // - class ScriptMethodInputMouseHasMoved: public ScriptMethod { + class MethodInputMouseHasMoved: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseHasMoved(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_BOOLEAN), + MethodInputMouseHasMoved(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_BOOLEAN), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.hasMoved"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseMoved; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseHasMoved(this)); + registerMethod(new MethodInputMouseHasMoved(this)); } { // - class ScriptMethodInputMouseGetX: public ScriptMethod { + class MethodInputMouseGetX: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetX(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetX(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getX"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseX); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetX(this)); + registerMethod(new MethodInputMouseGetX(this)); } { // - class ScriptMethodInputMouseGetXUnscaled: public ScriptMethod { + class MethodInputMouseGetXUnscaled: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetXUnscaled(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetXUnscaled(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getXUnscaled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseXUnscaled); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetXUnscaled(this)); + registerMethod(new MethodInputMouseGetXUnscaled(this)); } { // - class ScriptMethodInputMouseGetY: public ScriptMethod { + class MethodInputMouseGetY: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetY(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetY(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getY"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseY); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetY(this)); + registerMethod(new MethodInputMouseGetY(this)); } { // - class ScriptMethodInputMouseGetYUnscaled: public ScriptMethod { + class MethodInputMouseGetYUnscaled: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetYUnscaled(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodInputMouseGetYUnscaled(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getYUnscaled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = static_cast(miniScript->mouseYUnscaled); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetYUnscaled(this)); + registerMethod(new MethodInputMouseGetYUnscaled(this)); } { // - class ScriptMethodInputMouseGetWheelX: public ScriptMethod { + class MethodInputMouseGetWheelX: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetWheelX(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodInputMouseGetWheelX(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getWheelX"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseWheelX; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetWheelX(this)); + registerMethod(new MethodInputMouseGetWheelX(this)); } { // - class ScriptMethodInputMouseGetWheelY: public ScriptMethod { + class MethodInputMouseGetWheelY: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetWheelY(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodInputMouseGetWheelY(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getWheelY"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseWheelY; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetWheelY(this)); + registerMethod(new MethodInputMouseGetWheelY(this)); } { // - class ScriptMethodInputMouseGetWheelZ: public ScriptMethod { + class MethodInputMouseGetWheelZ: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodInputMouseGetWheelZ(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_FLOAT), + MethodInputMouseGetWheelZ(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_FLOAT), miniScript(miniScript) {} const string getMethodName() override { return "input.mouse.getWheelZ"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue = miniScript->mouseWheelZ; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodInputMouseGetWheelZ(this)); + registerMethod(new MethodInputMouseGetWheelZ(this)); } // gui { // - class ScriptMethodGUIScreenSetEnabled: public ScriptMethod { + class MethodGUIScreenSetEnabled: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIScreenSetEnabled(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIScreenSetEnabled(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "screenId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_BOOLEAN, .name = "enabled", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "screenId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_BOOLEAN, .name = "enabled", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.screen.setEnabled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string screenId; bool enabled; if (miniScript->getStringValue(argumentValues, 0, screenId, false) == false || @@ -1147,26 +1147,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIScreenSetEnabled(this)); + registerMethod(new MethodGUIScreenSetEnabled(this)); } { // - class ScriptMethodGUIScreenIsEnabled: public ScriptMethod { + class MethodGUIScreenIsEnabled: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIScreenIsEnabled(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIScreenIsEnabled(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "screenId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "screenId", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "gui.screen.isEnabled"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string screenId; if (miniScript->getStringValue(argumentValues, 0, screenId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -1184,28 +1184,28 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIScreenIsEnabled(this)); + registerMethod(new MethodGUIScreenIsEnabled(this)); } { // - class ScriptMethodGUIScreenGoto: public ScriptMethod { + class MethodGUIScreenGoto: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIScreenGoto(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIScreenGoto(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_MAP, .name = "variables", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_PSEUDO_MIXED, .name = "arguments", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_MAP, .name = "variables", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_PSEUDO_MIXED, .name = "arguments", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.screen.goto"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string fileName; if (argumentValues.size() > 3 || EngineMiniScript::getStringValue(argumentValues, 0, fileName, false) == false) { @@ -1235,7 +1235,7 @@ void GUIMiniScript::registerMethods() { screenPathName, screenFileName, variables, - argumentValues.size() == 3?argumentValues[2]:EngineMiniScript::ScriptVariable(), + argumentValues.size() == 3?argumentValues[2]:EngineMiniScript::Variable(), miniScript->screenNode->getContext() ) ); @@ -1249,28 +1249,28 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIScreenGoto(this)); + registerMethod(new MethodGUIScreenGoto(this)); } { // - class ScriptMethodGUIScreenPush: public ScriptMethod { + class MethodGUIScreenPush: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIScreenPush(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIScreenPush(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_MAP, .name = "variables", .optional = true, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_PSEUDO_MIXED, .name = "arguments", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "fileName", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_MAP, .name = "variables", .optional = true, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_PSEUDO_MIXED, .name = "arguments", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.screen.push"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string fileName; if (argumentValues.size() > 3 || EngineMiniScript::getStringValue(argumentValues, 0, fileName, false) == false) { @@ -1297,7 +1297,7 @@ void GUIMiniScript::registerMethods() { screenPathName, screenFileName, variables, - argumentValues.size() == 3?argumentValues[2]:EngineMiniScript::ScriptVariable(), + argumentValues.size() == 3?argumentValues[2]:EngineMiniScript::Variable(), miniScript->screenNode->getContext() ); miniScript->screenNode->getGUI()->addScreen(screenNode->getId(), screenNode); @@ -1312,52 +1312,52 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIScreenPush(this)); + registerMethod(new MethodGUIScreenPush(this)); } { // - class ScriptMethodGUIScreenPop: public ScriptMethod { + class MethodGUIScreenPop: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIScreenPop(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIScreenPop(GUIMiniScript* miniScript): + Method( {}, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { // mark as popped return "gui.screen.pop"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { miniScript->popped = true; } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIScreenPop(this)); + registerMethod(new MethodGUIScreenPop(this)); } { // - class ScriptMethodGUIScreenCall: public ScriptMethod { + class MethodGUIScreenCall: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIScreenCall(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIScreenCall(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "screenId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "function", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "screenId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "function", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_PSEUDO_MIXED + VariableType::TYPE_PSEUDO_MIXED ), miniScript(miniScript) {} const string getMethodName() override { return "gui.screen.call"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string screenId; string function; if (miniScript->getStringValue(argumentValues, 0, screenId) == false || @@ -1383,7 +1383,7 @@ void GUIMiniScript::registerMethods() { #if defined (__APPLE__) // MACOSX currently does not support initializing span using begin and end iterators, // so we need to make a copy of argumentValues beginning from second element - vector callArgumentValues; + vector callArgumentValues; for (auto i = 2; i < argumentValues.size(); i++) callArgumentValues.push_back(argumentValues[i]); // call span callArgumentValuesSpan(callArgumentValues); @@ -1402,89 +1402,89 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIScreenCall(this)); + registerMethod(new MethodGUIScreenCall(this)); } { // - class ScriptMethodScreenNodeGetId: public ScriptMethod { + class MethodScreenNodeGetId: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodScreenNodeGetId(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_STRING), + MethodScreenNodeGetId(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_STRING), miniScript(miniScript) {} const string getMethodName() override { return "gui.screennode.getId"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue.setValue(miniScript->screenNode->getId()); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodScreenNodeGetId(this)); + registerMethod(new MethodScreenNodeGetId(this)); } { // - class ScriptMethodGUIEventACTIONTYPE_PERFORMING: public ScriptMethod { + class MethodGUIEventACTIONTYPE_PERFORMING: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIEventACTIONTYPE_PERFORMING(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodGUIEventACTIONTYPE_PERFORMING(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "gui.event.ACTIONTYPE_PERFORMING"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue.setValue(static_cast(GUIActionListenerType::PERFORMING)); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIEventACTIONTYPE_PERFORMING(this)); + registerMethod(new MethodGUIEventACTIONTYPE_PERFORMING(this)); } { // - class ScriptMethodGUIEventACTIONTYPE_PERFORMED: public ScriptMethod { + class MethodGUIEventACTIONTYPE_PERFORMED: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIEventACTIONTYPE_PERFORMED(GUIMiniScript* miniScript): - ScriptMethod({}, ScriptVariableType::TYPE_INTEGER), + MethodGUIEventACTIONTYPE_PERFORMED(GUIMiniScript* miniScript): + Method({}, VariableType::TYPE_INTEGER), miniScript(miniScript) {} const string getMethodName() override { return "gui.event.ACTIONTYPE_PERFORMED"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { returnValue.setValue(static_cast(GUIActionListenerType::PERFORMED)); } const vector& getContextFunctions() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIEventACTIONTYPE_PERFORMED(this)); + registerMethod(new MethodGUIEventACTIONTYPE_PERFORMED(this)); } { // - class ScriptMethodGUINodeControllerGetValue: public ScriptMethod { + class MethodGUINodeControllerGetValue: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUINodeControllerGetValue(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUINodeControllerGetValue(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_STRING + VariableType::TYPE_STRING ), miniScript(miniScript) {} const string getMethodName() override { return "gui.node.controller.getValue"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string nodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, nodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -1504,27 +1504,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUINodeControllerGetValue(this)); + registerMethod(new MethodGUINodeControllerGetValue(this)); } { // - class ScriptMethodGUINodeControllerSetValue: public ScriptMethod { + class MethodGUINodeControllerSetValue: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUINodeControllerSetValue(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUINodeControllerSetValue(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "nodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "value", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.node.controller.setValue"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string nodeId; string value; if (EngineMiniScript::getStringValue(argumentValues, 0, nodeId, false) == false || @@ -1546,26 +1546,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUINodeControllerSetValue(this)); + registerMethod(new MethodGUINodeControllerSetValue(this)); } { // - class ScriptMethodGUITextNodeGetText: public ScriptMethod { + class MethodGUITextNodeGetText: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUITextNodeGetText(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUITextNodeGetText(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "textNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "textNodeId", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_STRING + VariableType::TYPE_STRING ), miniScript(miniScript) {} const string getMethodName() override { return "gui.textnode.getText"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string textNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, textNodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -1588,27 +1588,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUITextNodeGetText(this)); + registerMethod(new MethodGUITextNodeGetText(this)); } { // - class ScriptMethodGUITextNodeSetText: public ScriptMethod { + class MethodGUITextNodeSetText: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUITextNodeSetText(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUITextNodeSetText(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "textNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "text", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "textNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "text", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.textnode.setText"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string textNodeId; string text; if (EngineMiniScript::getStringValue(argumentValues, 0, textNodeId, false) == false || @@ -1633,27 +1633,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUITextNodeSetText(this)); + registerMethod(new MethodGUITextNodeSetText(this)); } { // - class ScriptMethodGUIElementNodeConditionsHas: public ScriptMethod { + class MethodGUIElementNodeConditionsHas: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsHas(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsHas(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.has"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; string condition; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false || @@ -1674,26 +1674,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsHas(this)); + registerMethod(new MethodGUIElementNodeConditionsHas(this)); } { // - class ScriptMethodGUIElementNodeConditionsGet: public ScriptMethod { + class MethodGUIElementNodeConditionsGet: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsGet(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsGet(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_ARRAY + VariableType::TYPE_ARRAY ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.get"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -1716,27 +1716,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsGet(this)); + registerMethod(new MethodGUIElementNodeConditionsGet(this)); } { // - class ScriptMethodGUIElementNodeConditionsSet: public ScriptMethod { + class MethodGUIElementNodeConditionsSet: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsSet(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsSet(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.set"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; string condition; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false || @@ -1757,27 +1757,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsSet(this)); + registerMethod(new MethodGUIElementNodeConditionsSet(this)); } { // - class ScriptMethodGUIElementNodeConditionsAdd: public ScriptMethod { + class MethodGUIElementNodeConditionsAdd: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsAdd(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsAdd(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.add"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; string condition; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false || @@ -1798,30 +1798,30 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsAdd(this)); + registerMethod(new MethodGUIElementNodeConditionsAdd(this)); } { // - class ScriptMethodGUIElementNodeConditionsSetAll: public ScriptMethod { + class MethodGUIElementNodeConditionsSetAll: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsSetAll(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsSetAll(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_ARRAY, .name = "conditions", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_ARRAY, .name = "conditions", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.setAll"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false || - argumentValues.size() <= 1 || argumentValues[1].getType() != ScriptVariableType::TYPE_ARRAY) { + argumentValues.size() <= 1 || argumentValues[1].getType() != VariableType::TYPE_ARRAY) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { @@ -1847,27 +1847,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsSetAll(this)); + registerMethod(new MethodGUIElementNodeConditionsSetAll(this)); } { // - class ScriptMethodGUIElementNodeConditionsRemove: public ScriptMethod { + class MethodGUIElementNodeConditionsRemove: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsRemove(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsRemove(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "condition", .optional = false, .reference = false, .nullable = false }, }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.remove"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; string condition; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false || @@ -1888,26 +1888,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsRemove(this)); + registerMethod(new MethodGUIElementNodeConditionsRemove(this)); } { // - class ScriptMethodGUIElementNodeConditionsRemoveAll: public ScriptMethod { + class MethodGUIElementNodeConditionsRemoveAll: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIElementNodeConditionsRemoveAll(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIElementNodeConditionsRemoveAll(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "elementNodeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.elementnode.conditions.removeAll"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string elementNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, elementNodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -1926,26 +1926,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIElementNodeConditionsRemoveAll(this)); + registerMethod(new MethodGUIElementNodeConditionsRemoveAll(this)); } { // - class ScriptMethodGUIImageNodeGetSource: public ScriptMethod { + class MethodGUIImageNodeGetSource: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIImageNodeGetSource(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIImageNodeGetSource(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "imageNodeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "imageNodeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_STRING + VariableType::TYPE_STRING ), miniScript(miniScript) {} const string getMethodName() override { return "gui.imagenode.getSource"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string imageNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, imageNodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -1964,27 +1964,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIImageNodeGetSource(this)); + registerMethod(new MethodGUIImageNodeGetSource(this)); } { // - class ScriptMethodGUIImageNodeSetSource: public ScriptMethod { + class MethodGUIImageNodeSetSource: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIImageNodeSetSource(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIImageNodeSetSource(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "imageNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "source", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "imageNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "source", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.imagenode.setSource"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string imageNodeId; string source; if (EngineMiniScript::getStringValue(argumentValues, 0, imageNodeId, false) == false || @@ -2005,26 +2005,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIImageNodeSetSource(this)); + registerMethod(new MethodGUIImageNodeSetSource(this)); } { // - class ScriptMethodGUIVideoNodeGetSource: public ScriptMethod { + class MethodGUIVideoNodeGetSource: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIVideoNodeGetSource(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIVideoNodeGetSource(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "videoNodeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "videoNodeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_STRING + VariableType::TYPE_STRING ), miniScript(miniScript) {} const string getMethodName() override { return "gui.videonode.getSource"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string videoNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, videoNodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -2043,27 +2043,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIVideoNodeGetSource(this)); + registerMethod(new MethodGUIVideoNodeGetSource(this)); } { // - class ScriptMethodGUIVideoNodeSetSource: public ScriptMethod { + class MethodGUIVideoNodeSetSource: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIVideoNodeSetSource(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIVideoNodeSetSource(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "videoNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "source", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "videoNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "source", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.videonode.setSource"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string videoNodeId; string source; if (EngineMiniScript::getStringValue(argumentValues, 0, videoNodeId, false) == false || @@ -2084,26 +2084,26 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIVideoNodeSetSource(this)); + registerMethod(new MethodGUIVideoNodeSetSource(this)); } { // - class ScriptMethodGUIParentNodeClearSubNodes: public ScriptMethod { + class MethodGUIParentNodeClearSubNodes: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIParentNodeClearSubNodes(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIParentNodeClearSubNodes(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "parentNodeId", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "parentNodeId", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.parentnode.clearSubNodes"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string parentNodeId; if (EngineMiniScript::getStringValue(argumentValues, 0, parentNodeId, false) == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); @@ -2122,28 +2122,28 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIParentNodeClearSubNodes(this)); + registerMethod(new MethodGUIParentNodeClearSubNodes(this)); } { // - class ScriptMethodGUIParentNodeAddSubNodes: public ScriptMethod { + class MethodGUIParentNodeAddSubNodes: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIParentNodeAddSubNodes(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIParentNodeAddSubNodes(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "parentNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "xml", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_BOOLEAN, .name = "resetScrollOffsets", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "parentNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "xml", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_BOOLEAN, .name = "resetScrollOffsets", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.parentnode.addSubNodes"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string parentNodeId; string xml; bool resetScrollOffsets = true; @@ -2166,28 +2166,28 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIParentNodeAddSubNodes(this)); + registerMethod(new MethodGUIParentNodeAddSubNodes(this)); } { // - class ScriptMethodGUIParentNodeReplaceSubNodes: public ScriptMethod { + class MethodGUIParentNodeReplaceSubNodes: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodGUIParentNodeReplaceSubNodes(GUIMiniScript* miniScript): - ScriptMethod( + MethodGUIParentNodeReplaceSubNodes(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "parentNodeId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "xml", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_BOOLEAN, .name = "resetScrollOffsets", .optional = true, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "parentNodeId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "xml", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_BOOLEAN, .name = "resetScrollOffsets", .optional = true, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_NULL + VariableType::TYPE_NULL ), miniScript(miniScript) {} const string getMethodName() override { return "gui.parentnode.replaceSubNodes"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { string parentNodeId; string xml; bool resetScrollOffsets = true; @@ -2210,24 +2210,24 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodGUIParentNodeReplaceSubNodes(this)); + registerMethod(new MethodGUIParentNodeReplaceSubNodes(this)); } { // - class ScriptMethodLogicSignalSend: public ScriptMethod { + class MethodLogicSignalSend: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicSignalSend(GUIMiniScript* miniScript): - ScriptMethod({ - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "signal", .optional = false, .reference = false, .nullable = false } + MethodLogicSignalSend(GUIMiniScript* miniScript): + Method({ + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "signal", .optional = false, .reference = false, .nullable = false } }), miniScript(miniScript) {} const string getMethodName() override { return "logic.signal.send"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { auto context = miniScript->screenNode->getContext(); if (context != nullptr) { string logicId; @@ -2240,7 +2240,7 @@ void GUIMiniScript::registerMethods() { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": no logic with given id: " + logicId); miniScript->startErrorScript(); } else { - vector arguments(argumentValues.size() - 2); + vector arguments(argumentValues.size() - 2); for (auto i = 2; i < argumentValues.size(); i++) arguments.push_back(argumentValues[i]); logic->addSignal(signal, arguments); } @@ -2261,27 +2261,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodLogicSignalSend(this)); + registerMethod(new MethodLogicSignalSend(this)); } { // - class ScriptMethodLogicHas: public ScriptMethod { + class MethodLogicHas: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicHas(GUIMiniScript* miniScript): - ScriptMethod( + MethodLogicHas(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_BOOLEAN + VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { return "logic.has"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { auto context = miniScript->screenNode->getContext(); if (context != nullptr) { string logicId; @@ -2298,7 +2298,7 @@ void GUIMiniScript::registerMethods() { } else { auto logicMiniScript = logic->getMiniScript(); auto scriptIdx = logicMiniScript->getFunctionScriptIdx(callable); - if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callable == false) { + if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callableFunction == false) { returnValue.setValue(false); } else { returnValue.setValue(true); @@ -2315,27 +2315,27 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodLogicHas(this)); + registerMethod(new MethodLogicHas(this)); } { // - class ScriptMethodLogicCall: public ScriptMethod { + class MethodLogicCall: public Method { private: GUIMiniScript* miniScript { nullptr }; public: - ScriptMethodLogicCall(GUIMiniScript* miniScript): - ScriptMethod( + MethodLogicCall(GUIMiniScript* miniScript): + Method( { - { .type = ScriptVariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, - { .type = ScriptVariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } + { .type = VariableType::TYPE_STRING, .name = "logicId", .optional = false, .reference = false, .nullable = false }, + { .type = VariableType::TYPE_STRING, .name = "callable", .optional = false, .reference = false, .nullable = false } }, - ScriptVariableType::TYPE_PSEUDO_MIXED + VariableType::TYPE_PSEUDO_MIXED ), miniScript(miniScript) {} const string getMethodName() override { return "logic.call"; } - void executeMethod(span& argumentValues, ScriptVariable& returnValue, const ScriptStatement& statement) override { + void executeMethod(span& argumentValues, Variable& returnValue, const Statement& statement) override { auto context = miniScript->screenNode->getContext(); if (context != nullptr) { string logicId; @@ -2353,14 +2353,14 @@ void GUIMiniScript::registerMethods() { } else { auto logicMiniScript = logic->getMiniScript(); auto scriptIdx = logicMiniScript->getFunctionScriptIdx(callable); - if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callable == false) { + if (scriptIdx == SCRIPTIDX_NONE || logicMiniScript->getScripts()[scriptIdx].callableFunction == false) { Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": callable not found: " + callable); miniScript->startErrorScript(); } else { #if defined (__APPLE__) // MACOSX currently does not support initializing span using begin and end iterators, // so we need to make a copy of argumentValues beginning from second element - vector callArgumentValues; + vector callArgumentValues; for (auto i = 2; i < argumentValues.size(); i++) callArgumentValues.push_back(argumentValues[i]); // call span callArgumentValuesSpan(callArgumentValues); @@ -2385,7 +2385,7 @@ void GUIMiniScript::registerMethods() { return CONTEXTFUNCTION_GUI; } }; - registerMethod(new ScriptMethodLogicCall(this)); + registerMethod(new MethodLogicCall(this)); } } diff --git a/src/tdme/tools/cli/createminiscriptcodecompletion-main.cpp b/src/tdme/tools/cli/createminiscriptcodecompletion-main.cpp index e0156415f..61a9dbfe3 100644 --- a/src/tdme/tools/cli/createminiscriptcodecompletion-main.cpp +++ b/src/tdme/tools/cli/createminiscriptcodecompletion-main.cpp @@ -84,11 +84,11 @@ int main(int argc, char** argv) if (description.empty() == true) description = methodDescriptions.get("miniscript." + scriptMethod->getMethodName(), string()); Console::println("Adding method: " + scriptMethod->getMethodName()); lines.push_back(" getMethodName() + "\" func=\"yes\">"); - lines.push_back(" getReturnValueType(), scriptMethod->isReturnValueNullable()) + "\" descr=\"" + GUIParser::escape(description) + "\">"); + lines.push_back(" getReturnValueType(), scriptMethod->isReturnValueNullable()) + "\" descr=\"" + GUIParser::escape(description) + "\">"); for (const auto& argumentType: scriptMethod->getArgumentTypes()) { string argumentValueString; if (argumentType.optional == true) argumentValueString+= "["; - argumentValueString+= EngineMiniScript::ScriptVariable::getTypeAsString(argumentType.type) + " "; + argumentValueString+= EngineMiniScript::Variable::getTypeAsString(argumentType.type) + " "; argumentValueString+= string() + (argumentType.reference == true?"=":"") + "$" + argumentType.name; if (argumentType.optional == true) argumentValueString+= "]"; lines.push_back(" "); diff --git a/src/tdme/tools/cli/createminiscriptdocumentation-main.cpp b/src/tdme/tools/cli/createminiscriptdocumentation-main.cpp index 86ac362f3..b9bb58949 100644 --- a/src/tdme/tools/cli/createminiscriptdocumentation-main.cpp +++ b/src/tdme/tools/cli/createminiscriptdocumentation-main.cpp @@ -70,7 +70,7 @@ static void generateMiniScriptMethodsDocumentation(const string& heading, int ma method+= "("; method+= scriptMethod->getArgumentsInformation(); method+= "): "; - method+= EngineMiniScript::ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + method+= EngineMiniScript::Variable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); method+= ""; while (method.size() < 99) method+= " "; method+= "|"; @@ -121,7 +121,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma auto scriptMethods = miniScript->getMethods(); // for (auto typeIdx = static_cast(EngineMiniScript::TYPE_STRING); ; typeIdx++) { - const auto& className = EngineMiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& className = EngineMiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (className.empty() == true) break; allClassMethods.insert(className); } @@ -133,7 +133,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma // auto _class = false; for (auto typeIdx = static_cast(EngineMiniScript::TYPE_STRING); ; typeIdx++) { - const auto& classNameCandidate = EngineMiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& classNameCandidate = EngineMiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (classNameCandidate.empty() == true) break; if (classNameCandidate == className) { _class = true; @@ -151,7 +151,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma auto _static = scriptMethod->getArgumentTypes().empty() == true || scriptMethod->getArgumentTypes()[0].name != className || - EngineMiniScript::ScriptVariable::getClassName(scriptMethod->getArgumentTypes()[0].type) != className; + EngineMiniScript::Variable::getTypeAsString(scriptMethod->getArgumentTypes()[0].type) != className; // allClassMethods.insert(scriptMethod->getMethodName()); } @@ -168,7 +168,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma auto _static = false; if (className.empty() == true) { for (auto typeIdx = static_cast(EngineMiniScript::TYPE_STRING); ; typeIdx++) { - const auto& classNameCandidate = EngineMiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& classNameCandidate = EngineMiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (classNameCandidate.empty() == true) break; if (scriptMethod->getMethodName() == classNameCandidate) { className = classNameCandidate; @@ -182,7 +182,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma _static = scriptMethod->getArgumentTypes().empty() == true || scriptMethod->getArgumentTypes()[0].name != className || - EngineMiniScript::ScriptVariable::getClassName(scriptMethod->getArgumentTypes()[0].type) != className; + EngineMiniScript::Variable::getTypeAsString(scriptMethod->getArgumentTypes()[0].type) != className; } // string description; @@ -200,7 +200,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma method+= "("; method+= scriptMethod->getArgumentsInformation(_static == true?0:1); method+= "): "; - method+= EngineMiniScript::ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + method+= EngineMiniScript::Variable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); method+= ""; while (method.size() < 99) method+= " "; method+= "|"; @@ -211,7 +211,7 @@ static void generateMiniScriptClassesDocumentation(const string& heading, int ma // auto classIdx = 1; for (auto typeIdx = static_cast(EngineMiniScript::TYPE_STRING); ; typeIdx++) { - const auto& className = EngineMiniScript::ScriptVariable::getClassName(static_cast(typeIdx)); + const auto& className = EngineMiniScript::Variable::getTypeAsString(static_cast(typeIdx)); if (className.empty() == true) break; auto classNameDescription = descriptions.get("miniscript.baseclass." + (className.empty() == true?"No class":className), "Not documented"); // @@ -298,7 +298,7 @@ int main(int argc, char** argv) operatorString+= "("; operatorString+= scriptMethod->getArgumentsInformation(); operatorString+= "): "; - operatorString+= EngineMiniScript::ScriptVariable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); + operatorString+= EngineMiniScript::Variable::getReturnTypeAsString(scriptMethod->getReturnValueType(), scriptMethod->isReturnValueNullable()); while (operatorString.size() < 99) operatorString+= " "; operatorString+= "|"; operators.push_back(operatorString); diff --git a/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.cpp b/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.cpp index 46258cbbd..c6546082a 100644 --- a/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.cpp +++ b/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.cpp @@ -470,7 +470,7 @@ void TextEditorTabController::updateMiniScriptSyntaxTree(int miniScriptScriptIdx string argumentsString; switch(script.scriptType) { case EngineMiniScript::Script::SCRIPTTYPE_FUNCTION: { - for (const auto& argument: script.arguments) { + for (const auto& argument: script.functionArguments) { if (argumentsString.empty() == false) argumentsString+= ", "; if (argument.reference == true) argumentsString+= "="; argumentsString+= argument.name; diff --git a/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.h b/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.h index 183e65a6d..d0a48aa02 100644 --- a/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.h +++ b/src/tdme/tools/editor/tabcontrollers/TextEditorTabController.h @@ -56,8 +56,8 @@ class tdme::tools::editor::tabcontrollers::TextEditorTabController final EngineMiniScript::Script::ScriptType type; string condition; string name; - EngineMiniScript::ScriptSyntaxTreeNode conditionSyntaxTree; - vector syntaxTree; + EngineMiniScript::SyntaxTreeNode conditionSyntaxTree; + vector syntaxTree; }; enum ContextMenuType { CONTEXTMENUTYPE_NONE, CONTEXTMENUTYPE_NODE, CONTEXTMENUTYPE_CANVAS }; diff --git a/src/tdme/tools/editor/tabviews/SceneEditorTabView.cpp b/src/tdme/tools/editor/tabviews/SceneEditorTabView.cpp index a6b49d6b8..4fa266624 100644 --- a/src/tdme/tools/editor/tabviews/SceneEditorTabView.cpp +++ b/src/tdme/tools/editor/tabviews/SceneEditorTabView.cpp @@ -1445,7 +1445,7 @@ void SceneEditorTabView::runScene() { Tools::getPathName(scene->getGUIFileName()), Tools::getFileName(scene->getGUIFileName()), {}, - MiniScript::ScriptVariable(), + MiniScript::Variable(), applicationClient->getContext() ); engine->getGUI()->addScreen(screenNode->getId(), screenNode); diff --git a/src/tdme/tools/editor/tabviews/TextEditorTabView.cpp b/src/tdme/tools/editor/tabviews/TextEditorTabView.cpp index 5271d6aad..e07a1a60d 100644 --- a/src/tdme/tools/editor/tabviews/TextEditorTabView.cpp +++ b/src/tdme/tools/editor/tabviews/TextEditorTabView.cpp @@ -655,7 +655,7 @@ void TextEditorTabView::createMiniScriptNode(const string& methodName, int x, in " src='resources/engine/gui/template_visualcode_input.xml' " + " pin_type_connected='resources/engine/images/visualcode_value_connected.png' " + " pin_type_unconnected='resources/engine/images/visualcode_value_unconnected.png' " + - " pin_color='{$" + GUIParser::escape(getScriptVariableTypePinColor(argumentTypes[argumentIdx].type)) + "}' " + + " pin_color='{$" + GUIParser::escape(getVariableTypePinColor(argumentTypes[argumentIdx].type)) + "}' " + " text='" + GUIParser::escape(argumentName) + "' "; if (isLiteral == true) { xml+= " input_text='" + GUIParser::escape(literal) + "' "; @@ -701,7 +701,7 @@ void TextEditorTabView::createMiniScriptNode(const string& methodName, int x, in } } // return value - if (method != nullptr && method->getReturnValueType() != MiniScript::ScriptVariableType::TYPE_NULL) { + if (method != nullptr && method->getReturnValueType() != MiniScript::VariableType::TYPE_NULL) { string xml; // xml+= @@ -711,7 +711,7 @@ void TextEditorTabView::createMiniScriptNode(const string& methodName, int x, in " src='resources/engine/gui/template_visualcode_output.xml' " + " pin_type_connected='resources/engine/images/visualcode_value_connected.png' " + " pin_type_unconnected='resources/engine/images/visualcode_value_unconnected.png' " + - " pin_color='{$" + GUIParser::escape(getScriptVariableTypePinColor(method->getReturnValueType())) + "}' " + + " pin_color='{$" + GUIParser::escape(getVariableTypePinColor(method->getReturnValueType())) + "}' " + " text='Return' " + "/>"; @@ -754,24 +754,24 @@ void TextEditorTabView::createMiniScriptNode(const string& methodName, int x, in screenNode->forceInvalidateLayout(screenNode); } -void TextEditorTabView::addMiniScriptNodeDeltaX(unordered_map& idMapping, const string& id, const MiniScript::ScriptSyntaxTreeNode& syntaxTreeNode, int deltaX) { +void TextEditorTabView::addMiniScriptNodeDeltaX(unordered_map& idMapping, const string& id, const MiniScript::SyntaxTreeNode& syntaxTreeNode, int deltaX) { auto node = required_dynamic_cast(screenNode->getNodeById(getMiniScriptNodeFlattenedId(idMapping, id))); node->getRequestsConstraints().left+= deltaX; for (auto argumentIdx = 0; argumentIdx < syntaxTreeNode.arguments.size(); argumentIdx++) { // - auto isLiteral = syntaxTreeNode.arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = syntaxTreeNode.arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; if (isLiteral == true) continue; addMiniScriptNodeDeltaX(idMapping, id + "." + to_string(argumentIdx), syntaxTreeNode.arguments[argumentIdx], deltaX); } } -void TextEditorTabView::createMiniScriptScriptNode(unordered_map& idMapping, const string& id, MiniScript::Script::ScriptType scriptType, const string& condition, const string& readableName, const MiniScript::ScriptSyntaxTreeNode* conditionSyntaxTreeNode, int x, int y, int& width, int& height) { +void TextEditorTabView::createMiniScriptScriptNode(unordered_map& idMapping, const string& id, MiniScript::Script::ScriptType scriptType, const string& condition, const string& readableName, const MiniScript::SyntaxTreeNode* conditionSyntaxTreeNode, int x, int y, int& width, int& height) { // create input nodes auto yInitial = y; // - if (conditionSyntaxTreeNode->type != MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE) { + if (conditionSyntaxTreeNode->type != MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE) { y+= 200; { auto childWidth = 0; @@ -797,7 +797,7 @@ void TextEditorTabView::createMiniScriptScriptNode(unordered_map .id = flattenedId, .type = Node::NODETYPE_ARGUMENT, .value = conditionSyntaxTreeNode->value.getValueAsString(), - .returnValueType = MiniScript::ScriptVariableType::TYPE_NULL, + .returnValueType = MiniScript::VariableType::TYPE_NULL, .left = x, .top = y }; @@ -819,7 +819,7 @@ void TextEditorTabView::createMiniScriptScriptNode(unordered_map // condition input { // - auto isLiteral = conditionSyntaxTreeNode->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE; + auto isLiteral = conditionSyntaxTreeNode->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE; auto literal = isLiteral == true?condition:string(); // string xml = @@ -829,7 +829,7 @@ void TextEditorTabView::createMiniScriptScriptNode(unordered_map " src='resources/engine/gui/template_visualcode_input.xml' " + " pin_type_connected='resources/engine/images/visualcode_value_connected.png' " + " pin_type_unconnected='resources/engine/images/visualcode_value_unconnected.png' " + - " pin_color='{$" + GUIParser::escape(getScriptVariableTypePinColor(MiniScript::ScriptVariableType::TYPE_BOOLEAN)) + "}' " + + " pin_color='{$" + GUIParser::escape(getVariableTypePinColor(MiniScript::VariableType::TYPE_BOOLEAN)) + "}' " + " text='" + GUIParser::escape("Cond") + "' "; if (isLiteral == true) { xml+= " input_text='" + GUIParser::escape(literal) + "' "; @@ -853,7 +853,7 @@ void TextEditorTabView::createMiniScriptScriptNode(unordered_map } // create connection to condition node return to node cond node - if (conditionSyntaxTreeNode->type != MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE) { + if (conditionSyntaxTreeNode->type != MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_NONE) { // string argumentInputNodeId = flattenedId + "_c"; string argumentOutputNodeId = getMiniScriptNodeFlattenedId(idMapping, id + ".c_r"); @@ -896,7 +896,7 @@ void TextEditorTabView::createMiniScriptScriptNode(unordered_map height = Math::max(height, 200); } -void TextEditorTabView::createMiniScriptNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const MiniScript::ScriptSyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, int x, int y, int& width, int& height, vector& createdNodeIds, int depth) { +void TextEditorTabView::createMiniScriptNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const MiniScript::SyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, int x, int y, int& width, int& height, vector& createdNodeIds, int depth) { // create input nodes int childMaxWidth = 0; auto yInitial = y; @@ -906,7 +906,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM vector leftNodeIds; for (auto argumentIdx = 0; argumentIdx < syntaxTreeNode->arguments.size(); argumentIdx++) { // - auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; if (isLiteral == true) continue; // auto childWidth = 0; @@ -930,8 +930,8 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM // switch (syntaxTreeNode->type) { - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_FUNCTION: { // createdNodeIds.push_back(flattenedId); @@ -940,7 +940,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM .id = flattenedId, .type = nodeType, .value = syntaxTreeNode->value.getValueAsString(), - .returnValueType = syntaxTreeNode->method != nullptr?syntaxTreeNode->method->getReturnValueType():MiniScript::ScriptVariableType::TYPE_NULL, + .returnValueType = syntaxTreeNode->getMethod() != nullptr?syntaxTreeNode->getMethod()->getReturnValueType():MiniScript::VariableType::TYPE_NULL, .left = x, .top = y }; @@ -953,7 +953,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM nodeTypeColor = "color.nodetype_math"; } - if (syntaxTreeNode->method == nullptr) { + if (syntaxTreeNode->getMethod() == nullptr) { nodeTypeColor = "color.nodetype_function"; } else { for (const auto& flowControlNode: flowControlNodes) { @@ -1006,11 +1006,11 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM { // auto argumentIdx = 0; - if (syntaxTreeNode->method != nullptr) { - const auto& argumentTypes = syntaxTreeNode->method->getArgumentTypes(); + if (syntaxTreeNode->getMethod() != nullptr) { + const auto& argumentTypes = syntaxTreeNode->getMethod()->getArgumentTypes(); for (argumentIdx = 0; argumentIdx < argumentTypes.size(); argumentIdx++) { // - auto isLiteral = argumentIdx < syntaxTreeNode->arguments.size()?syntaxTreeNode->arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL:false; + auto isLiteral = argumentIdx < syntaxTreeNode->arguments.size()?syntaxTreeNode->arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL:false; auto literal = isLiteral == true?syntaxTreeNode->arguments[argumentIdx].value.getValueAsString():string(); auto argumentName = argumentTypes[argumentIdx].name; if (argumentName.empty() == false) argumentName[0] = Character::toUpperCase(argumentName[0]); @@ -1022,7 +1022,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM " src='resources/engine/gui/template_visualcode_input.xml' " + " pin_type_connected='resources/engine/images/visualcode_value_connected.png' " + " pin_type_unconnected='resources/engine/images/visualcode_value_unconnected.png' " + - " pin_color='{$" + GUIParser::escape(getScriptVariableTypePinColor(argumentTypes[argumentIdx].type)) + "}' " + + " pin_color='{$" + GUIParser::escape(getVariableTypePinColor(argumentTypes[argumentIdx].type)) + "}' " + " text='" + GUIParser::escape(argumentName) + "' "; if (isLiteral == true) { xml+= " input_text='" + GUIParser::escape(literal) + "' "; @@ -1047,7 +1047,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM } for (; argumentIdx < syntaxTreeNode->arguments.size(); argumentIdx++) { // - auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; auto literal = isLiteral == true?syntaxTreeNode->arguments[argumentIdx].value.getValueAsString():string(); // string xml = @@ -1101,7 +1101,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM } } // return value - if (syntaxTreeNode->method != nullptr && syntaxTreeNode->method->getReturnValueType() != MiniScript::ScriptVariableType::TYPE_NULL) { + if (syntaxTreeNode->getMethod() != nullptr && syntaxTreeNode->getMethod()->getReturnValueType() != MiniScript::VariableType::TYPE_NULL) { string xml; // xml+= @@ -1111,7 +1111,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM " src='resources/engine/gui/template_visualcode_output.xml' " + " pin_type_connected='resources/engine/images/visualcode_value_connected.png' " + " pin_type_unconnected='resources/engine/images/visualcode_value_unconnected.png' " + - " pin_color='{$" + GUIParser::escape(getScriptVariableTypePinColor(syntaxTreeNode->method->getReturnValueType())) + "}' " + + " pin_color='{$" + GUIParser::escape(getVariableTypePinColor(syntaxTreeNode->getMethod()->getReturnValueType())) + "}' " + " text='Return' " + "/>"; @@ -1126,7 +1126,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM } else // functions have a return value pin by default for now // TODO: MiniScript user functions need also formal return values a) to find out if we have a return value at all and to know the type - if (syntaxTreeNode->method == nullptr) { + if (syntaxTreeNode->getMethod() == nullptr) { string xml; // xml+= @@ -1151,7 +1151,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM } break; } - case MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: + case MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL: break; } @@ -1164,7 +1164,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM auto nextLevelXBestFit = -1; for (auto argumentIdx = 0; argumentIdx < syntaxTreeNode->arguments.size(); argumentIdx++) { // - auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; if (isLiteral == true) continue; // auto nextLevelNode = required_dynamic_cast(screenNode->getNodeById(getMiniScriptNodeFlattenedId(idMapping, id + "." + to_string(argumentIdx)))); @@ -1177,7 +1177,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM } for (auto argumentIdx = 0; argumentIdx < syntaxTreeNode->arguments.size(); argumentIdx++) { // - auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; if (isLiteral == true) continue; // auto nextLevelNode = required_dynamic_cast(screenNode->getNodeById(getMiniScriptNodeFlattenedId(idMapping, id + "." + to_string(argumentIdx)))); @@ -1190,7 +1190,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM // create connections to input nodes for (auto argumentIdx = 0; argumentIdx < syntaxTreeNode->arguments.size(); argumentIdx++) { // - auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = syntaxTreeNode->arguments[argumentIdx].type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; if (isLiteral == true) continue; // string argumentInputNodeId = flattenedId + "_a" + to_string(argumentIdx); @@ -1208,18 +1208,18 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM // auto pinColor = string("color.pintype_undefined"); - if (syntaxTreeNode->method != nullptr) { - const auto& argumentTypes = syntaxTreeNode->method->getArgumentTypes(); + if (syntaxTreeNode->getMethod() != nullptr) { + const auto& argumentTypes = syntaxTreeNode->getMethod()->getArgumentTypes(); // first guess from argument type if (argumentIdx < argumentTypes.size()) { - pinColor = getScriptVariableTypePinColor(argumentTypes[argumentIdx].type); + pinColor = getVariableTypePinColor(argumentTypes[argumentIdx].type); } // no color?, try return value if (pinColor == "color.pintype_undefined") { auto node = getNodeById(flattenedId + "." + to_string(argumentIdx)); if (node != nullptr) { - if (node->returnValueType != MiniScript::ScriptVariableType::TYPE_NULL) { - pinColor = getScriptVariableTypePinColor(node->returnValueType); + if (node->returnValueType != MiniScript::VariableType::TYPE_NULL) { + pinColor = getVariableTypePinColor(node->returnValueType); } } } @@ -1247,7 +1247,7 @@ void TextEditorTabView::createMiniScriptNodes(unordered_map& idM } } -void TextEditorTabView::createMiniScriptBranchNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const MiniScript::ScriptSyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, const vector& branches, int x, int y, int& width, int& height, vector& createdNodeIds, int depth) { +void TextEditorTabView::createMiniScriptBranchNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const MiniScript::SyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, const vector& branches, int x, int y, int& width, int& height, vector& createdNodeIds, int depth) { // auto xInitial = x; auto yInitial = y; @@ -1262,7 +1262,7 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_maptype == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL) continue; + if (branches[branchIdx].conditionSyntaxTree->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL) continue; // auto childWidth = 0; @@ -1291,7 +1291,7 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_mapvalue.getValueAsString(), - .returnValueType = MiniScript::ScriptVariableType::TYPE_NULL, + .returnValueType = MiniScript::VariableType::TYPE_NULL, .left = x, .top = y }; @@ -1358,7 +1358,7 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_maptype == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; + auto isLiteral = branches[branchIdx].conditionSyntaxTree->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL; auto literal = isLiteral == true?branches[branchIdx].conditionSyntaxTree->value.getValueAsString():string(); // string xml = @@ -1368,7 +1368,7 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_maptype == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL) continue; + if (branches[branchIdx].conditionSyntaxTree->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL) continue; // auto nextLevelNode = required_dynamic_cast(screenNode->getNodeById(getMiniScriptNodeFlattenedId(idMapping, id + "." + to_string(branchIdx)))); auto nodeXPosition = nextLevelNode->getRequestsConstraints().left; @@ -1439,7 +1439,7 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_maptype == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL) continue; + if (branches[branchIdx].conditionSyntaxTree->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL) continue; // auto nextLevelNode = required_dynamic_cast(screenNode->getNodeById(getMiniScriptNodeFlattenedId(idMapping, id + "." + to_string(branchIdx)))); auto nodeXPosition = nextLevelNode->getRequestsConstraints().left; @@ -1452,7 +1452,7 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_maptype == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL)) continue; + (branches[branchIdx].conditionSyntaxTree != nullptr && branches[branchIdx].conditionSyntaxTree->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_LITERAL)) continue; // string conditionInputNodeId = flattenedId + "_c" + to_string(branchIdx); string conditionOutputNodeId = getMiniScriptNodeFlattenedId(idMapping, id + "." + to_string(branchIdx)); @@ -1660,12 +1660,12 @@ void TextEditorTabView::createMiniScriptBranchNodes(unordered_map& idMapping, const string& idPrefix, const vector& syntaxTree, int& i, int x, int y, int& width, int& height, vector& createdNodeIds) { +bool TextEditorTabView::handleMiniScriptBranch(unordered_map& idMapping, const string& idPrefix, const vector& syntaxTree, int& i, int x, int y, int& width, int& height, vector& createdNodeIds) { // auto syntaxTreeNode = syntaxTree[i]; auto syntaxTreeNodeIdx = i; // handle if - if (syntaxTreeNode->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && + if (syntaxTreeNode->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && (syntaxTreeNode->value.getValueAsString() == "if" || syntaxTreeNode->value.getValueAsString() == "forCondition" || syntaxTreeNode->value.getValueAsString() == "forTime")) { @@ -1682,14 +1682,14 @@ bool TextEditorTabView::handleMiniScriptBranch(unordered_map& id ); for (i++; i < syntaxTree.size(); i++) { auto branchSyntaxTreeNode = syntaxTree[i]; - if (branchSyntaxTreeNode->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && + if (branchSyntaxTreeNode->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && (branchSyntaxTreeNode->value.getValueAsString() == "if" || branchSyntaxTreeNode->value.getValueAsString() == "forCondition" || branchSyntaxTreeNode->value.getValueAsString() == "forTime")) { stackDepth++; branches[branches.size() - 1].syntaxTreeNodes.push_back(branchSyntaxTreeNode); } else - if (ifStatement == true && stackDepth == 1 && branchSyntaxTreeNode->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && branchSyntaxTreeNode->value.getValueAsString() == "elseif") { + if (ifStatement == true && stackDepth == 1 && branchSyntaxTreeNode->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && branchSyntaxTreeNode->value.getValueAsString() == "elseif") { branches.push_back( { .name = branchSyntaxTreeNode->value.getValueAsString(), @@ -1698,7 +1698,7 @@ bool TextEditorTabView::handleMiniScriptBranch(unordered_map& id } ); } else - if (ifStatement == true && stackDepth == 1 && branchSyntaxTreeNode->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && branchSyntaxTreeNode->value.getValueAsString() == "else") { + if (ifStatement == true && stackDepth == 1 && branchSyntaxTreeNode->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && branchSyntaxTreeNode->value.getValueAsString() == "else") { branches.push_back( { .name = branchSyntaxTreeNode->value.getValueAsString(), @@ -1707,7 +1707,7 @@ bool TextEditorTabView::handleMiniScriptBranch(unordered_map& id } ); } else - if (branchSyntaxTreeNode->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && branchSyntaxTreeNode->value.getValueAsString() == "end") { + if (branchSyntaxTreeNode->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && branchSyntaxTreeNode->value.getValueAsString() == "end") { // stackDepth--; // done? @@ -1771,11 +1771,11 @@ void TextEditorTabView::updateMiniScriptSyntaxTree(int miniScriptScriptIdx) { // copy syntax tree auto syntaxTree = textEditorTabController->getMiniScriptSyntaxTrees()[miniScriptScriptIdx].syntaxTree; // construct syntax tree as vector of pointers to the nodes - vector syntaxTreeNodes; + vector syntaxTreeNodes; for (auto& syntaxTreeNode: syntaxTree) syntaxTreeNodes.push_back(&syntaxTreeNode); // remove end node if we have any if (syntaxTreeNodes.empty() == false && - syntaxTreeNodes[syntaxTreeNodes.size() - 1]->type == MiniScript::ScriptSyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && + syntaxTreeNodes[syntaxTreeNodes.size() - 1]->type == MiniScript::SyntaxTreeNode::SCRIPTSYNTAXTREENODE_EXECUTE_METHOD && syntaxTreeNodes[syntaxTreeNodes.size() - 1]->value.getValueAsString() == "end") { syntaxTreeNodes.erase(syntaxTreeNodes.begin() + syntaxTreeNodes.size() - 1); } @@ -2064,8 +2064,8 @@ void TextEditorTabView::createSourceCodeFromNode(string& sourceCode, const Node* auto literalInputValue = literalInput->getController()->getValue().getString(); if (argumentsSourceCode.empty() == false) argumentsSourceCode+= ", "; // implicitely literal - MiniScript::ScriptVariable value; - MiniScript::ScriptStatement scriptStatement( + MiniScript::Variable value; + MiniScript::Statement scriptStatement( MiniScript::LINE_NONE, MiniScript::STATEMENTIDX_NONE, string(), diff --git a/src/tdme/tools/editor/tabviews/TextEditorTabView.h b/src/tdme/tools/editor/tabviews/TextEditorTabView.h index 14335d201..76c8129f1 100644 --- a/src/tdme/tools/editor/tabviews/TextEditorTabView.h +++ b/src/tdme/tools/editor/tabviews/TextEditorTabView.h @@ -89,7 +89,7 @@ class tdme::tools::editor::tabviews::TextEditorTabView final string id; NodeType type { NODETYPE_NONE }; string value; - EngineMiniScript::ScriptVariableType returnValueType; + EngineMiniScript::VariableType returnValueType; int left; int top; }; @@ -111,8 +111,8 @@ class tdme::tools::editor::tabviews::TextEditorTabView final struct MiniScriptBranch { string name; - EngineMiniScript::ScriptSyntaxTreeNode* conditionSyntaxTree { nullptr }; - vector syntaxTreeNodes; + EngineMiniScript::SyntaxTreeNode* conditionSyntaxTree { nullptr }; + vector syntaxTreeNodes; }; unordered_map methodOperatorMap; @@ -297,15 +297,15 @@ class tdme::tools::editor::tabviews::TextEditorTabView final * @param type type * @return string with color property name from theme */ - inline const string getScriptVariableTypePinColor(EngineMiniScript::ScriptVariableType type) { + inline const string getVariableTypePinColor(EngineMiniScript::VariableType type) { switch (type) { - case EngineMiniScript::ScriptVariableType::TYPE_BOOLEAN: + case EngineMiniScript::VariableType::TYPE_BOOLEAN: return string("color.pintype_boolean"); - case EngineMiniScript::ScriptVariableType::TYPE_INTEGER: + case EngineMiniScript::VariableType::TYPE_INTEGER: return string("color.pintype_integer"); - case EngineMiniScript::ScriptVariableType::TYPE_FLOAT: + case EngineMiniScript::VariableType::TYPE_FLOAT: return string("color.pintype_float"); - case EngineMiniScript::ScriptVariableType::TYPE_STRING: + case EngineMiniScript::VariableType::TYPE_STRING: return string("color.pintype_string"); case EngineMiniScript::TYPE_VECTOR2: case EngineMiniScript::TYPE_VECTOR3: @@ -316,13 +316,13 @@ class tdme::tools::editor::tabviews::TextEditorTabView final case EngineMiniScript::TYPE_MATRIX4x4: case EngineMiniScript::TYPE_TRANSFORM: return string("color.pintype_transform"); - case EngineMiniScript::ScriptVariableType::TYPE_ARRAY: - case EngineMiniScript::ScriptVariableType::TYPE_MAP: - case EngineMiniScript::ScriptVariableType::TYPE_SET: - case EngineMiniScript::ScriptVariableType::TYPE_PSEUDO_MIXED: - case EngineMiniScript::ScriptVariableType::TYPE_NULL: + case EngineMiniScript::VariableType::TYPE_ARRAY: + case EngineMiniScript::VariableType::TYPE_MAP: + case EngineMiniScript::VariableType::TYPE_SET: + case EngineMiniScript::VariableType::TYPE_PSEUDO_MIXED: + case EngineMiniScript::VariableType::TYPE_NULL: return string("color.pintype_undefined"); - case EngineMiniScript::ScriptVariableType::TYPE_PSEUDO_NUMBER: + case EngineMiniScript::VariableType::TYPE_PSEUDO_NUMBER: return string("color.pintype_float"); } return string("color.pintype_undefined"); @@ -475,7 +475,7 @@ class tdme::tools::editor::tabviews::TextEditorTabView final * @param syntaxTreeNode syntax tree node * @param deltaX delta X */ - void addMiniScriptNodeDeltaX(unordered_map& idMapping, const string& id, const EngineMiniScript::ScriptSyntaxTreeNode& syntaxTreeNode, int deltaX); + void addMiniScriptNodeDeltaX(unordered_map& idMapping, const string& id, const EngineMiniScript::SyntaxTreeNode& syntaxTreeNode, int deltaX); /** * Create UI nodes for EngineMiniScript script node syntax tree, which matches a event or function in EngineMiniScript @@ -491,7 +491,7 @@ class tdme::tools::editor::tabviews::TextEditorTabView final * @param height height * @param createdNodeIds created node ids */ - void createMiniScriptScriptNode(unordered_map& idMapping, const string& id, EngineMiniScript::Script::ScriptType scriptType, const string& condition, const string& readableName, const EngineMiniScript::ScriptSyntaxTreeNode* conditionSyntaxTreeNode, int x, int y, int& width, int& height); + void createMiniScriptScriptNode(unordered_map& idMapping, const string& id, EngineMiniScript::Script::ScriptType scriptType, const string& condition, const string& readableName, const EngineMiniScript::SyntaxTreeNode* conditionSyntaxTreeNode, int x, int y, int& width, int& height); /** * Create UI nodes for given statement syntax tree, which matches a statement in miniscript @@ -508,7 +508,7 @@ class tdme::tools::editor::tabviews::TextEditorTabView final * @oaram createdNodeIds created node ids * @param depth depth */ - void createMiniScriptNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const EngineMiniScript::ScriptSyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, int x, int y, int& width, int& height, vector& createdNodeIds, int depth = 0); + void createMiniScriptNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const EngineMiniScript::SyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, int x, int y, int& width, int& height, vector& createdNodeIds, int depth = 0); /** * Create UI nodes for branch nodes like if, elseif, else, end; forTime, end; forCondition, end @@ -526,7 +526,7 @@ class tdme::tools::editor::tabviews::TextEditorTabView final * @oaram createdNodeIds created node ids * @param depth depth */ - void createMiniScriptBranchNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const EngineMiniScript::ScriptSyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, const vector& branches, int x, int y, int& width, int& height, vector& createdNodeIds, int depth = 0); + void createMiniScriptBranchNodes(unordered_map& idMapping, const string& id, int syntaxTreeNodeIdx, int syntaxTreeNodeCount, const EngineMiniScript::SyntaxTreeNode* syntaxTreeNode, Node::NodeType nodeType, const vector& branches, int x, int y, int& width, int& height, vector& createdNodeIds, int depth = 0); /** * @return EngineMiniScript script index @@ -555,7 +555,7 @@ class tdme::tools::editor::tabviews::TextEditorTabView final * @param height height * @oaram createdNodeIds created node ids */ - bool handleMiniScriptBranch(unordered_map& idMapping, const string& idPrefix, const vector& syntaxTree, int& i, int x, int y, int& width, int& height, vector& createdNodeIds); + bool handleMiniScriptBranch(unordered_map& idMapping, const string& idPrefix, const vector& syntaxTree, int& i, int x, int y, int& width, int& height, vector& createdNodeIds); /** * Update miniscript syntax tree diff --git a/src/tdme/utilities/EngineMiniScript.h b/src/tdme/utilities/EngineMiniScript.h index d9e48ef5f..48e7ef9ee 100644 --- a/src/tdme/utilities/EngineMiniScript.h +++ b/src/tdme/utilities/EngineMiniScript.h @@ -65,13 +65,13 @@ class tdme::utilities::EngineMiniScript: public MiniScript { // custom data types, which needs to be created in this particular order // we could also read the types dynamically, but this works for now :) - static constexpr ScriptVariableType TYPE_TRANSFORM { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES) }; - static constexpr ScriptVariableType TYPE_MATRIX4x4 { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 1) }; - static constexpr ScriptVariableType TYPE_MATRIX3x3 { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 2) }; - static constexpr ScriptVariableType TYPE_QUATERNION { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 3) }; - static constexpr ScriptVariableType TYPE_VECTOR2 { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 4) }; - static constexpr ScriptVariableType TYPE_VECTOR3 { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 5) }; - static constexpr ScriptVariableType TYPE_VECTOR4 { static_cast(ScriptVariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 6) }; + static constexpr VariableType TYPE_TRANSFORM { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES) }; + static constexpr VariableType TYPE_MATRIX4x4 { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 1) }; + static constexpr VariableType TYPE_MATRIX3x3 { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 2) }; + static constexpr VariableType TYPE_QUATERNION { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 3) }; + static constexpr VariableType TYPE_VECTOR2 { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 4) }; + static constexpr VariableType TYPE_VECTOR3 { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 5) }; + static constexpr VariableType TYPE_VECTOR4 { static_cast(VariableType::TYPE_PSEUDO_CUSTOM_DATATYPES + 6) }; /** * Register data types @@ -102,7 +102,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline bool getVector2Value(const span& arguments, int idx, Vector2& value, bool optional = false) { + inline bool getVector2Value(const span& arguments, int idx, Vector2& value, bool optional = false) { return MiniScriptVector2::getVector2Value(TYPE_VECTOR2, arguments, idx, value, optional); } @@ -114,7 +114,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline bool getVector3Value(const span& arguments, int idx, Vector3& value, bool optional = false) { + inline bool getVector3Value(const span& arguments, int idx, Vector3& value, bool optional = false) { return MiniScriptVector3::getVector3Value(TYPE_VECTOR3, arguments, idx, value, optional); } @@ -126,7 +126,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline bool getVector4Value(const span& arguments, int idx, Vector4& value, bool optional = false) { + inline bool getVector4Value(const span& arguments, int idx, Vector4& value, bool optional = false) { return MiniScriptVector4::getVector4Value(TYPE_VECTOR4, arguments, idx, value, optional); } @@ -138,7 +138,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline static bool getQuaternionValue(const span& arguments, int idx, Quaternion& value, bool optional = false) { + inline static bool getQuaternionValue(const span& arguments, int idx, Quaternion& value, bool optional = false) { return MiniScriptQuaternion::getQuaternionValue(TYPE_QUATERNION, arguments, idx, value, optional); } @@ -150,7 +150,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline static bool getMatrix3x3Value(const span& arguments, int idx, Matrix3x3& value, bool optional = false) { + inline static bool getMatrix3x3Value(const span& arguments, int idx, Matrix3x3& value, bool optional = false) { return MiniScriptMatrix3x3::getMatrix3x3Value(TYPE_MATRIX3x3, arguments, idx, value, optional); } @@ -162,7 +162,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline static bool getMatrix4x4Value(const span& arguments, int idx, Matrix4x4& value, bool optional = false) { + inline static bool getMatrix4x4Value(const span& arguments, int idx, Matrix4x4& value, bool optional = false) { return MiniScriptMatrix4x4::getMatrix4x4Value(TYPE_MATRIX4x4, arguments, idx, value, optional); } @@ -174,7 +174,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param optional optional * @return success */ - inline static bool getTransformValue(const span& arguments, int idx, Transform& value, bool optional = false) { + inline static bool getTransformValue(const span& arguments, int idx, Transform& value, bool optional = false) { return MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, arguments, idx, value, optional); } @@ -183,7 +183,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, bool value) { + inline void setValue(Variable& variable, bool value) { variable.setValue(value); } @@ -192,7 +192,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, int64_t value) { + inline void setValue(Variable& variable, int64_t value) { variable.setValue(value); } @@ -201,7 +201,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, float value) { + inline void setValue(Variable& variable, float value) { variable.setValue(value); } @@ -210,7 +210,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const string& value) { + inline void setValue(Variable& variable, const string& value) { variable.setValue(value); } @@ -219,7 +219,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const vector& value) { + inline void setValue(Variable& variable, const vector& value) { variable.setValue(value); } @@ -228,7 +228,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const unordered_map& value) { + inline void setValue(Variable& variable, const unordered_map& value) { variable.setValue(value); } @@ -237,7 +237,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const unordered_set& value) { + inline void setValue(Variable& variable, const unordered_set& value) { variable.setValue(value); } @@ -246,7 +246,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Vector2& value) { + inline void setValue(Variable& variable, const Vector2& value) { variable.setType(TYPE_VECTOR2); variable.setValue(&value); } @@ -256,7 +256,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Vector3& value) { + inline void setValue(Variable& variable, const Vector3& value) { variable.setType(TYPE_VECTOR3); variable.setValue(&value); } @@ -266,7 +266,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Vector4& value) { + inline void setValue(Variable& variable, const Vector4& value) { variable.setType(TYPE_VECTOR4); variable.setValue(&value); } @@ -275,7 +275,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * Set vector3 value from given value into variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Quaternion& value) { + inline void setValue(Variable& variable, const Quaternion& value) { variable.setType(TYPE_QUATERNION); variable.setValue(&value); } @@ -285,7 +285,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Matrix3x3& value) { + inline void setValue(Variable& variable, const Matrix3x3& value) { variable.setType(TYPE_MATRIX3x3); variable.setValue(&value); } @@ -295,7 +295,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Matrix4x4& value) { + inline void setValue(Variable& variable, const Matrix4x4& value) { variable.setType(TYPE_MATRIX4x4); variable.setValue(&value); } @@ -305,7 +305,7 @@ class tdme::utilities::EngineMiniScript: public MiniScript { * @param variable variable * @param value value */ - inline void setValue(ScriptVariable& variable, const Transform& value) { + inline void setValue(Variable& variable, const Transform& value) { variable.setType(TYPE_TRANSFORM); variable.setValue(&value); } diff --git a/src/tdme/utilities/MiniScriptMatrix3x3.cpp b/src/tdme/utilities/MiniScriptMatrix3x3.cpp index abecbd02c..485b6a9b8 100644 --- a/src/tdme/utilities/MiniScriptMatrix3x3.cpp +++ b/src/tdme/utilities/MiniScriptMatrix3x3.cpp @@ -25,30 +25,29 @@ using tdme::utilities::Console; using tdme::utilities::Float; using tdme::utilities::MiniScriptVector2; -const string MiniScriptMatrix3x3::CLASS_NAME = "mat3"; const string MiniScriptMatrix3x3::TYPE_NAME = "Matrix3x3"; void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { - const auto TYPE_MATRIX3x3 = static_cast(getType()); - const auto TYPE_VECTOR2 = static_cast(miniScript->getDataTypeByClassName("vec2")->getType()); + const auto TYPE_MATRIX3x3 = static_cast(getType()); + const auto TYPE_VECTOR2 = static_cast(miniScript->getDataTypeByClassName("Vector2")->getType()); // { // - class ScriptMethodMatrix3x3Identity: public MiniScript::ScriptMethod { + class ScriptMethodMatrix3x3Identity: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX3x3; + MiniScript::VariableType TYPE_MATRIX3x3; public: ScriptMethodMatrix3x3Identity( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX3x3 + MiniScript::VariableType TYPE_MATRIX3x3 ): - MiniScript::ScriptMethod({}, TYPE_MATRIX3x3), + MiniScript::Method({}, TYPE_MATRIX3x3), miniScript(miniScript), TYPE_MATRIX3x3(TYPE_MATRIX3x3) {} const string getMethodName() override { - return "mat3.identity"; + return "Matrix3x3::identity"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { const auto result = Matrix3x3().identity(); returnValue.setType(TYPE_MATRIX3x3); returnValue.setValue(&result); @@ -58,18 +57,18 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix3x3Translate: public MiniScript::ScriptMethod { + class ScriptMethodMatrix3x3Translate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX3x3; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_MATRIX3x3; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodMatrix3x3Translate( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX3x3, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_MATRIX3x3, + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "translation", .optional = false, .reference = false, .nullable = false }, }, @@ -77,9 +76,9 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_MATRIX3x3(TYPE_MATRIX3x3), TYPE_VECTOR2(TYPE_VECTOR2) {} const string getMethodName() override { - return "mat3.translate"; + return "Matrix3x3::translate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 translation; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, translation, false) == true) { const auto result = Matrix3x3().identity().setTranslation(translation); @@ -95,26 +94,26 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix3x3Rotate: public MiniScript::ScriptMethod { + class ScriptMethodMatrix3x3Rotate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX3x3; + MiniScript::VariableType TYPE_MATRIX3x3; public: ScriptMethodMatrix3x3Rotate( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX3x3 + MiniScript::VariableType TYPE_MATRIX3x3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, }, TYPE_MATRIX3x3 ), miniScript(miniScript), TYPE_MATRIX3x3(TYPE_MATRIX3x3) {} const string getMethodName() override { - return "mat3.rotate"; + return "Matrix3x3::rotate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float angle; if (MiniScript::getFloatValue(argumentValues, 0, angle, false) == true) { const auto result = Matrix3x3().identity().setAxes(angle); @@ -130,26 +129,26 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix3x3RotateAroundTextureCenter: public MiniScript::ScriptMethod { + class ScriptMethodMatrix3x3RotateAroundTextureCenter: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX3x3; + MiniScript::VariableType TYPE_MATRIX3x3; public: ScriptMethodMatrix3x3RotateAroundTextureCenter( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX3x3 + MiniScript::VariableType TYPE_MATRIX3x3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, }, TYPE_MATRIX3x3 ), miniScript(miniScript), TYPE_MATRIX3x3(TYPE_MATRIX3x3) {} const string getMethodName() override { - return "mat3.rotateAroundTextureCenter"; + return "Matrix3x3::rotateAroundTextureCenter"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float angle; if (MiniScript::getFloatValue(argumentValues, 0, angle, false) == true) { const auto result = Matrix3x3::rotateAroundTextureCenter(angle); @@ -165,29 +164,29 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix3x3RotateAroundPoint: public MiniScript::ScriptMethod { + class ScriptMethodMatrix3x3RotateAroundPoint: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX3x3; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_MATRIX3x3; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodMatrix3x3RotateAroundPoint( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX3x3, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_MATRIX3x3, + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "point", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, }, TYPE_MATRIX3x3 ), miniScript(miniScript), TYPE_MATRIX3x3(TYPE_MATRIX3x3), TYPE_VECTOR2(TYPE_VECTOR2) {} const string getMethodName() override { - return "mat3.rotateAroundPoint"; + return "Matrix3x3::rotateAroundPoint"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 point; float angle; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, point, false) == true && @@ -205,23 +204,23 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix3x3Scale: public MiniScript::ScriptMethod { + class ScriptMethodMatrix3x3Scale: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX3x3; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_MATRIX3x3; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodMatrix3x3Scale( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX3x3, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_MATRIX3x3, + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod({}, TYPE_MATRIX3x3), + MiniScript::Method({}, TYPE_MATRIX3x3), miniScript(miniScript), TYPE_MATRIX3x3(TYPE_MATRIX3x3), TYPE_VECTOR2(TYPE_VECTOR2) {} const string getMethodName() override { - return "mat3.scale"; + return "Matrix3x3::scale"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 vec2Value; float floatValue; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, vec2Value, false) == true) { @@ -247,7 +246,7 @@ void MiniScriptMatrix3x3::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptMatrix3x3::unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const { +void MiniScriptMatrix3x3::unsetVariableValue(MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -255,7 +254,7 @@ void MiniScriptMatrix3x3::unsetScriptVariableValue(MiniScript::ScriptVariable& v variable.setValuePtr(0ll); } -void MiniScriptMatrix3x3::setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptMatrix3x3::setVariableValue(MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Matrix3x3 matrix3x3Value; @@ -271,21 +270,21 @@ void MiniScriptMatrix3x3::setScriptVariableValue(MiniScript::ScriptVariable& var variable.setValuePtr((uint64_t)(new Matrix3x3(matrix3x3Value))); } -void MiniScriptMatrix3x3::copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const { +void MiniScriptMatrix3x3::copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const { // Matrix3x3 matrix3x3Value; if (from.getType() == getType() && from.getValuePtr() != 0ll) { matrix3x3Value = *static_cast((void*)from.getValuePtr()); } // - const auto TYPE_MATRIX3x3 = static_cast(getType()); + const auto TYPE_MATRIX3x3 = static_cast(getType()); to.setType(TYPE_MATRIX3x3); *static_cast((void*)to.getValuePtr()) = matrix3x3Value; } -bool MiniScriptMatrix3x3::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_MATRIX3x3 = static_cast(getType()); - const auto TYPE_VECTOR2 = static_cast(miniScript->getDataTypeByClassName("vec2")->getType()); +bool MiniScriptMatrix3x3::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_MATRIX3x3 = static_cast(getType()); + const auto TYPE_VECTOR2 = static_cast(miniScript->getDataTypeByClassName("Vector2")->getType()); // if (MiniScript::hasType(argumentValues, TYPE_MATRIX3x3) == true) { // matrix3x3 * matrix @@ -332,7 +331,7 @@ bool MiniScriptMatrix3x3::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptMatrix3x3::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptMatrix3x3::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptMatrix3x3::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptMatrix3x3::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptMatrix3x3::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -const string& MiniScriptMatrix3x3::getClassName() const { - return CLASS_NAME; -} - const string& MiniScriptMatrix3x3::getTypeAsString() const { return TYPE_NAME; } -const string MiniScriptMatrix3x3::getValueAsString(const MiniScript::ScriptVariable& variable) const { +const string MiniScriptMatrix3x3::getValueAsString(const MiniScript::Variable& variable) const { // Matrix3x3 matrix3x3Value; if (variable.getType() == getType() && variable.getValuePtr() != 0ll) { diff --git a/src/tdme/utilities/MiniScriptMatrix3x3.h b/src/tdme/utilities/MiniScriptMatrix3x3.h index 29c975622..b42c57ff4 100644 --- a/src/tdme/utilities/MiniScriptMatrix3x3.h +++ b/src/tdme/utilities/MiniScriptMatrix3x3.h @@ -18,21 +18,20 @@ using tdme::math::Matrix3x3; * MiniScript Matrix3x3 data type * @author Andreas Drewke */ -class tdme::utilities::MiniScriptMatrix3x3 final: public MiniScript::ScriptDataType { +class tdme::utilities::MiniScriptMatrix3x3 final: public MiniScript::DataType { private: // overridden methods void registerMethods(MiniScript* miniScript) const override; - void unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const override; - void setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const override; - void copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const override; - bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get matrix3x3 value from given variable @@ -43,7 +42,7 @@ class tdme::utilities::MiniScriptMatrix3x3 final: public MiniScript::ScriptDataT * @param optional optional * @return success */ - static inline bool getMatrix3x3Value(MiniScript::ScriptVariableType TYPE_MATRIX3x3, const span& arguments, int idx, Matrix3x3& value, bool optional = false) { + static inline bool getMatrix3x3Value(MiniScript::VariableType TYPE_MATRIX3x3, const span& arguments, int idx, Matrix3x3& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_MATRIX3x3) { @@ -62,13 +61,12 @@ class tdme::utilities::MiniScriptMatrix3x3 final: public MiniScript::ScriptDataT * MiniScript Matrix3x3 data type * @param miniScript mini script instance */ - MiniScriptMatrix3x3(): MiniScript::ScriptDataType(true) { + MiniScriptMatrix3x3(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; }; diff --git a/src/tdme/utilities/MiniScriptMatrix4x4.cpp b/src/tdme/utilities/MiniScriptMatrix4x4.cpp index a708d5314..046229de8 100644 --- a/src/tdme/utilities/MiniScriptMatrix4x4.cpp +++ b/src/tdme/utilities/MiniScriptMatrix4x4.cpp @@ -25,30 +25,29 @@ using tdme::utilities::Float; using tdme::utilities::MiniScriptVector3; using tdme::utilities::MiniScriptVector4; -const string MiniScriptMatrix4x4::CLASS_NAME = "mat4"; const string MiniScriptMatrix4x4::TYPE_NAME = "Matrix4x4"; void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { - const auto TYPE_MATRIX4x4 = static_cast(getType()); - const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("vec3")->getType()); + const auto TYPE_MATRIX4x4 = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("Vector3")->getType()); // { // - class ScriptMethodMatrix4x4Identity: public MiniScript::ScriptMethod { + class ScriptMethodMatrix4x4Identity: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_MATRIX4x4; public: ScriptMethodMatrix4x4Identity( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX4x4 + MiniScript::VariableType TYPE_MATRIX4x4 ): - MiniScript::ScriptMethod({}, TYPE_MATRIX4x4), + MiniScript::Method({}, TYPE_MATRIX4x4), miniScript(miniScript), TYPE_MATRIX4x4(TYPE_MATRIX4x4) {} const string getMethodName() override { - return "mat4.identity"; + return "Matrix4x4.identity"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { const auto result = Matrix4x4().identity(); returnValue.setType(TYPE_MATRIX4x4); returnValue.setValue(&result); @@ -58,18 +57,18 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix4x4Translate: public MiniScript::ScriptMethod { + class ScriptMethodMatrix4x4Translate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodMatrix4x4Translate( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX4x4, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_MATRIX4x4, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "translation", .optional = false, .reference = false, .nullable = false }, }, @@ -77,9 +76,9 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_MATRIX4x4(TYPE_MATRIX4x4), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "mat4.translate"; + return "Matrix4x4.translate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 translation; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, translation, false) == true) { const auto result = Matrix4x4().identity().setTranslation(translation); @@ -95,29 +94,29 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix4x4Rotate: public MiniScript::ScriptMethod { + class ScriptMethodMatrix4x4Rotate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodMatrix4x4Rotate( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX4x4, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_MATRIX4x4, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "axis", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, }, TYPE_MATRIX4x4 ), miniScript(miniScript), TYPE_MATRIX4x4(TYPE_MATRIX4x4), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "mat4.rotate"; + return "Matrix4x4.rotate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 axis; float angle; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, axis, false) == true && @@ -135,23 +134,23 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix4x4Scale: public MiniScript::ScriptMethod { + class ScriptMethodMatrix4x4Scale: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodMatrix4x4Scale( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX4x4, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_MATRIX4x4, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod({}, TYPE_MATRIX4x4), + MiniScript::Method({}, TYPE_MATRIX4x4), miniScript(miniScript), TYPE_MATRIX4x4(TYPE_MATRIX4x4), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "mat4.scale"; + return "Matrix4x4.scale"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3Value; float floatValue; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3Value, false) == true) { @@ -177,16 +176,16 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix4x4Invert: public MiniScript::ScriptMethod { + class ScriptMethodMatrix4x4Invert: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_MATRIX4x4; public: ScriptMethodMatrix4x4Invert( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX4x4 + MiniScript::VariableType TYPE_MATRIX4x4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_MATRIX4x4, .name = "mat4", .optional = false, .reference = false, .nullable = false }, }, @@ -194,9 +193,9 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_MATRIX4x4(TYPE_MATRIX4x4) {} const string getMethodName() override { - return "mat4.invert"; + return "Matrix4x4.invert"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Matrix4x4 mat4; if (MiniScriptMatrix4x4::getMatrix4x4Value(TYPE_MATRIX4x4, argumentValues, 0, mat4, false) == true) { const auto result = mat4.invert(); @@ -212,18 +211,18 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodMatrix4x4EulerAngles: public MiniScript::ScriptMethod { + class ScriptMethodMatrix4x4EulerAngles: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodMatrix4x4EulerAngles( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_MATRIX4x4, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_MATRIX4x4, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_MATRIX4x4, .name = "mat4", .optional = false, .reference = false, .nullable = false }, }, @@ -231,9 +230,9 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_MATRIX4x4(TYPE_MATRIX4x4), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "mat4.computeEulerAngles"; + return "Matrix4x4.computeEulerAngles"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Matrix4x4 mat4; if (MiniScriptMatrix4x4::getMatrix4x4Value(TYPE_MATRIX4x4, argumentValues, 0, mat4, false) == true) { const auto result = mat4.computeEulerAngles(); @@ -249,7 +248,7 @@ void MiniScriptMatrix4x4::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptMatrix4x4::unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const { +void MiniScriptMatrix4x4::unsetVariableValue(MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -257,7 +256,7 @@ void MiniScriptMatrix4x4::unsetScriptVariableValue(MiniScript::ScriptVariable& v variable.setValuePtr(0ll); } -void MiniScriptMatrix4x4::setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptMatrix4x4::setVariableValue(MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Matrix4x4 matrix4x4Value; @@ -273,22 +272,22 @@ void MiniScriptMatrix4x4::setScriptVariableValue(MiniScript::ScriptVariable& var variable.setValuePtr((uint64_t)(new Matrix4x4(matrix4x4Value))); } -void MiniScriptMatrix4x4::copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const { +void MiniScriptMatrix4x4::copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const { // Matrix4x4 matrix4x4Value; if (from.getType() == getType() && from.getValuePtr() != 0ll) { matrix4x4Value = *static_cast((void*)from.getValuePtr()); } // - const auto TYPE_MATRIX4x4 = static_cast(getType()); + const auto TYPE_MATRIX4x4 = static_cast(getType()); to.setType(TYPE_MATRIX4x4); *static_cast((void*)to.getValuePtr()) = matrix4x4Value; } -bool MiniScriptMatrix4x4::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_MATRIX4x4 = static_cast(getType()); - const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("vec3")->getType()); - const auto TYPE_VECTOR4 = static_cast(miniScript->getDataTypeByClassName("vec4")->getType()); +bool MiniScriptMatrix4x4::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_MATRIX4x4 = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("Vector3")->getType()); + const auto TYPE_VECTOR4 = static_cast(miniScript->getDataTypeByClassName("Vector4")->getType()); // if (MiniScript::hasType(argumentValues, TYPE_MATRIX4x4) == true) { // matrix4x4 * matrix @@ -364,7 +363,7 @@ bool MiniScriptMatrix4x4::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptMatrix4x4::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptMatrix4x4::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptMatrix4x4::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptMatrix4x4::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptMatrix4x4::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -const string& MiniScriptMatrix4x4::getClassName() const { - return CLASS_NAME; -} - const string& MiniScriptMatrix4x4::getTypeAsString() const { return TYPE_NAME; } -const string MiniScriptMatrix4x4::getValueAsString(const MiniScript::ScriptVariable& variable) const { +const string MiniScriptMatrix4x4::getValueAsString(const MiniScript::Variable& variable) const { // Matrix4x4 matrix4x4Value; if (variable.getType() == getType() && variable.getValuePtr() != 0ll) { diff --git a/src/tdme/utilities/MiniScriptMatrix4x4.h b/src/tdme/utilities/MiniScriptMatrix4x4.h index ab1f5aa7a..9d0e2a3cb 100644 --- a/src/tdme/utilities/MiniScriptMatrix4x4.h +++ b/src/tdme/utilities/MiniScriptMatrix4x4.h @@ -18,21 +18,20 @@ using tdme::math::Matrix4x4; * MiniScript Matrix4x4 data type * @author Andreas Drewke */ -class tdme::utilities::MiniScriptMatrix4x4 final: public MiniScript::ScriptDataType { +class tdme::utilities::MiniScriptMatrix4x4 final: public MiniScript::DataType { private: // overridden methods void registerMethods(MiniScript* miniScript) const override; - void unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const override; - void setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const override; - void copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const override; - bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get matrix4x4 value from given variable @@ -43,7 +42,7 @@ class tdme::utilities::MiniScriptMatrix4x4 final: public MiniScript::ScriptDataT * @param optional optional * @return success */ - static inline bool getMatrix4x4Value(MiniScript::ScriptVariableType TYPE_MATRIX4x4, const span& arguments, int idx, Matrix4x4& value, bool optional = false) { + static inline bool getMatrix4x4Value(MiniScript::VariableType TYPE_MATRIX4x4, const span& arguments, int idx, Matrix4x4& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_MATRIX4x4) { @@ -60,13 +59,12 @@ class tdme::utilities::MiniScriptMatrix4x4 final: public MiniScript::ScriptDataT /** * MiniScript Matrix4x4 data type */ - MiniScriptMatrix4x4(): MiniScript::ScriptDataType(true) { + MiniScriptMatrix4x4(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; }; diff --git a/src/tdme/utilities/MiniScriptQuaternion.cpp b/src/tdme/utilities/MiniScriptQuaternion.cpp index 5f6898c09..14caebcf0 100644 --- a/src/tdme/utilities/MiniScriptQuaternion.cpp +++ b/src/tdme/utilities/MiniScriptQuaternion.cpp @@ -25,32 +25,31 @@ using tdme::utilities::Float; using tdme::utilities::MiniScriptMatrix4x4; using tdme::utilities::MiniScriptVector3; -const string MiniScriptQuaternion::CLASS_NAME = "quaternion"; const string MiniScriptQuaternion::TYPE_NAME = "Quaternion"; void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { - const auto TYPE_QUATERNION = static_cast(getType()); - const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("vec3")->getType()); - const auto TYPE_MATRIX4x4 = static_cast(miniScript->getDataTypeByClassName("mat4")->getType()); + const auto TYPE_QUATERNION = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("Vector3")->getType()); + const auto TYPE_MATRIX4x4 = static_cast(miniScript->getDataTypeByClassName("Matrix4x4")->getType()); { // - class ScriptMethodQuaternionIdentity: public MiniScript::ScriptMethod { + class ScriptMethodQuaternionIdentity: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_QUATERNION; public: ScriptMethodQuaternionIdentity( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_QUATERNION + MiniScript::VariableType TYPE_QUATERNION ): - MiniScript::ScriptMethod({}, TYPE_QUATERNION), + MiniScript::Method({}, TYPE_QUATERNION), miniScript(miniScript), TYPE_QUATERNION(TYPE_QUATERNION) { // } const string getMethodName() override { - return "quaternion.identity"; + return "Quaternion::identity"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { auto result = Quaternion().identity(); returnValue.setType(TYPE_QUATERNION); returnValue.setValue(&result); @@ -60,16 +59,16 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodQuaternionInvert: public MiniScript::ScriptMethod { + class ScriptMethodQuaternionInvert: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_QUATERNION; public: ScriptMethodQuaternionInvert( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_QUATERNION + MiniScript::VariableType TYPE_QUATERNION ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_QUATERNION, .name = "quaternion", .optional = false, .reference = false, .nullable = false }, }, @@ -79,9 +78,9 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "quaternion.invert"; + return "Quaternion::invert"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Quaternion quaternion; if (MiniScriptQuaternion::getQuaternionValue(TYPE_QUATERNION, argumentValues, 0, quaternion, false) == true) { auto result = quaternion.invert(); @@ -97,21 +96,21 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodQuaternionRotate: public MiniScript::ScriptMethod { + class ScriptMethodQuaternionRotate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_QUATERNION; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodQuaternionRotate( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_QUATERNION, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_QUATERNION, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "axis", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false } + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false } }, TYPE_QUATERNION ), @@ -121,9 +120,9 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "quaternion.rotate"; + return "Quaternion::rotate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 axis; float angle; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, axis, false) == true && @@ -141,16 +140,16 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodQuaternionNormalize: public MiniScript::ScriptMethod { + class ScriptMethodQuaternionNormalize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_QUATERNION; public: ScriptMethodQuaternionNormalize( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_QUATERNION + MiniScript::VariableType TYPE_QUATERNION ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_QUATERNION, .name = "quaternion", .optional = false, .reference = false, .nullable = false }, }, @@ -158,9 +157,9 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_QUATERNION(TYPE_QUATERNION) {} const string getMethodName() override { - return "quaternion.normalize"; + return "Quaternion::normalize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Quaternion quaternion; if (MiniScriptQuaternion::getQuaternionValue(TYPE_QUATERNION, argumentValues, 0, quaternion, false) == true) { auto result = quaternion.normalize(); @@ -176,18 +175,18 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodQuaternionInvert: public MiniScript::ScriptMethod { + class ScriptMethodQuaternionInvert: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_QUATERNION; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodQuaternionInvert( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_QUATERNION, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_QUATERNION, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_QUATERNION, .name = "quaternion", .optional = false, .reference = false, .nullable = false }, }, @@ -199,9 +198,9 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "quaternion.computeEulerAngles"; + return "Quaternion::computeEulerAngles"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Quaternion quaternion; if (MiniScriptQuaternion::getQuaternionValue(TYPE_QUATERNION, argumentValues, 0, quaternion, false) == true) { auto result = quaternion.computeEulerAngles(); @@ -217,18 +216,18 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodQuaternionComputeMatrix: public MiniScript::ScriptMethod { + class ScriptMethodQuaternionComputeMatrix: public MiniScript::Method { private: - MiniScript::ScriptVariableType TYPE_QUATERNION; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_MATRIX4x4; MiniScript* miniScript { nullptr }; public: ScriptMethodQuaternionComputeMatrix( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_QUATERNION, - MiniScript::ScriptVariableType TYPE_MATRIX4x4 + MiniScript::VariableType TYPE_QUATERNION, + MiniScript::VariableType TYPE_MATRIX4x4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_QUATERNION, .name = "quaternion", .optional = false, .reference = false, .nullable = false }, }, @@ -238,9 +237,9 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "quaternion.computeMatrix"; + return "Quaternion::computeMatrix"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Quaternion quaternion; if (MiniScriptQuaternion::getQuaternionValue(TYPE_QUATERNION, argumentValues, 0, quaternion, false) == true) { auto result = quaternion.computeMatrix(); @@ -256,7 +255,7 @@ void MiniScriptQuaternion::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptQuaternion::unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const { +void MiniScriptQuaternion::unsetVariableValue(MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -264,7 +263,7 @@ void MiniScriptQuaternion::unsetScriptVariableValue(MiniScript::ScriptVariable& variable.setValuePtr(0ll); } -void MiniScriptQuaternion::setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptQuaternion::setVariableValue(MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Quaternion quaternionValue; @@ -280,21 +279,21 @@ void MiniScriptQuaternion::setScriptVariableValue(MiniScript::ScriptVariable& va variable.setValuePtr((uint64_t)(new Quaternion(quaternionValue))); } -void MiniScriptQuaternion::copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const { +void MiniScriptQuaternion::copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const { // Quaternion quaternionValue; if (from.getType() == getType() && from.getValuePtr() != 0ll) { quaternionValue = *static_cast((void*)from.getValuePtr()); } // - const auto TYPE_QUATERNION = static_cast(getType()); + const auto TYPE_QUATERNION = static_cast(getType()); to.setType(TYPE_QUATERNION); *static_cast((void*)to.getValuePtr()) = quaternionValue; } -bool MiniScriptQuaternion::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_QUATERNION = static_cast(getType()); - const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("vec3")->getType()); +bool MiniScriptQuaternion::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_QUATERNION = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("Vector3")->getType()); // quaternion if (MiniScript::hasType(argumentValues, TYPE_QUATERNION) == true) { // quaternion * quaternion @@ -349,12 +348,12 @@ bool MiniScriptQuaternion::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptQuaternion::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptQuaternion::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_QUATERNION = static_cast(getType()); +bool MiniScriptQuaternion::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_QUATERNION = static_cast(getType()); // if (MiniScript::hasType(argumentValues, TYPE_QUATERNION) == true) { Quaternion a; @@ -378,8 +377,8 @@ bool MiniScriptQuaternion::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_QUATERNION = static_cast(getType()); +bool MiniScriptQuaternion::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_QUATERNION = static_cast(getType()); // if (MiniScript::hasType(argumentValues, TYPE_QUATERNION) == true) { Quaternion a; @@ -403,15 +402,11 @@ bool MiniScriptQuaternion::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get quaternion value from given variable @@ -45,7 +44,7 @@ class tdme::utilities::MiniScriptQuaternion final: public MiniScript::ScriptData * @param optional optional * @return success */ - static inline bool getQuaternionValue(MiniScript::ScriptVariableType TYPE_QUATERNION, const span& arguments, int idx, Quaternion& value, bool optional = false) { + static inline bool getQuaternionValue(MiniScript::VariableType TYPE_QUATERNION, const span& arguments, int idx, Quaternion& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_QUATERNION) { @@ -63,13 +62,12 @@ class tdme::utilities::MiniScriptQuaternion final: public MiniScript::ScriptData /** * MiniScript Quaternion data type */ - MiniScriptQuaternion(): MiniScript::ScriptDataType(true) { + MiniScriptQuaternion(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; }; diff --git a/src/tdme/utilities/MiniScriptTransform.cpp b/src/tdme/utilities/MiniScriptTransform.cpp index 5ec38cf68..499c2cdeb 100644 --- a/src/tdme/utilities/MiniScriptTransform.cpp +++ b/src/tdme/utilities/MiniScriptTransform.cpp @@ -27,32 +27,31 @@ using tdme::utilities::MiniScriptQuaternion; using tdme::utilities::MiniScriptVector3; using tdme::utilities::Console; -const string MiniScriptTransform::CLASS_NAME = "transform"; const string MiniScriptTransform::TYPE_NAME = "Transform"; void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { - const auto TYPE_TRANSFORM = static_cast(getType()); - const auto TYPE_MATRIX4x4 = static_cast(miniScript->getDataTypeByClassName("mat4")->getType()); - const auto TYPE_QUATERNION = static_cast(miniScript->getDataTypeByClassName("quaternion")->getType()); - const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("vec3")->getType()); + const auto TYPE_TRANSFORM = static_cast(getType()); + const auto TYPE_MATRIX4x4 = static_cast(miniScript->getDataTypeByClassName("Matrix4x4")->getType()); + const auto TYPE_QUATERNION = static_cast(miniScript->getDataTypeByClassName("Quaternion")->getType()); + const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("Vector3")->getType()); // { // - class ScriptMethodTransformAxisZ: public MiniScript::ScriptMethod { + class ScriptMethodTransformAxisZ: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformAxisZ( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod({}, TYPE_VECTOR3), + MiniScript::Method({}, TYPE_VECTOR3), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.AXIS_Z"; + return "Transform::AXIS_Z"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { auto result = Vector3(0.0f, 0.0f, 1.0f); returnValue.setType(TYPE_VECTOR3); returnValue.setValue(&result); @@ -62,21 +61,21 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformAxisY: public MiniScript::ScriptMethod { + class ScriptMethodTransformAxisY: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformAxisY( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod({}, TYPE_VECTOR3), + MiniScript::Method({}, TYPE_VECTOR3), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.AXIS_Y"; + return "Transform::AXIS_Y"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { auto result = Vector3(0.0f, 1.0f, 0.0f); returnValue.setType(TYPE_VECTOR3); returnValue.setValue(&result); @@ -86,21 +85,21 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformAxisX: public MiniScript::ScriptMethod { + class ScriptMethodTransformAxisX: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformAxisX( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod({}, TYPE_VECTOR3), + MiniScript::Method({}, TYPE_VECTOR3), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.AXIS_X"; + return "Transform::AXIS_X"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { auto result = Vector3(1.0f, 0.0f, 0.0f); returnValue.setType(TYPE_VECTOR3); returnValue.setValue(&result); @@ -110,24 +109,24 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransform: public MiniScript::ScriptMethod { + class ScriptMethodTransform: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransform( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "translation", .optional = true, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "scale", .optional = true, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "rotationZ", .optional = true, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "rotationY", .optional = true, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "rotationX", .optional = true, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "rotationZ", .optional = true, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "rotationY", .optional = true, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "rotationX", .optional = true, .reference = false, .nullable = false }, }, TYPE_TRANSFORM ), @@ -135,7 +134,7 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { const string getMethodName() override { return "transform"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform result; Vector3 vec3Value; float floatValue; @@ -181,18 +180,18 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformGetTranslation: public MiniScript::ScriptMethod { + class ScriptMethodTransformGetTranslation: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformGetTranslation( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, }, @@ -200,9 +199,9 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.getTranslation"; + return "Transform::getTranslation"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true) { const auto& result = transform.getTranslation(); @@ -219,29 +218,29 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformSetTranslation: public MiniScript::ScriptMethod { + class ScriptMethodTransformSetTranslation: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformSetTranslation( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = true, .nullable = false }, { .type = TYPE_VECTOR3, .name = "translation", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_NULL + MiniScript::VariableType::TYPE_NULL ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.setTranslation"; + return "Transform::setTranslation"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; Vector3 translation; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true && @@ -262,18 +261,18 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformGetScale: public MiniScript::ScriptMethod { + class ScriptMethodTransformGetScale: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformGetScale( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, }, @@ -281,9 +280,9 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.getScale"; + return "Transform::getScale"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true) { const auto& result = transform.getScale(); @@ -300,29 +299,29 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformSetScale: public MiniScript::ScriptMethod { + class ScriptMethodTransformSetScale: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformSetScale( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = true, .nullable = false }, { .type = TYPE_VECTOR3, .name = "scale", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_NULL + MiniScript::VariableType::TYPE_NULL ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.setScale"; + return "Transform::setScale"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; Vector3 scale; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true && @@ -342,29 +341,29 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformGetRotationAxis: public MiniScript::ScriptMethod { + class ScriptMethodTransformGetRotationAxis: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformGetRotationAxis( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_INTEGER, .name = "idx", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_INTEGER, .name = "idx", .optional = false, .reference = false, .nullable = false }, }, TYPE_VECTOR3 ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.getRotationAxis"; + return "Transform::getRotationAxis"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t idx; Transform transform; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true && @@ -388,27 +387,27 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformGetRotationAngle: public MiniScript::ScriptMethod { + class ScriptMethodTransformGetRotationAngle: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_TRANSFORM; public: ScriptMethodTransformGetRotationAngle( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM + MiniScript::VariableType TYPE_TRANSFORM ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_INTEGER, .name = "idx", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_INTEGER, .name = "idx", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM) {} const string getMethodName() override { - return "transform.getRotationAngle"; + return "Transform::getRotationAngle"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t idx; Transform transform; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true && @@ -429,28 +428,28 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformSetRotationAngle: public MiniScript::ScriptMethod { + class ScriptMethodTransformSetRotationAngle: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_TRANSFORM; public: ScriptMethodTransformSetRotationAngle( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM + MiniScript::VariableType TYPE_TRANSFORM ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = true, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_INTEGER, .name = "idx", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_INTEGER, .name = "idx", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_NULL + MiniScript::VariableType::TYPE_NULL ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM) {} const string getMethodName() override { - return "transform.setRotationAngle"; + return "Transform::setRotationAngle"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { int64_t idx; Transform transform; float angle; @@ -477,18 +476,18 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformRotate: public MiniScript::ScriptMethod { + class ScriptMethodTransformRotate: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformRotate( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false }, @@ -497,9 +496,9 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.rotate"; + return "Transform::rotate"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; Vector3 vec3; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true && @@ -519,30 +518,30 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformApplyRotation: public MiniScript::ScriptMethod { + class ScriptMethodTransformApplyRotation: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodTransformApplyRotation( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = true, .nullable = false }, { .type = TYPE_VECTOR3, .name = "axis", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "angle", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_NULL + MiniScript::VariableType::TYPE_NULL ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_VECTOR3(TYPE_VECTOR3) {} const string getMethodName() override { - return "transform.applyRotation"; + return "Transform::applyRotation"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; Vector3 axis; float angle; @@ -576,26 +575,26 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformInterpolateRotation: public MiniScript::ScriptMethod { + class ScriptMethodTransformInterpolateRotation: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; public: ScriptMethodTransformInterpolateRotation(MiniScript* miniScript): - MiniScript::ScriptMethod( + MiniScript::Method( { - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "currentAngle", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "targetAngle", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "timePassedSeconds", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "degreesPerSeconds", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "interpolatedAngle", .optional = false, .reference = true, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "currentAngle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "targetAngle", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "timePassedSeconds", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "degreesPerSeconds", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "interpolatedAngle", .optional = false, .reference = true, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_BOOLEAN + MiniScript::VariableType::TYPE_BOOLEAN ), miniScript(miniScript) {} const string getMethodName() override { - return "transform.interpolateRotation"; + return "Transform::interpolateRotation"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float currentAngle; float targetAngle; float timePassedSeconds; @@ -618,18 +617,18 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformGetTransformMatrix: public MiniScript::ScriptMethod { + class ScriptMethodTransformGetTransformMatrix: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_MATRIX4x4; public: ScriptMethodTransformGetTransformMatrix( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_MATRIX4x4 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_MATRIX4x4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, }, @@ -637,9 +636,9 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_MATRIX4x4(TYPE_MATRIX4x4) {} const string getMethodName() override { - return "transform.getTransformMatrix"; + return "Transform::getTransformMatrix"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true) { const auto& result = transform.getTransformMatrix(); @@ -656,18 +655,18 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformGetRotationsQuaternion: public MiniScript::ScriptMethod { + class ScriptMethodTransformGetRotationsQuaternion: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_QUATERNION; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_QUATERNION; public: ScriptMethodTransformGetRotationsQuaternion( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_QUATERNION + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_QUATERNION ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_TRANSFORM, .name = "transform", .optional = false, .reference = false, .nullable = false }, }, @@ -675,9 +674,9 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_QUATERNION(TYPE_QUATERNION) {} const string getMethodName() override { - return "transform.getRotationsQuaternion"; + return "Transform::getRotationsQuaternion"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Transform transform; if (MiniScriptTransform::getTransformValue(TYPE_TRANSFORM, argumentValues, 0, transform, false) == true) { const auto& result = transform.getRotationsQuaternion(); @@ -694,18 +693,18 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodTransformFromMatrix: public MiniScript::ScriptMethod { + class ScriptMethodTransformFromMatrix: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_TRANSFORM; - MiniScript::ScriptVariableType TYPE_MATRIX4x4; + MiniScript::VariableType TYPE_TRANSFORM; + MiniScript::VariableType TYPE_MATRIX4x4; public: ScriptMethodTransformFromMatrix( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_TRANSFORM, - MiniScript::ScriptVariableType TYPE_MATRIX4x4 + MiniScript::VariableType TYPE_TRANSFORM, + MiniScript::VariableType TYPE_MATRIX4x4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_MATRIX4x4, .name = "transformMatrix", .optional = false, .reference = false, .nullable = false }, }, @@ -713,9 +712,9 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { ), miniScript(miniScript), TYPE_TRANSFORM(TYPE_TRANSFORM), TYPE_MATRIX4x4(TYPE_MATRIX4x4) {} const string getMethodName() override { - return "transform.fromMatrix"; + return "Transform::fromMatrix"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Matrix4x4 transformMatrix; if (MiniScriptMatrix4x4::getMatrix4x4Value(TYPE_TRANSFORM, argumentValues, 0, transformMatrix, false) == true) { Transform result; @@ -732,7 +731,7 @@ void MiniScriptTransform::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptTransform::unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const { +void MiniScriptTransform::unsetVariableValue(MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -740,7 +739,7 @@ void MiniScriptTransform::unsetScriptVariableValue(MiniScript::ScriptVariable& v variable.setValuePtr(0ll); } -void MiniScriptTransform::setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptTransform::setVariableValue(MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Transform transformValue; @@ -756,21 +755,21 @@ void MiniScriptTransform::setScriptVariableValue(MiniScript::ScriptVariable& var variable.setValuePtr((uint64_t)(new Transform(transformValue))); } -void MiniScriptTransform::copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const { +void MiniScriptTransform::copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const { // Transform transformValue; if (from.getType() == getType() && from.getValuePtr() != 0ll) { transformValue = *static_cast((void*)from.getValuePtr()); } // - const auto TYPE_TRANSFORM = static_cast(getType()); + const auto TYPE_TRANSFORM = static_cast(getType()); to.setType(TYPE_TRANSFORM); *static_cast((void*)to.getValuePtr()) = transformValue; } -bool MiniScriptTransform::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_TRANSFORM = static_cast(getType()); - const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("vec3")->getType()); +bool MiniScriptTransform::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_TRANSFORM = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(miniScript->getDataTypeByClassName("Vector3")->getType()); // transform if (MiniScript::hasType(argumentValues, TYPE_TRANSFORM) == true) { // transform * vec3 @@ -811,27 +810,23 @@ bool MiniScriptTransform::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptTransform::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptTransform::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptTransform::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -bool MiniScriptTransform::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { +bool MiniScriptTransform::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { return false; } -const string& MiniScriptTransform::getClassName() const { - return CLASS_NAME; -} - const string& MiniScriptTransform::getTypeAsString() const { return TYPE_NAME; } -const string MiniScriptTransform::getValueAsString(const MiniScript::ScriptVariable& variable) const { +const string MiniScriptTransform::getValueAsString(const MiniScript::Variable& variable) const { // Transform transformValue; if (variable.getType() == getType() && variable.getValuePtr() != 0ll) { diff --git a/src/tdme/utilities/MiniScriptTransform.h b/src/tdme/utilities/MiniScriptTransform.h index c08c3c4e6..bc780657b 100644 --- a/src/tdme/utilities/MiniScriptTransform.h +++ b/src/tdme/utilities/MiniScriptTransform.h @@ -18,21 +18,20 @@ using tdme::engine::Transform; * MiniScript Transform data type * @author Andreas Drewke */ -class tdme::utilities::MiniScriptTransform final: public MiniScript::ScriptDataType { +class tdme::utilities::MiniScriptTransform final: public MiniScript::DataType { private: // overridden methods void registerMethods(MiniScript* miniScript) const override; - void unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const override; - void setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const override; - void copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const override; - bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get quaternion value from given variable @@ -43,7 +42,7 @@ class tdme::utilities::MiniScriptTransform final: public MiniScript::ScriptDataT * @param optional optional * @return success */ - static inline bool getTransformValue(MiniScript::ScriptVariableType TYPE_TRANSFORM, const span& arguments, int idx, Transform& value, bool optional = false) { + static inline bool getTransformValue(MiniScript::VariableType TYPE_TRANSFORM, const span& arguments, int idx, Transform& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_TRANSFORM) { @@ -61,13 +60,12 @@ class tdme::utilities::MiniScriptTransform final: public MiniScript::ScriptDataT /** * MiniScript Transform data type */ - MiniScriptTransform(): MiniScript::ScriptDataType(true) { + MiniScriptTransform(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; }; diff --git a/src/tdme/utilities/MiniScriptVector2.cpp b/src/tdme/utilities/MiniScriptVector2.cpp index c9bd52f94..c9da2b790 100644 --- a/src/tdme/utilities/MiniScriptVector2.cpp +++ b/src/tdme/utilities/MiniScriptVector2.cpp @@ -19,26 +19,25 @@ using tdme::utilities::Console; using tdme::utilities::Float; using tdme::utilities::MiniScriptVector2; -const string MiniScriptVector2::CLASS_NAME = "vec2"; const string MiniScriptVector2::TYPE_NAME = "Vector2"; void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { - const auto TYPE_VECTOR2 = static_cast(getType()); + const auto TYPE_VECTOR2 = static_cast(getType()); { // - class ScriptMethodVec2: public MiniScript::ScriptMethod { + class ScriptMethodVec2: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false } + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false } }, TYPE_VECTOR2 ), @@ -47,9 +46,9 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "vec2"; + return "Vector2"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { float xValue; float yValue; if (MiniScript::getFloatValue(argumentValues, 0, xValue, false) == true && @@ -67,29 +66,29 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec2ComputeLength: public MiniScript::ScriptMethod { + class ScriptMethodVec2ComputeLength: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2ComputeLength( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "vec2", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR2(TYPE_VECTOR2) { // } const string getMethodName() override { - return "vec2.computeLength"; + return "Vector2::computeLength"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 vec2; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, vec2, false) == true) { auto length = vec2.computeLength(); @@ -104,29 +103,29 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec2ComputeLengthSquared: public MiniScript::ScriptMethod { + class ScriptMethodVec2ComputeLengthSquared: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2ComputeLengthSquared( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "vec2", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR2(TYPE_VECTOR2) { // } const string getMethodName() override { - return "vec2.computeLengthSquared"; + return "Vector2::computeLengthSquared"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 vec2; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, vec2, false) == true) { returnValue.setValue(vec2.computeLengthSquared()); @@ -140,30 +139,30 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec2ComputeDotProduct: public MiniScript::ScriptMethod { + class ScriptMethodVec2ComputeDotProduct: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2ComputeDotProduct( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR2, .name = "b", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR2(TYPE_VECTOR2) { // } const string getMethodName() override { - return "vec2.computeDotProduct"; + return "Vector2::computeDotProduct"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 a; Vector2 b; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, a, false) == true && @@ -179,16 +178,16 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec2Normalize: public MiniScript::ScriptMethod { + class ScriptMethodVec2Normalize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2Normalize( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "vec2", .optional = false, .reference = false, .nullable = false }, }, @@ -199,9 +198,9 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "vec2.normalize"; + return "Vector2::normalize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 vec2; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, vec2, false) == true) { auto length = vec2.computeLength(); @@ -218,29 +217,29 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec2GetX: public MiniScript::ScriptMethod { + class ScriptMethodVec2GetX: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2GetX( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "vec2", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR2(TYPE_VECTOR2) { // } const string getMethodName() override { - return "vec2.getX"; + return "Vector2::getX"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 vec2; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, vec2, false) == true) { returnValue.setValue(vec2.getX()); @@ -254,29 +253,29 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec2GetY: public MiniScript::ScriptMethod { + class ScriptMethodVec2GetY: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR2; + MiniScript::VariableType TYPE_VECTOR2; public: ScriptMethodVec2GetY( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR2 + MiniScript::VariableType TYPE_VECTOR2 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR2, .name = "vec2", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR2(TYPE_VECTOR2) { // } const string getMethodName() override { - return "vec2.getY"; + return "Vector2::getY"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector2 vec2; if (MiniScriptVector2::getVector2Value(TYPE_VECTOR2, argumentValues, 0, vec2, false) == true) { returnValue.setValue(vec2.getY()); @@ -290,7 +289,7 @@ void MiniScriptVector2::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptVector2::unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const { +void MiniScriptVector2::unsetVariableValue(MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -298,7 +297,7 @@ void MiniScriptVector2::unsetScriptVariableValue(MiniScript::ScriptVariable& var variable.setValuePtr(0ll); } -void MiniScriptVector2::setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptVector2::setVariableValue(MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Vector2 vector2Value; @@ -314,20 +313,20 @@ void MiniScriptVector2::setScriptVariableValue(MiniScript::ScriptVariable& varia variable.setValuePtr((uint64_t)(new Vector2(vector2Value))); } -void MiniScriptVector2::copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const { +void MiniScriptVector2::copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const { // Vector2 vector2Value; if (from.getType() == getType() && from.getValuePtr() != 0ll) { vector2Value = *static_cast((void*)from.getValuePtr()); } // - const auto TYPE_VECTOR2 = static_cast(getType()); + const auto TYPE_VECTOR2 = static_cast(getType()); to.setType(TYPE_VECTOR2); *static_cast((void*)to.getValuePtr()) = vector2Value; } -bool MiniScriptVector2::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR2 = static_cast(getType()); +bool MiniScriptVector2::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR2 = static_cast(getType()); // if (MiniScript::hasType(argumentValues, TYPE_VECTOR2) == true) { float f; @@ -368,8 +367,8 @@ bool MiniScriptVector2::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR2 = static_cast(getType()); +bool MiniScriptVector2::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR2 = static_cast(getType()); // if (argumentValues[0].getType() == TYPE_VECTOR2) { Vector2 a; @@ -401,8 +400,8 @@ bool MiniScriptVector2::div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR2 = static_cast(getType()); +bool MiniScriptVector2::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR2 = static_cast(getType()); // if (MiniScript::hasType(argumentValues, TYPE_VECTOR2) == true) { Vector2 a; @@ -426,8 +425,8 @@ bool MiniScriptVector2::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR2 = static_cast(getType()); +bool MiniScriptVector2::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR2 = static_cast(getType()); // if (MiniScript::hasType(argumentValues, TYPE_VECTOR2) == true) { Vector2 a; @@ -451,15 +450,11 @@ bool MiniScriptVector2::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get vector2 value from given variable @@ -43,7 +42,7 @@ class tdme::utilities::MiniScriptVector2 final: public MiniScript::ScriptDataTyp * @param optional optional * @return success */ - static inline bool getVector2Value(MiniScript::ScriptVariableType TYPE_VECTOR2, const span& arguments, int idx, Vector2& value, bool optional = false) { + static inline bool getVector2Value(MiniScript::VariableType TYPE_VECTOR2, const span& arguments, int idx, Vector2& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_VECTOR2) { @@ -60,13 +59,12 @@ class tdme::utilities::MiniScriptVector2 final: public MiniScript::ScriptDataTyp /** * MiniScript Vector2 data type */ - MiniScriptVector2(): MiniScript::ScriptDataType(true) { + MiniScriptVector2(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; }; diff --git a/src/tdme/utilities/MiniScriptVector3.cpp b/src/tdme/utilities/MiniScriptVector3.cpp index f3a81b60a..c16ac1e10 100644 --- a/src/tdme/utilities/MiniScriptVector3.cpp +++ b/src/tdme/utilities/MiniScriptVector3.cpp @@ -19,27 +19,26 @@ using tdme::utilities::Console; using tdme::utilities::Float; using tdme::utilities::MiniScriptVector3; -const string MiniScriptVector3::CLASS_NAME = "vec3"; const string MiniScriptVector3::TYPE_NAME = "Vector3"; void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { - const auto TYPE_VECTOR3 = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(getType()); { // - class ScriptMethodVec3: public MiniScript::ScriptMethod { + class ScriptMethodVec3: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "z", .optional = false, .reference = false, .nullable = false } + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "z", .optional = false, .reference = false, .nullable = false } }, TYPE_VECTOR3 ), @@ -48,9 +47,9 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "vec3"; + return "Vector3"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 result; float xValue; float yValue; @@ -71,29 +70,29 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3ComputeLength: public MiniScript::ScriptMethod { + class ScriptMethodVec3ComputeLength: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3ComputeLength( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.computeLength"; + return "Vector3::computeLength"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3, false) == true) { auto length = vec3.computeLength(); @@ -108,29 +107,29 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3ComputeLengthSquared: public MiniScript::ScriptMethod { + class ScriptMethodVec3ComputeLengthSquared: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3ComputeLengthSquared( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.computeLengthSquared"; + return "Vector3::computeLengthSquared"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3, false) == true) { returnValue.setValue(vec3.computeLengthSquared()); @@ -144,30 +143,30 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3ComputeDotProduct: public MiniScript::ScriptMethod { + class ScriptMethodVec3ComputeDotProduct: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3ComputeDotProduct( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "b", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.computeDotProduct"; + return "Vector3::computeDotProduct"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 a; Vector3 b; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, a, false) == true && @@ -183,16 +182,16 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3ComputeCrossProduct: public MiniScript::ScriptMethod { + class ScriptMethodVec3ComputeCrossProduct: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3ComputeCrossProduct( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "b", .optional = false, .reference = false, .nullable = false } @@ -204,9 +203,9 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "vec3.computeCrossProduct"; + return "Vector3::computeCrossProduct"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 a; Vector3 b; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, a, false) == true && @@ -224,16 +223,16 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3Normalize: public MiniScript::ScriptMethod { + class ScriptMethodVec3Normalize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3Normalize( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false }, }, @@ -244,9 +243,9 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "vec3.normalize"; + return "Vector3::normalize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3, false) == true) { auto length = vec3.computeLength(); @@ -263,31 +262,31 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3ComputeAngle: public MiniScript::ScriptMethod { + class ScriptMethodVec3ComputeAngle: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3ComputeAngle( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "b", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR3, .name = "n", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.computeAngle"; + return "Vector3::computeAngle"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 a; Vector3 b; Vector3 n; @@ -305,29 +304,29 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3GetX: public MiniScript::ScriptMethod { + class ScriptMethodVec3GetX: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3GetX( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.getX"; + return "Vector3::getX"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3, false) == true) { returnValue.setValue(vec3.getX()); @@ -341,29 +340,29 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3GetY: public MiniScript::ScriptMethod { + class ScriptMethodVec3GetY: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3GetY( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.getY"; + return "Vector3::getY"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3, false) == true) { returnValue.setValue(vec3.getY()); @@ -377,29 +376,29 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec3GetZ: public MiniScript::ScriptMethod { + class ScriptMethodVec3GetZ: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR3; + MiniScript::VariableType TYPE_VECTOR3; public: ScriptMethodVec3GetZ( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR3 + MiniScript::VariableType TYPE_VECTOR3 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR3, .name = "vec3", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR3(TYPE_VECTOR3) { // } const string getMethodName() override { - return "vec3.getZ"; + return "Vector3::getZ"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 vec3; if (MiniScriptVector3::getVector3Value(TYPE_VECTOR3, argumentValues, 0, vec3, false) == true) { returnValue.setValue(vec3.getZ()); @@ -413,7 +412,7 @@ void MiniScriptVector3::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptVector3::unsetScriptVariableValue(MiniScript::MiniScript::ScriptVariable& variable) const { +void MiniScriptVector3::unsetVariableValue(MiniScript::MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -421,7 +420,7 @@ void MiniScriptVector3::unsetScriptVariableValue(MiniScript::MiniScript::ScriptV variable.setValuePtr(0ll); } -void MiniScriptVector3::setScriptVariableValue(MiniScript::MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptVector3::setVariableValue(MiniScript::MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Vector3 vector3Value; @@ -437,20 +436,20 @@ void MiniScriptVector3::setScriptVariableValue(MiniScript::MiniScript::ScriptVar variable.setValuePtr((uint64_t)(new Vector3(vector3Value))); } -void MiniScriptVector3::copyScriptVariable(MiniScript::MiniScript::ScriptVariable& to, const MiniScript::MiniScript::ScriptVariable& from) const { +void MiniScriptVector3::copyVariable(MiniScript::MiniScript::Variable& to, const MiniScript::MiniScript::Variable& from) const { // Vector3 vector3Value; if (from.getType() == getType() && from.getValuePtr() != 0ll) { vector3Value = *static_cast((void*)from.getValuePtr()); } // - const auto TYPE_VECTOR3 = static_cast(getType()); + const auto TYPE_VECTOR3 = static_cast(getType()); to.setType(TYPE_VECTOR3); *static_cast((void*)to.getValuePtr()) = vector3Value; } -bool MiniScriptVector3::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR3 = static_cast(getType()); +bool MiniScriptVector3::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR3 = static_cast(getType()); // vector3 if (MiniScript::hasType(argumentValues, TYPE_VECTOR3) == true) { float f; @@ -489,8 +488,8 @@ bool MiniScriptVector3::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR3 = static_cast(getType()); +bool MiniScriptVector3::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR3 = static_cast(getType()); // vector3 if (argumentValues[0].getType() == TYPE_VECTOR3) { Vector3 a; @@ -521,8 +520,8 @@ bool MiniScriptVector3::div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR3 = static_cast(getType()); +bool MiniScriptVector3::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR3 = static_cast(getType()); // vector3 if (MiniScript::hasType(argumentValues, TYPE_VECTOR3) == true) { Vector3 a; @@ -545,8 +544,8 @@ bool MiniScriptVector3::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR3 = static_cast(getType()); +bool MiniScriptVector3::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR3 = static_cast(getType()); // vector3 if (MiniScript::hasType(argumentValues, TYPE_VECTOR3) == true) { Vector3 a; @@ -569,15 +568,11 @@ bool MiniScriptVector3::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get vector3 value from given variable @@ -43,7 +42,7 @@ class tdme::utilities::MiniScriptVector3 final: public MiniScript::ScriptDataTyp * @param optional optional * @return success */ - static inline bool getVector3Value(MiniScript::ScriptVariableType TYPE_VECTOR3, const span& arguments, int idx, Vector3& value, bool optional = false) { + static inline bool getVector3Value(MiniScript::VariableType TYPE_VECTOR3, const span& arguments, int idx, Vector3& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_VECTOR3) { @@ -61,13 +60,12 @@ class tdme::utilities::MiniScriptVector3 final: public MiniScript::ScriptDataTyp /** * MiniScript Vector3 data type */ - MiniScriptVector3(): MiniScript::ScriptDataType(true) { + MiniScriptVector3(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; }; diff --git a/src/tdme/utilities/MiniScriptVector4.cpp b/src/tdme/utilities/MiniScriptVector4.cpp index ff30a3d8f..d512a5be9 100644 --- a/src/tdme/utilities/MiniScriptVector4.cpp +++ b/src/tdme/utilities/MiniScriptVector4.cpp @@ -19,28 +19,27 @@ using tdme::utilities::Console; using tdme::utilities::Float; using tdme::utilities::MiniScriptVector4; -const string MiniScriptVector4::CLASS_NAME = "vec4"; const string MiniScriptVector4::TYPE_NAME = "Vector4"; void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { - const auto TYPE_VECTOR4 = static_cast(getType()); + const auto TYPE_VECTOR4 = static_cast(getType()); { // - class ScriptMethodVec4: public MiniScript::ScriptMethod { + class ScriptMethodVec4: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "z", .optional = false, .reference = false, .nullable = false }, - { .type = MiniScript::ScriptVariableType::TYPE_FLOAT, .name = "w", .optional = false, .reference = false, .nullable = false } + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "x", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "y", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "z", .optional = false, .reference = false, .nullable = false }, + { .type = MiniScript::VariableType::TYPE_FLOAT, .name = "w", .optional = false, .reference = false, .nullable = false } }, TYPE_VECTOR4 ), @@ -50,9 +49,9 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } const string getMethodName() override { - return "vec4"; + return "Vector4"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector3 result; float xValue; float yValue; @@ -75,29 +74,29 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4ComputeLength: public MiniScript::ScriptMethod { + class ScriptMethodVec4ComputeLength: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4ComputeLength( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.computeLength"; + return "Vector4::computeLength"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { auto length = vec4.computeLength(); @@ -112,29 +111,29 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4ComputeLengthSquared: public MiniScript::ScriptMethod { + class ScriptMethodVec4ComputeLengthSquared: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4ComputeLengthSquared( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.computeLengthSquared"; + return "Vector4::computeLengthSquared"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { returnValue.setValue(vec4.computeLengthSquared()); @@ -148,30 +147,30 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4ComputeDotProduct: public MiniScript::ScriptMethod { + class ScriptMethodVec4ComputeDotProduct: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4ComputeDotProduct( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "a", .optional = false, .reference = false, .nullable = false }, { .type = TYPE_VECTOR4, .name = "b", .optional = false, .reference = false, .nullable = false } }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.computeDotProduct"; + return "Vector4::computeDotProduct"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 a; Vector4 b; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, a, false) == true && @@ -187,16 +186,16 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4Normalize: public MiniScript::ScriptMethod { + class ScriptMethodVec4Normalize: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4Normalize( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false }, }, @@ -207,9 +206,9 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { // } const string getMethodName() override { - return "vec4.normalize"; + return "Vector4::normalize"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { auto length = vec4.computeLength(); @@ -226,29 +225,29 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4GetX: public MiniScript::ScriptMethod { + class ScriptMethodVec4GetX: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4GetX( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.getX"; + return "Vector4::getX"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { returnValue.setValue(vec4.getX()); @@ -262,29 +261,29 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4GetY: public MiniScript::ScriptMethod { + class ScriptMethodVec4GetY: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4GetY( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.getY"; + return "Vector4::getY"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { returnValue.setValue(vec4.getY()); @@ -298,29 +297,29 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4GetZ: public MiniScript::ScriptMethod { + class ScriptMethodVec4GetZ: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4GetZ( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.getZ"; + return "Vector4::getZ"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { returnValue.setValue(vec4.getZ()); @@ -334,29 +333,29 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } { // - class ScriptMethodVec4GetW: public MiniScript::ScriptMethod { + class ScriptMethodVec4GetW: public MiniScript::Method { private: MiniScript* miniScript { nullptr }; - MiniScript::ScriptVariableType TYPE_VECTOR4; + MiniScript::VariableType TYPE_VECTOR4; public: ScriptMethodVec4GetW( MiniScript* miniScript, - MiniScript::ScriptVariableType TYPE_VECTOR4 + MiniScript::VariableType TYPE_VECTOR4 ): - MiniScript::ScriptMethod( + MiniScript::Method( { { .type = TYPE_VECTOR4, .name = "vec4", .optional = false, .reference = false, .nullable = false }, }, - MiniScript::ScriptVariableType::TYPE_FLOAT + MiniScript::VariableType::TYPE_FLOAT ), miniScript(miniScript), TYPE_VECTOR4(TYPE_VECTOR4) { // } const string getMethodName() override { - return "vec4.getW"; + return "Vector4::getW"; } - void executeMethod(span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) override { + void executeMethod(span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { Vector4 vec4; if (MiniScriptVector4::getVector4Value(TYPE_VECTOR4, argumentValues, 0, vec4, false) == true) { returnValue.setValue(vec4.getW()); @@ -370,7 +369,7 @@ void MiniScriptVector4::registerMethods(MiniScript* miniScript) const { } } -void MiniScriptVector4::unsetScriptVariableValue(MiniScript::ScriptVariable& variable) const { +void MiniScriptVector4::unsetVariableValue(MiniScript::Variable& variable) const { if (variable.getType() != getType()) return; if (variable.getValuePtr() == 0ll) return; // @@ -378,7 +377,7 @@ void MiniScriptVector4::unsetScriptVariableValue(MiniScript::ScriptVariable& var variable.setValuePtr(0ll); } -void MiniScriptVector4::setScriptVariableValue(MiniScript::ScriptVariable& variable, const void* value) const { +void MiniScriptVector4::setVariableValue(MiniScript::Variable& variable, const void* value) const { if (variable.getType() != getType()) return; // Vector4 vector4Value; @@ -394,19 +393,19 @@ void MiniScriptVector4::setScriptVariableValue(MiniScript::ScriptVariable& varia variable.setValuePtr((uint64_t)(new Vector4(vector4Value))); } -void MiniScriptVector4::copyScriptVariable(MiniScript::ScriptVariable& to, const MiniScript::ScriptVariable& from) const { +void MiniScriptVector4::copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const { // Vector4 vector4Value; if (from.getType() == getType() && from.getValuePtr() != 0ll) { vector4Value = *static_cast((void*)from.getValuePtr()); } // - to.setType(static_cast(getType())); + to.setType(static_cast(getType())); *static_cast((void*)to.getValuePtr()) = vector4Value; } -bool MiniScriptVector4::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR4 = static_cast(getType()); +bool MiniScriptVector4::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR4 = static_cast(getType()); // if (MiniScript::hasType(argumentValues, TYPE_VECTOR4) == true) { float f; @@ -447,8 +446,8 @@ bool MiniScriptVector4::mul(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR4 = static_cast(getType()); +bool MiniScriptVector4::div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR4 = static_cast(getType()); // if (argumentValues[0].getType() == TYPE_VECTOR4) { Vector4 a; @@ -481,8 +480,8 @@ bool MiniScriptVector4::div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR4 = static_cast(getType()); +bool MiniScriptVector4::add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR4 = static_cast(getType()); // // vector4 if (MiniScript::hasType(argumentValues, TYPE_VECTOR4) == true) { @@ -507,8 +506,8 @@ bool MiniScriptVector4::add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const { - const auto TYPE_VECTOR4 = static_cast(getType()); +bool MiniScriptVector4::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const { + const auto TYPE_VECTOR4 = static_cast(getType()); // // vector4 if (MiniScript::hasType(argumentValues, TYPE_VECTOR4) == true) { @@ -533,15 +532,11 @@ bool MiniScriptVector4::sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; - bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::ScriptVariable& returnValue, const MiniScript::ScriptStatement& statement) const override; + void unsetVariableValue(MiniScript::Variable& variable) const override; + void setVariableValue(MiniScript::Variable& variable, const void* value) const override; + void copyVariable(MiniScript::Variable& to, const MiniScript::Variable& from) const override; + bool mul(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool div(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool add(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; + bool sub(MiniScript* miniScript, const span& argumentValues, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; public: - static const string CLASS_NAME; - static const string TYPE_NAME; + STATIC_DLL_IMPEXT static const string TYPE_NAME; /** * Get vector4 value from given variable @@ -43,7 +42,7 @@ class tdme::utilities::MiniScriptVector4 final: public MiniScript::ScriptDataTyp * @param optional optional * @return success */ - static inline bool getVector4Value(MiniScript::ScriptVariableType TYPE_VECTOR4, const span& arguments, int idx, Vector4& value, bool optional = false) { + static inline bool getVector4Value(MiniScript::VariableType TYPE_VECTOR4, const span& arguments, int idx, Vector4& value, bool optional = false) { if (idx >= arguments.size()) return optional; const auto& argument = arguments[idx]; if (argument.getType() == TYPE_VECTOR4) { @@ -61,13 +60,12 @@ class tdme::utilities::MiniScriptVector4 final: public MiniScript::ScriptDataTyp /** * MiniScript Vector4 data type */ - MiniScriptVector4(): MiniScript::ScriptDataType(true) { + MiniScriptVector4(): MiniScript::DataType(true) { // } // overridden methods - const string& getClassName() const override; const string& getTypeAsString() const override; - const string getValueAsString(const MiniScript::ScriptVariable& variable) const override; + const string getValueAsString(const MiniScript::Variable& variable) const override; };