fix: Fix script return value handling
This commit is contained in:
parent
fc71d63f7c
commit
90fd4d1d9f
2 changed files with 15 additions and 8 deletions
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "SDL2/SDL_timer.h"
|
||||
|
||||
#include "../../core/log.h"
|
||||
|
||||
#include "../object/creature.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -85,9 +87,10 @@ Variable RoutineManager::getFirstPC(const vector<Variable> &args, ExecutionConte
|
|||
|
||||
Variable RoutineManager::getObjectByTag(const vector<Variable> &args, ExecutionContext &ctx) {
|
||||
assert(!args.empty() && args[0].type == VariableType::String);
|
||||
shared_ptr<Object> object(_callbacks->getObjectByTag(args[0].strValue));
|
||||
|
||||
Variable result(VariableType::Object);
|
||||
result.objectId = _callbacks->getObjectByTag(args[0].strValue)->id();
|
||||
result.objectId = object ? object->id() : kObjectInvalid;
|
||||
|
||||
return move(result);
|
||||
}
|
||||
|
@ -102,6 +105,11 @@ Variable RoutineManager::getLevelByClass(const vector<Variable> &args, Execution
|
|||
|
||||
int objectId = args.size() < 2 ? kObjectSelf : args[1].objectId;
|
||||
shared_ptr<Object> object(getObjectById(objectId, ctx));
|
||||
if (!object) {
|
||||
warn("Object not found by id: " + to_string(objectId));
|
||||
return 0;
|
||||
}
|
||||
|
||||
Creature &creature = static_cast<Creature &>(*object);
|
||||
|
||||
return Variable(creature.getClassLevel(clazz));
|
||||
|
|
|
@ -83,7 +83,6 @@ ScriptExecution::ScriptExecution(const shared_ptr<ScriptProgram> &program, const
|
|||
|
||||
int ScriptExecution::run() {
|
||||
uint32_t insOff = kStartInstructionOffset;
|
||||
_stack.push_back(Variable(0));
|
||||
|
||||
if (_context.savedState) {
|
||||
vector<Variable> globals(_context.savedState->globals);
|
||||
|
@ -111,9 +110,9 @@ int ScriptExecution::run() {
|
|||
insOff = _nextInstruction;
|
||||
}
|
||||
|
||||
assert(_stack.front().type == VariableType::Int);
|
||||
if (_stack.empty() || _stack.back().type != VariableType::Int) return -1;
|
||||
|
||||
return _stack.front().intValue;
|
||||
return _stack.back().intValue;
|
||||
}
|
||||
|
||||
void ScriptExecution::executeCopyDownSP(const Instruction &ins) {
|
||||
|
@ -226,9 +225,9 @@ void ScriptExecution::executeCallRoutine(const Instruction &ins) {
|
|||
case VariableType::Void:
|
||||
break;
|
||||
case VariableType::Vector:
|
||||
_stack.push_back(retValue.vecValue.x);
|
||||
_stack.push_back(retValue.vecValue.y);
|
||||
_stack.push_back(retValue.vecValue.z);
|
||||
_stack.push_back(retValue.vecValue.y);
|
||||
_stack.push_back(retValue.vecValue.x);
|
||||
break;
|
||||
default:
|
||||
_stack.push_back(retValue);
|
||||
|
@ -237,9 +236,9 @@ void ScriptExecution::executeCallRoutine(const Instruction &ins) {
|
|||
}
|
||||
|
||||
Variable ScriptExecution::getVectorFromStack() {
|
||||
float x = getFloatFromStack().floatValue;
|
||||
float y = getFloatFromStack().floatValue;
|
||||
float z = getFloatFromStack().floatValue;
|
||||
float y = getFloatFromStack().floatValue;
|
||||
float x = getFloatFromStack().floatValue;
|
||||
|
||||
return glm::vec3(x, y, z);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue