The reason is that at the moment the task handling the PTP command will wait until the script is done to send back the return value and I'm unsure of the consequences of waiting for a long time. Perhaps it's completely harmless. An alternative is to make it asynchronous, having the camera send an event on completion or having a command to poll for a result.
I played around with this a little bit and ended up restoring your "luar" (prefix script with result and retrieve lua return value) and naming mine "luaw" (do not modify script, retrieve result, w as in for "wait" for result) and leaving the "lua" as is (do not modify script, do not retrieve result).
Waiting for a result too long does seem to be a problem, at least for me
luaw sleep(4500);return(22+1) -- works
luaw sleep(5000);return(22+1) -- fails
I also believe I fixed the connection retry thing and added another retry loop to device finding meaning it now should not immediately fail if a command is started during power-on (tested via cli interface) and firmware reboot (not tested).
I also wrote a simple timelapse script (simple as in no good for serious timelapse work but fine for an example) in bash to show how to transfer the latest photo off the camera to the PC and delete it from the camera. It uses disk.lua from mattkime's lua libs package so if you don't have those installed (on the camera), you'll need to do something like this first:
ptpcam --chdk="upload disk.lua A/CHDK/LUALIB/disk.lua"
The new versions are available for download in ptpcam-climod-2.zip at
http://drop.io/a570_chdk_ptp.