Work in progress patch. There are still some issues, lots of mess and unfinished bits. Enclosed ptpcam will only work with this code.
Basic idea
set_usb_result() in lua sets the value to be returned. Accepts string, number boolean or nil. nil is the same as not setting a result. There is currently no way to tell the difference. Setting more than once is fine, it just replaces the previous value. Tables are not allowed, but a lua function to serialize simple tables can be made standard somewhere. I already planned this for my lua based client.
Result is only available to ptp once the script has finished.
Result is saved for every script run, whether you use lua or luar. Old result is thrown away next time a script is run. This means a big result could be stored and never freed if you don't run any more scripts. I plan to add script execution status and error message to the result, so it will make sense even if script doesn't set result.
If you want the result from the previous lua (not luar) command, you can use getr [timeout]
Currently, if there is an error, the 'press a key to close' appears, and the result isn't available until this is done. I think we don't need this for ptp scripts, especially if they return flag and error message.
If you start another script while a script is running, the old scripts is killed and any result is thrown away. But I'm not sure this cleans up properly in other areas, needs to be looked into.
Currently getr and luar just polls script-status every 250ms. I may add additional bits for error or result available, but I'm not sure they are needed yet.
If there is no result (already received or not set) GetResult returns TYPE_NOTHING. This is a change of meaning, might indicate it in a different way later.
If anyone has feedback on how it should work, now is your time to speak.