Actium Posted Wednesday at 05:36 PM Posted Wednesday at 05:36 PM (edited) The net.dostring_in() function has the following function signature to run code in the Lua environment state (type hints after the colon): net.dostring_in(state: string, code: string) -> return_value: string, success: boolean Example with Valid State (for Comparison) Run the following code via the Scripts/Hooks folder, i.e., from the "gui" state: return {net.dostring_in("mission", "return 42")} Successful return value: { "42", true } Example with Invalid State Try to run the same code inside a non-existing state: return {net.dostring_in("invalid", "return 42")} Up until DCS 2.9.17.12034, using an invalid Lua state name returned a proper error message: { "Invalid state name", false } Since DCS 2.9.18.12722, net.dostring_in() now returns only nil, resulting in an empty table: {} I've said it before: A simple unit test could have prevented releasing DCS with such basic bugs. Edited Wednesday at 06:23 PM by Actium
Draken35 Posted Wednesday at 06:28 PM Posted Wednesday at 06:28 PM On 2.9.18.12722 , behavior was changed to return values as per the change logs and forums post... This was then reversed on hotfix 2.9.18.12899. Returning nil seems like a consistent behavior to me, but that particular tidbit was not spelled out in the change log or in the forum post about this (granted, I did not read all the thread) 1
Actium Posted Wednesday at 07:23 PM Author Posted Wednesday at 07:23 PM It was indeed supposed to pass-thru multiple return values. However, that pass-thru never worked. With the changes being reverted, I'd expect that broken pass-thru to also be reverted, returning to the old behavior. 50 minutes ago, Draken35 said: Returning nil seems like a consistent behavior to me Not quite. Lua's native pcall() demonstrates how to do it properly. It returns the success boolean first and then either an error message or all return values. That enables discriminating between both cases. Unfortunately, net.dostring_in() uses the objectively wrong ordering. Simply returning nil will not allow to differentiate between a net.dostring_in() error and the executed code rightfully returning nil. For lack of an error message in case of a net.dostring_in() error condition, debugging is also complicated.
Recommended Posts