Repository navigation
SCM function handling by GOSUB return. - #96
Conversation
| { | ||
| if (thread->SP == 0 && thread->IsCustom() && !IsLegacyScript(thread)) // CLEO5 - allow use of GOSUB `return` to exit cleo calls too | ||
| { | ||
| return opcode_0AB2(thread); // try CLEO's function return |
There was a problem hiding this comment.
0051 isn't var args opcode. please use CleoReturnGeneric directly
There was a problem hiding this comment.
return GetInstance().OpcodeSystem.CleoReturnGeneric(0x0051, thread, false);
There was a problem hiding this comment.
is thread->IsCustom() check necessary? we might be able to use it in main.scm too
There was a problem hiding this comment.
how about showing a custom message when return is found outside of any gosub or scm function?
if sp ==0 && !IsLegacyScript(thread) {
get scm func
if func == nullptr {
return message ("return is used outside of subroutine (gosub or scm call), suspended")
}
call returnGeneric
}
call 0051
There was a problem hiding this comment.
return true/false does not return any arguments, it's condition flag. return true/false is the same as cleo_return_with true/false
that's the point. even if you don't care about condition result you are now forced to provide one in order to use return in a function now. I used something like return true everywhere in cleo testing library.
now, with this change you should be able to use just return and get consistent results with return true/false .
There was a problem hiding this comment.
| function | function: result | gosub | |
|---|---|---|---|
| return | OK | ERROR | OK |
| return true/false | OK | ERROR | OK |
| return true/false values | ERROR | OK | ERROR |
There was a problem hiding this comment.
so a function with no output and gosub will be treated in the same way. you can exit both using return or return true/false, depending on whether or not you care about condition flag.
return true/false values syntax can only be used in functions returning something.
There was a problem hiding this comment.
0AB2: cleo_return should always exit from SCM function, even we are currently in gosub.
2002: return_with should check if we are in a gosub and exit from gosub. 0 returned values expected.
2003 return_fail should check if we are in a gosub and exit from gosub, setting condition flag to false
There was a problem hiding this comment.
Updated.
What to do with main scm is still debatable. In theory legacy mode can be enabled in cleo.ini, but then the setting will be shared between main game and all mod packs. scm3 scm4 filetype extension would make sense.
be46b62 to
f30bedc
Compare
|
appeared to be working. tests and sanny updated to support single return in functions. |
No description provided.