diff --git a/README-MiniScript.md b/README-MiniScript.md index 6ff4b2b04..34a6b517a 100644 --- a/README-MiniScript.md +++ b/README-MiniScript.md @@ -1292,8 +1292,12 @@ end | bool($bool: Boolean): Boolean | | Break out of current forCondition or forTime loop | | break(): Null | +| Begins a case block within a switch block, which will be executed if the case value has matched | +| case($value: Mixed): Null | | Continue to next iteration of forCondition or forTime loop | | continue(): Null | +| Begins a default block within a switch block, which will be executed if no case value has matched| +| default(): Null | | Divide | | div($a: Mixed, $b: Mixed): Mixed | | Else | @@ -1342,6 +1346,8 @@ end | return([$value: Mixed]): Null | | Subtract | | sub($a: Mixed, $b: Mixed): Mixed | +| Begins switch block to match a given value to case values or a default | +| switch($value: Mixed): Null | ## 7.2. Application methods diff --git a/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp b/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp index 2a771bb60..91e1d4787 100644 --- a/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp +++ b/ext/miniscript/src/miniscript/miniscript/BaseMethods.cpp @@ -68,7 +68,7 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { if (miniScript->getScriptState().blockStack.empty() == true) { - _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": break without forXXX"); + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": break without forCondition/forTime"); miniScript->startErrorScript(); } else { auto& blockStack = miniScript->getScriptState().blockStack; @@ -81,7 +81,7 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } if (endType.type == MiniScript::ScriptState::BLOCKTYPE_NONE) { - _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": break without forXXX"); + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": break without forCondition/forTime"); } else if (endType.continueStatement != nullptr) { miniScript->gotoStatement(*endType.breakStatement); @@ -105,7 +105,7 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { if (miniScript->getScriptState().blockStack.empty() == true) { - _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": continue without forXXX"); + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": continue without forCondition, forTime"); miniScript->startErrorScript(); } else { auto& blockStack = miniScript->getScriptState().blockStack; @@ -118,7 +118,7 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } } if (endType == nullptr) { - _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": continue without forXXX"); + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": continue without forCondition, forTime"); } else if (endType->continueStatement != nullptr) { miniScript->gotoStatement(*endType->continueStatement); @@ -142,25 +142,21 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { } void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { if (miniScript->getScriptState().blockStack.empty() == true) { - _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": end without block/forXXX/if"); + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": end without if/elseif/else/switch/case/default/forCondition/forTime/end"); miniScript->startErrorScript(); } else { auto& blockStack = miniScript->getScriptState().blockStack; - auto endType = blockStack[blockStack.size() - 1]; - blockStack.erase(blockStack.begin() + blockStack.size() - 1); - switch(endType.type) { + auto& block = blockStack[blockStack.size() - 1]; + switch(block.type) { case MiniScript::ScriptState::BLOCKTYPE_BLOCK: if (miniScript->isFunctionRunning() == true && miniScript->scriptStateStack.size() == 2) { miniScript->stopRunning(); } break; - case MiniScript::ScriptState::BLOCKTYPE_FOR: - // no op - break; - case MiniScript::ScriptState::BLOCKTYPE_IF: - miniScript->getScriptState().conditionStack.pop(); + default: break; } + blockStack.erase(blockStack.begin() + blockStack.size() - 1); if (statement.gotoStatementIdx != MiniScript::STATEMENTIDX_NONE) { miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); miniScript->gotoStatementGoto(statement); @@ -209,9 +205,11 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { miniScript->gotoStatementGoto(statement); } else { scriptState.blockStack.emplace_back( - MiniScript::ScriptState::BLOCKTYPE_FOR, + MiniScript::ScriptState::BLOCKTYPE_FORTIME, + false, &miniScript->getScripts()[scriptState.scriptIdx].statements[statement.gotoStatementIdx - 1], - &miniScript->getScripts()[scriptState.scriptIdx].statements[statement.gotoStatementIdx] + &miniScript->getScripts()[scriptState.scriptIdx].statements[statement.gotoStatementIdx], + MiniScript::Variable() ); } } @@ -250,8 +248,10 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { auto& scriptState = miniScript->getScriptState(); scriptState.blockStack.emplace_back( MiniScript::ScriptState::BLOCKTYPE_FOR, + false, &miniScript->getScripts()[scriptState.scriptIdx].statements[statement.gotoStatementIdx - 1], - &miniScript->getScripts()[scriptState.scriptIdx].statements[statement.gotoStatementIdx] + &miniScript->getScripts()[scriptState.scriptIdx].statements[statement.gotoStatementIdx], + MiniScript::Variable() ); } } @@ -282,8 +282,7 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { miniScript->startErrorScript(); } else { auto& scriptState = miniScript->getScriptState(); - scriptState.blockStack.emplace_back(MiniScript::ScriptState::BLOCKTYPE_IF, nullptr, nullptr); - scriptState.conditionStack.push(booleanValue); + scriptState.blockStack.emplace_back(MiniScript::ScriptState::BLOCKTYPE_IF, booleanValue, nullptr, nullptr, MiniScript::Variable()); if (booleanValue == false) { miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); miniScript->gotoStatementGoto(statement); @@ -314,20 +313,19 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { 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("MethodElseIfCondition::executeMethod(): elseif without if"); - miniScript->startErrorScript(); } else { // - auto conditionStackElement = miniScript->getScriptState().conditionStack.top(); - if (conditionStackElement == false) { - miniScript->getScriptState().conditionStack.pop(); - miniScript->getScriptState().conditionStack.push(booleanValue); - } - if (conditionStackElement == true || booleanValue == false) { + auto& scriptState = miniScript->getScriptState(); + auto& blockStack = scriptState.blockStack[scriptState.blockStack.size() - 1]; + if (blockStack.type != MiniScript::ScriptState::BlockType::BLOCKTYPE_IF) { + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": elseif without if"); + miniScript->startErrorScript(); + } else + if (blockStack.match == true || booleanValue == false) { miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); miniScript->gotoStatementGoto(statement); + } else { + blockStack.match = booleanValue; } } } @@ -345,19 +343,116 @@ void BaseMethods::registerMethods(MiniScript* miniScript) { return "else"; } void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { - if (miniScript->getScriptState().conditionStack.empty() == true) { - _Console::println("MethodElse::executeMethod(): else without if"); + auto& scriptState = miniScript->getScriptState(); + auto& blockStack = scriptState.blockStack[scriptState.blockStack.size() - 1]; + if (blockStack.type != MiniScript::ScriptState::BlockType::BLOCKTYPE_IF) { + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": else without if"); + miniScript->startErrorScript(); + } else + if (blockStack.match == true) { + miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); + miniScript->gotoStatementGoto(statement); + } + } + }; + miniScript->registerMethod(new MethodElse(miniScript)); + } + // switch + { + // + class MethodSwitch: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodSwitch(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = false, .reference = false, .nullable = false } + } + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "switch"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + bool booleanValue; + if (arguments.size() != 1) { + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": argument mismatch: expected arguments: " + miniScript->getArgumentInformation(getMethodName())); miniScript->startErrorScript(); } else { - auto conditionStackElement = miniScript->getScriptState().conditionStack.top(); - if (conditionStackElement == true) { - miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); - miniScript->gotoStatementGoto(statement); + auto& scriptState = miniScript->getScriptState(); + scriptState.blockStack.emplace_back(MiniScript::ScriptState::BLOCKTYPE_SWITCH, booleanValue, nullptr, nullptr, arguments[0]); + } + } + }; + miniScript->registerMethod(new MethodSwitch(miniScript)); + } + { + // + class MethodCase: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodCase(MiniScript* miniScript): + MiniScript::Method( + { + { .type = MiniScript::TYPE_PSEUDO_MIXED, .name = "value", .optional = false, .reference = false, .nullable = false } + } + ), + miniScript(miniScript) {} + const string getMethodName() override { + return "case"; + } + 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 { + // + auto& scriptState = miniScript->getScriptState(); + auto& blockStack = scriptState.blockStack[scriptState.blockStack.size() - 1]; + if (blockStack.type != MiniScript::ScriptState::BlockType::BLOCKTYPE_SWITCH) { + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": case without switch"); + miniScript->startErrorScript(); + } else { + auto match = arguments[0].getValueAsString() == blockStack.switchVariable.getValueAsString(); + if (blockStack.match == true || match == false) { + miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); + miniScript->gotoStatementGoto(statement); + } else { + blockStack.match = match; + scriptState.blockStack.emplace_back(MiniScript::ScriptState::BLOCKTYPE_CASE, false, nullptr, nullptr, MiniScript::Variable()); + } } } } }; - miniScript->registerMethod(new MethodElse(miniScript)); + miniScript->registerMethod(new MethodCase(miniScript)); + } + { + // + class MethodDefault: public MiniScript::Method { + private: + MiniScript* miniScript { nullptr }; + public: + MethodDefault(MiniScript* miniScript): MiniScript::Method(), miniScript(miniScript) {} + const string getMethodName() override { + return "default"; + } + void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { + auto& scriptState = miniScript->getScriptState(); + auto& blockStack = scriptState.blockStack[scriptState.blockStack.size() - 1]; + if (blockStack.type != MiniScript::ScriptState::BlockType::BLOCKTYPE_SWITCH) { + _Console::println(getMethodName() + "(): " + miniScript->getStatementInformation(statement) + ": default without switch"); + miniScript->startErrorScript(); + } else + if (blockStack.match == true) { + miniScript->setScriptStateState(MiniScript::STATEMACHINESTATE_NEXT_STATEMENT); + miniScript->gotoStatementGoto(statement); + } + } + }; + miniScript->registerMethod(new MethodDefault(miniScript)); } // equality { diff --git a/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.cpp b/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.cpp index f524db8fe..cc5b1cfa8 100644 --- a/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.cpp +++ b/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.cpp @@ -43,10 +43,11 @@ void HTTPDownloadClientClass::registerMethods(MiniScript* miniScript) const { return "HTTPDownloadClient"; } void executeMethod(span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) override { - auto& scriptContext = *static_cast(miniScript->getDataTypeScriptContext(MiniScript::TYPE_HTTPDOWNLOADCLIENT)); + auto& scriptContext = *static_cast(miniScript->getDataTypeScriptContext(MiniScript::TYPE_HTTPDOWNLOADCLIENT)); // auto httpDownloadClient = make_shared<_HTTPDownloadClient>(); - scriptContext.instances.push_back(httpDownloadClient); + scriptContext.getInstances().push_back(httpDownloadClient); + scriptContext.setRequiresGarbageCollection(); // returnValue.setType(MiniScript::TYPE_HTTPDOWNLOADCLIENT); returnValue.setValue(&httpDownloadClient); @@ -715,22 +716,26 @@ const string HTTPDownloadClientClass::getValueAsString(const MiniScript::Variabl return "HTTPDownloadClientClass(url: " + httpDownloadClient->getURL() + ", file: " + httpDownloadClient->getFile() + ")"; } -void* HTTPDownloadClientClass::createScriptContext() const { - return new ScriptContext(); +MiniScript::DataType::ScriptContext* HTTPDownloadClientClass::createScriptContext() const { + return new HTTPDownloadClientClassScriptContext(); } -void HTTPDownloadClientClass::deleteScriptContext(void* context) const { - delete static_cast(context); +void HTTPDownloadClientClass::deleteScriptContext(MiniScript::DataType::ScriptContext* context) const { + delete static_cast(context); } -void HTTPDownloadClientClass::garbageCollection(void* context) const { - auto& scriptContext = *static_cast(context); - for (auto i = 0; i < scriptContext.instances.size(); i++) { - auto& instance = scriptContext.instances[i]; +void HTTPDownloadClientClass::garbageCollection(MiniScript::DataType::ScriptContext* context) const { + auto& scriptContext = *static_cast(context); + auto& instances = scriptContext.getInstances(); + for (auto i = 0; i < instances.size(); i++) { + auto& instance = instances[i]; if (instance.use_count() == 1 && instance->isFinished() == true) { instance->join(); - scriptContext.instances.erase(scriptContext.instances.begin() + i); + instances.erase(instances.begin() + i); i--; } } + if (instances.empty() == true) { + scriptContext.unsetRequiresGarbageCollection(); + } } diff --git a/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.h b/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.h index e6c2c4ec5..0a8e8ab46 100644 --- a/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.h +++ b/ext/miniscript/src/miniscript/miniscript/HTTPDownloadClientClass.h @@ -36,16 +36,29 @@ class miniscript::miniscript::HTTPDownloadClientClass final: public MiniScript:: bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + DataType::ScriptContext* createScriptContext() const override; + void deleteScriptContext(DataType::ScriptContext* context) const override; + void garbageCollection(DataType::ScriptContext* context) const override; public: /** * Script context */ - struct ScriptContext { - vector> instances; + class HTTPDownloadClientClassScriptContext final: public ScriptContext { + public: + /** + * Constructor + */ + HTTPDownloadClientClassScriptContext() {} + + /** + * @return instances + */ + inline vector>& getInstances() { + return instances; + } + private: + vector> instances; }; // forbid class copy @@ -76,9 +89,9 @@ class miniscript::miniscript::HTTPDownloadClientClass final: public MiniScript:: } /** - * MiniScript Vector2 data type + * MiniScript HTTP download client class */ - HTTPDownloadClientClass(): MiniScript::DataType(false) { + HTTPDownloadClientClass(): MiniScript::DataType(false, true) { // } diff --git a/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp b/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp index eb4c452c1..fd94610cd 100644 --- a/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp +++ b/ext/miniscript/src/miniscript/miniscript/MiniScript.cpp @@ -164,7 +164,16 @@ const vector MiniScript::getTranspilationUnits() { } MiniScript::MiniScript() { - for (auto datatype: dataTypes) dataTypeScriptContexts.push_back(datatype->createScriptContext()); + for (auto dataType: dataTypes) { + if (dataType->isRequiringGarbageCollection() == false) continue; + // create script context + auto scriptContext = dataType->createScriptContext(); + scriptContext->setMiniScript(this); + scriptContext->setIndex(garbageCollectionDataTypes.size()); + // + garbageCollectionDataTypes.emplace_back(dataType,scriptContext); + garbageCollectionScriptContextsByDataType[dataType->getType()] = scriptContext; + } setNative(false); pushScriptState(); } @@ -174,8 +183,7 @@ MiniScript::~MiniScript() { for (const auto& [stateMachineStateId, stateMachineState]: this->stateMachineStates) delete stateMachineState; while (scriptStateStack.empty() == false) popScriptState(); garbageCollection(); - for (auto i = 0; i < dataTypes.size(); i++) dataTypes[i]->deleteScriptContext(dataTypeScriptContexts[i]); - dataTypeScriptContexts.clear(); + for (auto& garbageCollectionDataType: garbageCollectionDataTypes) garbageCollectionDataType.dataType->deleteScriptContext(garbageCollectionDataType.context); } void MiniScript::registerStateMachineState(StateMachineState* state) { @@ -1309,7 +1317,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { auto lineIdx = LINE_FIRST; auto currentLineIdx = 0; auto statementIdx = STATEMENTIDX_FIRST; - enum GotoStatementType { GOTOSTATEMENTTYPE_FOR, GOTOSTATEMENTTYPE_IF, GOTOSTATEMENTTYPE_ELSE, GOTOSTATEMENTTYPE_ELSEIF }; + enum GotoStatementType { GOTOSTATEMENTTYPE_FOR, GOTOSTATEMENTTYPE_IF, GOTOSTATEMENTTYPE_ELSE, GOTOSTATEMENTTYPE_ELSEIF, GOTOSTATEMENTTYPE_SWITCH, GOTOSTATEMENTTYPE_CASE, GOTOSTATEMENTTYPE_DEFAULT }; struct GotoStatementStruct { GotoStatementType type; int statementIdx; @@ -1465,14 +1473,14 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { auto rightBracketIdx = statement.find(')'); if (leftBracketIdx != string::npos || leftBracketIdx != string::npos) { if (leftBracketIdx == string::npos) { - _Console::println("MiniScript::parseScriptInternal(): " + scriptFileName + ": @" + to_string(currentLineIdx) + ": 'function:': unbalanced bracket count"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": 'function:': unbalanced bracket count"); // parseErrors.push_back(to_string(currentLineIdx) + ": 'function:': unbalanced bracket count"); // scriptValid = false; } else if (rightBracketIdx == string::npos) { - _Console::println("MiniScript::parseScriptInternal(): " + scriptFileName + ": @" + to_string(currentLineIdx) + ": 'function:': unbalanced bracket count"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": 'function:': unbalanced bracket count"); // parseErrors.push_back(to_string(currentLineIdx) + ": 'function:': unbalanced bracket count"); // @@ -1494,7 +1502,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { reference ); } else { - _Console::println("MiniScript::parseScriptInternal(): " + scriptFileName + ": @" + to_string(currentLineIdx) + ": 'function:': invalid argument name: '" + argumentNameTrimmed + "'"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": 'function:': invalid argument name: '" + argumentNameTrimmed + "'"); // parseErrors.push_back(to_string(currentLineIdx) + ": 'function:': invalid argument name: '" + argumentNameTrimmed + "'"); // @@ -1538,9 +1546,9 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { arguments ); } else { - _Console::println("MiniScript::parseScriptInternal(): " + scriptFileName + ": @" + to_string(currentLineIdx) + ": expecting 'on:', 'on-enabled:', 'on-function:' script condition"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": expecting 'on:', 'on-enabled:', 'function:', 'callable:'"); // - parseErrors.push_back(to_string(currentLineIdx) + ": expecting 'on:', 'on-enabled:', 'on-function:' script condition"); + parseErrors.push_back(to_string(currentLineIdx) + ": expecting 'on:', 'on-enabled:', 'function:', 'callable:'"); // scriptValid = false; } @@ -1550,9 +1558,9 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { _StringTools::startsWith(statementCode, "on-enabled:") == true || _StringTools::startsWith(statementCode, "callable:") == true ) { - _Console::println("MiniScript::parseScriptInternal(): " + scriptFileName + ": @" + to_string(currentLineIdx) + ": unbalanced forXXX/if/elseif/else/end"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": unbalanced if/elseif/else/switch/case/default/forCondition/forTime/end"); // - parseErrors.push_back(to_string(currentLineIdx) + ": unbalanced forXXX/if/elseif/else/end"); + parseErrors.push_back(to_string(currentLineIdx) + ": unbalanced if/elseif/else/switch/case/default/forCondition/forTime/end"); // scriptValid = false; } else @@ -1585,6 +1593,23 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { scripts[scripts.size() - 1].statements.emplace_back(currentLineIdx, statementIdx, statementCode, statementCode, STATEMENTIDX_NONE); } break; + case GOTOSTATEMENTTYPE_SWITCH: + { + scripts[scripts.size() - 1].statements.emplace_back(currentLineIdx, statementIdx, statementCode, statementCode, STATEMENTIDX_NONE); + } + break; + case GOTOSTATEMENTTYPE_CASE: + { + scripts[scripts.size() - 1].statements[gotoStatementStackElement.statementIdx].gotoStatementIdx = scripts[scripts.size() - 1].statements.size() + 1; + scripts[scripts.size() - 1].statements.emplace_back(currentLineIdx, statementIdx, statementCode, statementCode, STATEMENTIDX_NONE); + } + break; + case GOTOSTATEMENTTYPE_DEFAULT: + { + scripts[scripts.size() - 1].statements[gotoStatementStackElement.statementIdx].gotoStatementIdx = scripts[scripts.size() - 1].statements.size() + 1; + scripts[scripts.size() - 1].statements.emplace_back(currentLineIdx, statementIdx, statementCode, statementCode, STATEMENTIDX_NONE); + } + break; } } else{ scripts[scripts.size() - 1].statements.emplace_back(currentLineIdx, statementIdx, statementCode, statementCode, STATEMENTIDX_NONE); @@ -1609,7 +1634,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } break; default: - _Console::println("MiniScript::parseScriptInternal(): '" + scriptFileName + ": @" + to_string(currentLineIdx) + ": else without if/elseif"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": else without if/elseif"); // parseErrors.push_back(to_string(currentLineIdx) + ": else without if/elseif"); // @@ -1623,7 +1648,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } ); } else { - _Console::println("MiniScript::parseScriptInternal(): '" + scriptFileName + ": @" + to_string(currentLineIdx) + ": else without if"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": else without if"); // parseErrors.push_back(to_string(currentLineIdx) + ": else without if"); // @@ -1656,7 +1681,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } break; default: - _Console::println("MiniScript::parseScriptInternal(): '" + scriptFileName + ": @" + to_string(currentLineIdx) + ": elseif without if"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": elseif without if"); scriptValid = false; break; } @@ -1667,7 +1692,7 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } ); } else { - _Console::println("MiniScript::parseScriptInternal(): '" + scriptFileName + ": @" + to_string(currentLineIdx) + ": elseif without if"); + _Console::println(scriptFileName + ": @" + to_string(currentLineIdx) + ": elseif without if"); // parseErrors.push_back(to_string(currentLineIdx) + ": elseif without if"); // @@ -1698,6 +1723,30 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { .statementIdx = statementIdx } ); + } else + if (_StringTools::regexMatch(executableStatement, "^switch[\\s]*\\(.*\\)$") == true) { + gotoStatementStack.push( + { + .type = GOTOSTATEMENTTYPE_SWITCH, + .statementIdx = STATEMENTIDX_NONE + } + ); + } else + if (_StringTools::regexMatch(executableStatement, "^case[\\s]*\\(.*\\)$") == true) { + gotoStatementStack.push( + { + .type = GOTOSTATEMENTTYPE_CASE, + .statementIdx = statementIdx + } + ); + } + if (_StringTools::regexMatch(executableStatement, "^default[\\s]*$") == true) { + gotoStatementStack.push( + { + .type = GOTOSTATEMENTTYPE_DEFAULT, + .statementIdx = statementIdx + } + ); } scripts[scripts.size() - 1].statements.emplace_back(currentLineIdx, statementIdx, statementCode, executableStatement, STATEMENTIDX_NONE); } @@ -1705,11 +1754,11 @@ bool MiniScript::parseScriptInternal(const string& scriptCode) { } } - // check for unbalanced forXXX/if/elseif/else/end + // check for unbalanced if/elseif/else/switch/case/default/forCondition/forTime/end if (scriptValid == true && gotoStatementStack.empty() == false) { - _Console::println("MiniScript::parseScriptInternal(): '" + scriptFileName + ": unbalanced forXXX/if/elseif/else/end"); + _Console::println(scriptFileName + ": unbalanced if/elseif/else/switch/case/default/forCondition/forTime/end"); // - parseErrors.push_back("Unbalanced forXXX/if/elseif/else/end"); + parseErrors.push_back("Unbalanced if/elseif/else/switch/case/default/forCondition/forTime/end"); // scriptValid = false; // @@ -4124,5 +4173,9 @@ void MiniScript::setConstantInternal(Variable& variable) { } void MiniScript::garbageCollection() { - for (auto i = 0; i < dataTypes.size(); i++) dataTypes[i]->garbageCollection(dataTypeScriptContexts[i]); + auto garbageCollectionDataTypesIndicesCopy = garbageCollectionDataTypesIndices; + for (auto index: garbageCollectionDataTypesIndicesCopy) { + auto& garbageCollectionDataType = garbageCollectionDataTypes[index]; + garbageCollectionDataType.dataType->garbageCollection(garbageCollectionDataType.context); + } } diff --git a/ext/miniscript/src/miniscript/miniscript/MiniScript.h b/ext/miniscript/src/miniscript/miniscript/MiniScript.h index f1b15edc9..211ceeb8e 100644 --- a/ext/miniscript/src/miniscript/miniscript/MiniScript.h +++ b/ext/miniscript/src/miniscript/miniscript/MiniScript.h @@ -169,8 +169,61 @@ class miniscript::miniscript::MiniScript { friend class MathMethods; protected: + /** + * Script context + */ + class ScriptContext { + friend class MiniScript; + public: + /** + * Constructor + */ + ScriptContext() {} + + /** + * Destructor + */ + virtual ~ScriptContext() {} + + /** + * Set MiniScript instance + * @param miniScript MiniScript instance + */ + void setMiniScript(MiniScript* miniScript) { + this->miniScript = miniScript; + } + + /** + * Set garbage collection type index + * @param index garbage collection type index + */ + void setIndex(int index) { + this->index = index; + } + + /** + * Set requires garbage collection + */ + inline void setRequiresGarbageCollection() { + miniScript->garbageCollectionDataTypesIndices.insert(index); + } + + /** + * Unset requires garbage collection + */ + inline void unsetRequiresGarbageCollection() { + miniScript->garbageCollectionDataTypesIndices.erase(index); + } + + private: + int index { -1 }; + MiniScript* miniScript { nullptr }; + }; + // bool mathDataType { false }; + bool requiresGarbageCollection { false }; + // MiniScript::VariableType type { TYPE_NULL }; /** @@ -188,6 +241,13 @@ class miniscript::miniscript::MiniScript { return mathDataType; } + /** + * @return is requiring garbage collection + */ + inline bool isRequiringGarbageCollection() { + return requiresGarbageCollection; + } + /** * Register constants * @param miniScript MiniScript instance @@ -270,19 +330,19 @@ class miniscript::miniscript::MiniScript { * Create script context * @return script context */ - virtual void* createScriptContext() const = 0; + virtual ScriptContext* createScriptContext() const = 0; /** * Delete script context * @param context script context */ - virtual void deleteScriptContext(void* context) const = 0; + virtual void deleteScriptContext(ScriptContext* context) const = 0; /** * Issue garbage collection * @param context script context */ - virtual void garbageCollection(void* context) const = 0; + virtual void garbageCollection(ScriptContext* context) const = 0; public: // forbid class copy @@ -291,8 +351,9 @@ class miniscript::miniscript::MiniScript { /** * Data type * @param mathDataType is math data type and provides math methods + * @param requiresGarbageCollection requires garbage collection */ - DataType(bool mathDataType): mathDataType(mathDataType) { + DataType(bool mathDataType, bool requiresGarbageCollection): mathDataType(mathDataType), requiresGarbageCollection(requiresGarbageCollection) { // } @@ -2555,25 +2616,33 @@ class miniscript::miniscript::MiniScript { static constexpr int64_t TIME_NONE { -1LL }; struct ScriptState { - enum BlockType { BLOCKTYPE_NONE, BLOCKTYPE_BLOCK, BLOCKTYPE_FOR, BLOCKTYPE_IF }; + enum BlockType { BLOCKTYPE_NONE, BLOCKTYPE_BLOCK, BLOCKTYPE_FOR, BLOCKTYPE_FORTIME, BLOCKTYPE_IF, BLOCKTYPE_SWITCH, BLOCKTYPE_CASE }; struct Block { Block(): type(BLOCKTYPE_NONE), + match(false), continueStatement(nullptr), - breakStatement(nullptr) + breakStatement(nullptr), + switchVariable(Variable()) {} Block( BlockType type, + bool match, const Statement* continueStatement, - const Statement* breakStatement + const Statement* breakStatement, + const Variable& switchVariable ): type(type), + match(match), continueStatement(continueStatement), - breakStatement(breakStatement) + breakStatement(breakStatement), + switchVariable(switchVariable) {} BlockType type; + bool match; const Statement* continueStatement; const Statement* breakStatement; + Variable switchVariable; }; enum ConditionType { SCRIPT, @@ -2591,7 +2660,6 @@ class miniscript::miniscript::MiniScript { string id; unordered_map variables; unordered_map forTimeStarted; - stack conditionStack; vector blockStack; // applies for functions only Variable returnValue; @@ -2690,9 +2758,8 @@ class miniscript::miniscript::MiniScript { auto& scriptState = getScriptState(); if (isFunctionRunning() == false) enabledNamedConditions.clear(); scriptState.forTimeStarted.clear(); - while (scriptState.conditionStack.empty() == false) scriptState.conditionStack.pop(); scriptState.blockStack.clear(); - if (scriptIdx != SCRIPTIDX_NONE) scriptState.blockStack.emplace_back(ScriptState::BLOCKTYPE_BLOCK, nullptr, nullptr); + if (scriptIdx != SCRIPTIDX_NONE) scriptState.blockStack.emplace_back(ScriptState::BLOCKTYPE_BLOCK, false, nullptr, nullptr, Variable()); scriptState.id.clear(); scriptState.scriptIdx = scriptIdx; scriptState.statementIdx = STATEMENTIDX_FIRST; @@ -2866,7 +2933,26 @@ class miniscript::miniscript::MiniScript { // bool scriptValid { false }; - vector dataTypeScriptContexts; + /** + * Garbage collection data type + */ + struct GarbageCollectionDataType { + GarbageCollectionDataType( + DataType* dataType, + DataType::ScriptContext* context): + dataType(dataType), + context(context) { + // + } + // + DataType* dataType; + DataType::ScriptContext* context; + }; + + // + vector garbageCollectionDataTypes; + unordered_map garbageCollectionScriptContextsByDataType; + unordered_set garbageCollectionDataTypesIndices; /** * Parse script code into this MiniScript instance @@ -3231,14 +3317,12 @@ class miniscript::miniscript::MiniScript { * @param type data type * @return data type script context */ - inline void* getDataTypeScriptContext(VariableType type) { - // custom data types - auto dataTypeIdx = static_cast(type) - TYPE_PSEUDO_DATATYPES; - if (dataTypeIdx < 0 || dataTypeIdx >= MiniScript::dataTypes.size()) { - _Console::println("MiniScript::getDataTypeScriptContext(): unknown data type with id " + to_string(dataTypeIdx)); - return nullptr; + inline DataType::ScriptContext* getDataTypeScriptContext(VariableType type) { + auto garbageCollectionScriptContextsByDataTypeIt = garbageCollectionScriptContextsByDataType.find(type); + if (garbageCollectionScriptContextsByDataTypeIt != garbageCollectionScriptContextsByDataType.end()) { + return garbageCollectionScriptContextsByDataTypeIt->second; } - return MiniScript::dataTypeScriptContexts[dataTypeIdx]; + return nullptr; } /** diff --git a/ext/miniscript/src/miniscript/miniscript/Version.cpp b/ext/miniscript/src/miniscript/miniscript/Version.cpp index fde840782..15f663c16 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.19 PRE-BETA"; + return "0.9.21 PRE-BETA"; } string Version::getCopyright() { diff --git a/resources/engine/code-completion/tscript-methods.properties b/resources/engine/code-completion/tscript-methods.properties index 8bb1756a6..fa64b79c6 100644 --- a/resources/engine/code-completion/tscript-methods.properties +++ b/resources/engine/code-completion/tscript-methods.properties @@ -152,6 +152,7 @@ miniscript.basemethod.bitwiseOr=Bitwise or miniscript.basemethod.bitwiseXor=Bitwise xor miniscript.basemethod.bool=Create bool miniscript.basemethod.break=Break out of current forCondition or forTime loop +miniscript.basemethod.case=Begins a case block within a switch block, which will be executed if the case value has matched miniscript.basemethod.continue=Continue to next iteration of forCondition or forTime loop miniscript.basemethod.ByteArray=Create byte array miniscript.basemethod.ByteArray::clear=Clear byte array @@ -191,6 +192,7 @@ miniscript.basemethod.context.script.getScriptIds=Returns all script ids of its miniscript.basemethod.context.script.call=Call a script callable function miniscript.basemethod.context.script.loadScript=Load a script into context miniscript.basemethod.context.script.removeScript=Remove a script from context +miniscript.basemethod.default=Begins a default block within a switch block, which will be executed if no case value has matched miniscript.basemethod.div=Divide miniscript.basemethod.else=Else miniscript.basemethod.elseif=Else if @@ -294,6 +296,7 @@ miniscript.basemethod.script.evaluate=Evaluate a script statement miniscript.basemethod.script.stop=Stop script miniscript.basemethod.script.wait=Wait for given milliseconds miniscript.basemethod.script.waitForCondition=Wait for condition to happen +miniscript.basemethod.switch=Begins switch block to match a given value to case values or a default miniscript.basemethod.Set=Create set miniscript.basemethod.Set::has=Has key in set miniscript.basemethod.Set::getKeys=Get set keys diff --git a/src/tdme/miniscript/MiniScriptMatrix3x3.cpp b/src/tdme/miniscript/MiniScriptMatrix3x3.cpp index 7a72a4a3f..6c5dde790 100644 --- a/src/tdme/miniscript/MiniScriptMatrix3x3.cpp +++ b/src/tdme/miniscript/MiniScriptMatrix3x3.cpp @@ -357,12 +357,12 @@ const string MiniScriptMatrix3x3::getValueAsString(const MiniScript::Variable& v } -void* MiniScriptMatrix3x3::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptMatrix3x3::createScriptContext() const { return nullptr; } -void MiniScriptMatrix3x3::deleteScriptContext(void* context) const { +void MiniScriptMatrix3x3::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptMatrix3x3::garbageCollection(void* context) const { +void MiniScriptMatrix3x3::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptMatrix3x3.h b/src/tdme/miniscript/MiniScriptMatrix3x3.h index 12e67735b..ed5f11839 100644 --- a/src/tdme/miniscript/MiniScriptMatrix3x3.h +++ b/src/tdme/miniscript/MiniScriptMatrix3x3.h @@ -31,9 +31,9 @@ class tdme::miniscript::MiniScriptMatrix3x3 final: public MiniScript::DataType { bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_MATRIX3x3; @@ -71,9 +71,8 @@ class tdme::miniscript::MiniScriptMatrix3x3 final: public MiniScript::DataType { /** * MiniScript Matrix3x3 data type - * @param miniScript mini script instance */ - MiniScriptMatrix3x3(): MiniScript::DataType(true) { + MiniScriptMatrix3x3(): MiniScript::DataType(true, false) { // } diff --git a/src/tdme/miniscript/MiniScriptMatrix4x4.cpp b/src/tdme/miniscript/MiniScriptMatrix4x4.cpp index d459c55f1..0ba8c9211 100644 --- a/src/tdme/miniscript/MiniScriptMatrix4x4.cpp +++ b/src/tdme/miniscript/MiniScriptMatrix4x4.cpp @@ -397,12 +397,12 @@ const string MiniScriptMatrix4x4::getValueAsString(const MiniScript::Variable& v to_string(matrix4x4[15]) + ")"; } -void* MiniScriptMatrix4x4::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptMatrix4x4::createScriptContext() const { return nullptr; } -void MiniScriptMatrix4x4::deleteScriptContext(void* context) const { +void MiniScriptMatrix4x4::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptMatrix4x4::garbageCollection(void* context) const { +void MiniScriptMatrix4x4::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptMatrix4x4.h b/src/tdme/miniscript/MiniScriptMatrix4x4.h index 15b6becc1..d2c080b4c 100644 --- a/src/tdme/miniscript/MiniScriptMatrix4x4.h +++ b/src/tdme/miniscript/MiniScriptMatrix4x4.h @@ -31,9 +31,9 @@ class tdme::miniscript::MiniScriptMatrix4x4 final: public MiniScript::DataType { bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_MATRIX4x4; @@ -72,7 +72,7 @@ class tdme::miniscript::MiniScriptMatrix4x4 final: public MiniScript::DataType { /** * MiniScript Matrix4x4 data type */ - MiniScriptMatrix4x4(): MiniScript::DataType(true) { + MiniScriptMatrix4x4(): MiniScript::DataType(true, false) { // } diff --git a/src/tdme/miniscript/MiniScriptQuaternion.cpp b/src/tdme/miniscript/MiniScriptQuaternion.cpp index 33fcb5e2f..ec431a7db 100644 --- a/src/tdme/miniscript/MiniScriptQuaternion.cpp +++ b/src/tdme/miniscript/MiniScriptQuaternion.cpp @@ -372,12 +372,12 @@ const string MiniScriptQuaternion::getValueAsString(const MiniScript::Variable& } -void* MiniScriptQuaternion::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptQuaternion::createScriptContext() const { return nullptr; } -void MiniScriptQuaternion::deleteScriptContext(void* context) const { +void MiniScriptQuaternion::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptQuaternion::garbageCollection(void* context) const { +void MiniScriptQuaternion::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptQuaternion.h b/src/tdme/miniscript/MiniScriptQuaternion.h index a9b695735..577c4a740 100644 --- a/src/tdme/miniscript/MiniScriptQuaternion.h +++ b/src/tdme/miniscript/MiniScriptQuaternion.h @@ -33,9 +33,9 @@ class tdme::miniscript::MiniScriptQuaternion final: public MiniScript::DataType bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_MATRIX4x4; @@ -75,7 +75,7 @@ class tdme::miniscript::MiniScriptQuaternion final: public MiniScript::DataType /** * MiniScript Quaternion data type */ - MiniScriptQuaternion(): MiniScript::DataType(true) { + MiniScriptQuaternion(): MiniScript::DataType(true, false) { // } diff --git a/src/tdme/miniscript/MiniScriptTransform.cpp b/src/tdme/miniscript/MiniScriptTransform.cpp index 40bda3197..0fc71304c 100644 --- a/src/tdme/miniscript/MiniScriptTransform.cpp +++ b/src/tdme/miniscript/MiniScriptTransform.cpp @@ -756,12 +756,12 @@ const string MiniScriptTransform::getValueAsString(const MiniScript::Variable& v return result; } -void* MiniScriptTransform::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptTransform::createScriptContext() const { return nullptr; } -void MiniScriptTransform::deleteScriptContext(void* context) const { +void MiniScriptTransform::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptTransform::garbageCollection(void* context) const { +void MiniScriptTransform::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptTransform.h b/src/tdme/miniscript/MiniScriptTransform.h index ae9662b9a..ac777e113 100644 --- a/src/tdme/miniscript/MiniScriptTransform.h +++ b/src/tdme/miniscript/MiniScriptTransform.h @@ -31,9 +31,9 @@ class tdme::miniscript::MiniScriptTransform final: public MiniScript::DataType { bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_MATRIX4x4; @@ -73,7 +73,7 @@ class tdme::miniscript::MiniScriptTransform final: public MiniScript::DataType { /** * MiniScript Transform data type */ - MiniScriptTransform(): MiniScript::DataType(true) { + MiniScriptTransform(): MiniScript::DataType(true, false) { // } diff --git a/src/tdme/miniscript/MiniScriptVector2.cpp b/src/tdme/miniscript/MiniScriptVector2.cpp index 9276a6341..696a937ba 100644 --- a/src/tdme/miniscript/MiniScriptVector2.cpp +++ b/src/tdme/miniscript/MiniScriptVector2.cpp @@ -414,12 +414,12 @@ const string MiniScriptVector2::getValueAsString(const MiniScript::Variable& var to_string(vector2.getY()) + ")"; } -void* MiniScriptVector2::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptVector2::createScriptContext() const { return nullptr; } -void MiniScriptVector2::deleteScriptContext(void* context) const { +void MiniScriptVector2::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptVector2::garbageCollection(void* context) const { +void MiniScriptVector2::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptVector2.h b/src/tdme/miniscript/MiniScriptVector2.h index 81a3a28a4..cfb41a450 100644 --- a/src/tdme/miniscript/MiniScriptVector2.h +++ b/src/tdme/miniscript/MiniScriptVector2.h @@ -31,9 +31,9 @@ class tdme::miniscript::MiniScriptVector2 final: public MiniScript::DataType { bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_VECTOR2; @@ -70,7 +70,7 @@ class tdme::miniscript::MiniScriptVector2 final: public MiniScript::DataType { /** * MiniScript Vector2 data type */ - MiniScriptVector2(): MiniScript::DataType(true) { + MiniScriptVector2(): MiniScript::DataType(true, false) { // } diff --git a/src/tdme/miniscript/MiniScriptVector3.cpp b/src/tdme/miniscript/MiniScriptVector3.cpp index 25ec90a85..8fb4c81a3 100644 --- a/src/tdme/miniscript/MiniScriptVector3.cpp +++ b/src/tdme/miniscript/MiniScriptVector3.cpp @@ -519,12 +519,12 @@ const string MiniScriptVector3::getValueAsString(const MiniScript::MiniScript::V } -void* MiniScriptVector3::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptVector3::createScriptContext() const { return nullptr; } -void MiniScriptVector3::deleteScriptContext(void* context) const { +void MiniScriptVector3::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptVector3::garbageCollection(void* context) const { +void MiniScriptVector3::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptVector3.h b/src/tdme/miniscript/MiniScriptVector3.h index 17422e3ef..cbbc1f9a8 100644 --- a/src/tdme/miniscript/MiniScriptVector3.h +++ b/src/tdme/miniscript/MiniScriptVector3.h @@ -31,9 +31,9 @@ class tdme::miniscript::MiniScriptVector3 final: public MiniScript::DataType { bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_VECTOR3; @@ -71,7 +71,7 @@ class tdme::miniscript::MiniScriptVector3 final: public MiniScript::DataType { /** * MiniScript Vector3 data type */ - MiniScriptVector3(): MiniScript::DataType(true) { + MiniScriptVector3(): MiniScript::DataType(true, false) { // } diff --git a/src/tdme/miniscript/MiniScriptVector4.cpp b/src/tdme/miniscript/MiniScriptVector4.cpp index 350f930bd..893eaa214 100644 --- a/src/tdme/miniscript/MiniScriptVector4.cpp +++ b/src/tdme/miniscript/MiniScriptVector4.cpp @@ -488,12 +488,12 @@ const string MiniScriptVector4::getValueAsString(const MiniScript::Variable& var } -void* MiniScriptVector4::createScriptContext() const { +MiniScript::DataType::ScriptContext* MiniScriptVector4::createScriptContext() const { return nullptr; } -void MiniScriptVector4::deleteScriptContext(void* context) const { +void MiniScriptVector4::deleteScriptContext(ScriptContext* context) const { } -void MiniScriptVector4::garbageCollection(void* context) const { +void MiniScriptVector4::garbageCollection(ScriptContext* context) const { } diff --git a/src/tdme/miniscript/MiniScriptVector4.h b/src/tdme/miniscript/MiniScriptVector4.h index 604c8eb7c..63750e9ef 100644 --- a/src/tdme/miniscript/MiniScriptVector4.h +++ b/src/tdme/miniscript/MiniScriptVector4.h @@ -31,9 +31,9 @@ class tdme::miniscript::MiniScriptVector4 final: public MiniScript::DataType { bool div(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool add(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; bool sub(MiniScript* miniScript, const span& arguments, MiniScript::Variable& returnValue, const MiniScript::Statement& statement) const override; - void* createScriptContext() const override; - void deleteScriptContext(void* context) const override; - void garbageCollection(void* context) const override; + ScriptContext* createScriptContext() const override; + void deleteScriptContext(ScriptContext* context) const override; + void garbageCollection(ScriptContext* context) const override; // STATIC_DLL_IMPEXT static MiniScript::VariableType TYPE_VECTOR4; @@ -71,7 +71,7 @@ class tdme::miniscript::MiniScriptVector4 final: public MiniScript::DataType { /** * MiniScript Vector4 data type */ - MiniScriptVector4(): MiniScript::DataType(true) { + MiniScriptVector4(): MiniScript::DataType(true, false) { // }