As the title says... Chat on...

User avatar
By gerardwr
#3710 Nothing in the API doc, and never seen any workaround yet.

Tried if open has a returning value that you could check: It doesn't :cry:
Code: Select all>  =file.open("init.txt","r")
lua: stdin:1: cannot open file
> file.open("init.txt","r")
lua: stdin:1: cannot open file
>


Only method I see right now is to write a nasty procedure that executes the "file.open" command in a string, catch the return value, and check if this value.

Is a lua challenge, some background here:
http://www.lua.org/pil/8.4.html
http://www.tutorialspoint.com/lua/lua_e ... ndling.htm

If you go on this slippery path, report back if you have any luck, I'm interested.
User avatar
By ThomasW
#3711
zeroday wrote:file.open("init.lua","r") or file.open("init.lua")
if init.lua not exist, a error shows.
in next release this api will return a nil if the file not exists.


Meanwhile, this should work also:
Code: Select allif file.list()[filename] then ....

(found here: http://dracoblue.net/dev/fast-inarray-o ... mented-lua)

Edit: hey, even better - this returns either nil or the filesize :)

Thomas