fs2open.github.com icon indicating copy to clipboard operation
fs2open.github.com copied to clipboard

FR: full sexp 'boolean' return from lua

Open EatThePath opened this issue 2 years ago • 5 comments

I have on occasion wanted to have a lua sexp return the values like SEXP_KNOWN_FALSE to mesh a little more closely with the event evaluation system. An enum for this or new userdata type seems like the cleanest way to do this.

EatThePath avatar Jan 27 '24 19:01 EatThePath

After a little more poking at the idea that prompted this, it would likely need to include a new value $Return Type: in the sexp table, that would let the operators using it be used in the root position of an event.

EatThePath avatar Feb 06 '24 19:02 EatThePath

Sounds about right. The return type could use an enum class with values corresponding to the SEXP_ boolean values, and then these could be converted in the LuaSEXP::getSexpReturnValue function.

Goober5000 avatar Feb 07 '24 20:02 Goober5000

lua-save-file-exists would benefit greatly from this: currently, using it in the obvious way, i.e. ( when ( lua-save-file-exists "whatever" ) ( do-something-related-to-save-files ) ), causes disk IO every frame if the file doesn't exist.

naomimyselfandi avatar Mar 23 '24 16:03 naomimyselfandi

I recently added a caching mechanism to alleviate this problem: https://github.com/FSO-Scripters/fso-scripts/pull/59

But this is not to take away from your comment, which is an excellent use case for this FR.

Goober5000 avatar Mar 23 '24 20:03 Goober5000

Turns out that this can be done in a way that's fully compatible with the current API. PR shortly.

Goober5000 avatar Mar 24 '24 03:03 Goober5000

Implemented in #6063

Goober5000 avatar Apr 14 '24 01:04 Goober5000