diff options
author | gumi <git@gumi.ca> | 2020-07-06 18:07:56 +0000 |
---|---|---|
committer | gumi <git@gumi.ca> | 2020-07-06 18:16:20 +0000 |
commit | d0477515f30f0b2612f5de10f4531026dab2798e (patch) | |
tree | aafba58ba367520a136ca779a7a7e31dc2312cf7 /src/map/script-call.cpp | |
parent | 3949942605f6cfc32a5a14eb31285d06bcdcade6 (diff) | |
download | tmwa-d0477515f30f0b2612f5de10f4531026dab2798e.tar.gz tmwa-d0477515f30f0b2612f5de10f4531026dab2798e.tar.bz2 tmwa-d0477515f30f0b2612f5de10f4531026dab2798e.tar.xz tmwa-d0477515f30f0b2612f5de10f4531026dab2798e.zip |
ensure that returning builtins always return, else abort
Diffstat (limited to 'src/map/script-call.cpp')
-rw-r--r-- | src/map/script-call.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/map/script-call.cpp b/src/map/script-call.cpp index 5541043..4de94d7 100644 --- a/src/map/script-call.cpp +++ b/src/map/script-call.cpp @@ -706,6 +706,28 @@ void run_func(ScriptState *st) } builtin_functions[func].func(st); + if (builtin_functions[func].ret != '\0') { + // this builtin is expected to return a value + script_data &back = st->stack->stack_datav.back(); + + if (builtin_functions[func].ret == 'i' && !back.is<ScriptDataInt>()) { + PRINTF("script-call:run_func: expected %s to push an integer but none was found. aborting script execution.\n"_fmt, builtin_functions[func].name); + st->state = ScriptEndState::END; + } else if (builtin_functions[func].ret == 's' && !back.is<ScriptDataStr>()) { + PRINTF("script-call:run_func: expected %s to push a string but none was found. aborting script execution.\n"_fmt, builtin_functions[func].name); + st->state = ScriptEndState::END; + } else if (builtin_functions[func].ret == 'v' && !back.is<ScriptDataStr>() && !back.is<ScriptDataInt>() && !back.is<ScriptDataParam>() && !back.is<ScriptDataVariable>()) { + PRINTF("script-call:run_func: expected %s to push a value but none was found. aborting script execution.\n"_fmt, builtin_functions[func].name); + st->state = ScriptEndState::END; + } else if (builtin_functions[func].ret == 'r' && !back.is<ScriptDataVariable>()) { + PRINTF("script-call:run_func: expected %s to push a variable reference but none was found. aborting script execution.\n"_fmt, builtin_functions[func].name); + st->state = ScriptEndState::END; + } else if (builtin_functions[func].ret == 'l' && !back.is<ScriptDataPos>()) { + PRINTF("script-call:run_func: expected %s to push a label pos but none was found. aborting script execution.\n"_fmt, builtin_functions[func].name); + st->state = ScriptEndState::END; + } + } + pop_stack(st->stack, start_sp, end_sp); if (st->state == ScriptEndState::RETFUNC) |