--- linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp 2019/08/01 09:56:27 3550 +++ linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp 2019/08/01 10:22:56 3551 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2017 Christian Schoenebeck + * Copyright (c) 2014-2019 Christian Schoenebeck * * http://www.linuxsampler.org * @@ -92,8 +92,32 @@ /////////////////////////////////////////////////////////////////////////// // built-in script function: exit() +int CoreVMFunction_exit::maxAllowedArgs() const { + return (vm->isExitResultEnabled()) ? 1 : 0; +} + +bool CoreVMFunction_exit::acceptsArgType(int iArg, ExprType_t type) const { + if (!vm->isExitResultEnabled()) return false; + return type == INT_EXPR || type == STRING_EXPR; +} + VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) { this->result.flags = STMT_ABORT_SIGNALLED; + if (vm->isExitResultEnabled() && args->argsCount()) { + ExecContext* ctx = dynamic_cast(vm->currentVMExecContext()); + switch (args->arg(0)->exprType()) { + case INT_EXPR: + ctx->exitRes.intLiteral.value = args->arg(0)->asInt()->evalInt(); + ctx->exitRes.value = &ctx->exitRes.intLiteral; + break; + case STRING_EXPR: + ctx->exitRes.stringLiteral.value = args->arg(0)->asString()->evalStr(); + ctx->exitRes.value = &ctx->exitRes.stringLiteral; + break; + default: + ; // noop - just to shut up the compiler + } + } return &result; }