Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: thespindoctor on April 25, 2018, 05:23:01 PM

Title: Lua file operations
Post by: thespindoctor on April 25, 2018, 05:23:01 PM
I cannot get Lua to write to an empty file.  I create the file nicely and if I put a character on the first line then the write command works fine
If I create a file which is empty, then the commands do not work.

Anyone have this problem?

THanks
Title: Re: Lua file operations
Post by: joeaverage on April 25, 2018, 06:23:29 PM
Hi,
I think you have to open the file, then flush() and then close() before the file will stick even though
its empty.

Craig
Title: Re: Lua file operations
Post by: thespindoctor on April 25, 2018, 07:45:48 PM
That is whatI am doing but the strange thing is it works only when there is at least one character on rhe first line.

I have tried all kinds of manipulations.  Everything works as expected with a file that is not empty.

Nothing works on an empty file...
Title: Re: Lua file operations
Post by: thespindoctor on April 25, 2018, 07:47:50 PM
Could be an issue since i first open the file to read it then check to find a zero length.  Then close it and reopen it for writing
Title: Re: Lua file operations
Post by: thespindoctor on April 25, 2018, 09:17:04 PM
Working now.  I just simplified the variables and it is working.  I had been saving the file name from a variable into an easier variable. Leaving it in the first variable worked.
Title: Re: Lua file operations
Post by: joeaverage on April 26, 2018, 12:37:26 AM
Hi,
maybe a file has to have one character...an EOF character?

Craig
Title: Re: Lua file operations
Post by: thespindoctor on April 26, 2018, 09:37:27 AM
No it works fine now.  I had another script running that created a global variable for path and file but then I stored that file name in a local variable.  This caused the issue.  When I use the global variable, it works fine!
Title: Re: Lua file operations
Post by: Cbyrdtopper on April 26, 2018, 10:42:10 AM
What exactly are you trying to do here?  Write to a file?
You've struck my curiosity haha.
Title: Re: Lua file operations
Post by: thespindoctor on April 26, 2018, 11:06:41 AM
Just a simple one line write to a file!