RetroBASIC

Retrogamecoding(.org) => EGSL => Topic started by: gaulthunter on February 09, 2013, 12:57:53 AM

Title: Writing to files
Post by: gaulthunter on February 09, 2013, 12:57:53 AM
Hello, I've been using EGSL (I like to call it eggshell) for a while, and noticed when porting one of my lua programs, that it seems to lack (Or I haven't noticed) a system to write or read from files... How can this be achieved?
Title: Re: Writing to files
Post by: kolyamatic on February 09, 2013, 06:59:29 AM
Firstly, I might say that "eggshell" sounds like a rather funny name for EGSL.

Other than that, Eggshell does not lack a way of doing such things. Though, the resource upon which one could achieve the knowledge of how to doing this, is not quite finished yet.
Anyway, this link (which redirects to the, as mentioned before, unfinished documentation) should help you at least a little:
http://egsl.retrogamecoding.org/documentation/egsldocumentation.html
I hope that this forum supports link-posting.
If not so, just search for the documentation or ask someone round here.

Additionally, I may try some of the commands in the next few days, as I literally rush through the unexplained commands by (attempting to) using them in programmes.


-- Kolyamatic
-- EDIT: some minor grammatical issues
Title: Re: Writing to files
Post by: Tomaaz on February 09, 2013, 02:39:25 PM
EGSL can do everything Lua can, so you can simply use Lua functions for working with files. You can also use additional EGSL functions - see File Management section in EGSL documentation (http://egsl.retrogamecoding.org/documentation/egsldocumentation.html).
Title: Re: Writing to files
Post by: cvirus on February 09, 2013, 06:54:28 PM
Simple example to write into a file using LUA.

Code: [Select]
local file = io.open("text.txt", "w")
file:write("writing to text.txt file with EGSL and LUA")
file:flush()
file:close()

The "w" means you can write and you can use others such "a" for appending.

for further reading http://www.lua.org/pil/21.1.html (http://www.lua.org/pil/21.1.html)

Title: Re: Writing to files
Post by: Tomaaz on February 09, 2013, 07:05:20 PM
And this is how it looks with additional EGSL function:

Code: [Select]
a = open("test2.txt", "w")
fprint(a, "Writing to text.txt file with EGSL and LUA")
close(a)
Title: Re: Writing to files
Post by: lelldorin on February 09, 2013, 10:03:03 PM
And this is how it looks with additional EGSL function:

Code: [Select]
a = open("test2.txt", "w")
fprint(a, "Writing to text.txt file with EGSL and LUA")
close(a)

Nice, and with variables?

its for the templates odf my EGSL IDE

Can you explaint reading from file too :-)
Title: Re: Writing to files
Post by: Tomaaz on February 10, 2013, 12:12:58 PM
Here is example that creates test.txt file and writes numbers from 1 to 10 to it. Every time you run it again, it add next ten numbers to the file.

Code: [Select]
if (fileexists("test.txt") == false) then
plik = open("test.txt", "w")
for x = 1, 10 do
fprint(plik, x)
end
close(plik)
end

plik = open("test.txt", "r")
x = 0
while (eof(plik) == false) do
x = x + 1
finput(plik)
end
close(plik)

plik = open("test.txt", "a")
for y = x + 1, x + 10 do
fprint(plik, y)
end
close(plik)
Title: Re: Writing to files
Post by: lelldorin on February 10, 2013, 02:55:29 PM
For my templates of my EGSL IDE is this too much. I need smal ones, like onle read file or only read folder reoutines.

I have open a new treat for this, because i will collect all i can get :-)

*Sorry bad english ;-)
Title: Re: Writing to files
Post by: gaulthunter on February 18, 2013, 03:47:54 AM
Firstly, I might say that "eggshell" sounds like a rather funny name for EGSL.

Other than that, Eggshell does not lack a way of doing such things. Though, the resource upon which one could achieve the knowledge of how to doing this, is not quite finished yet.
Anyway, this link (which redirects to the, as mentioned before, unfinished documentation) should help you at least a little:
http://egsl.retrogamecoding.org/documentation/egsldocumentation.html
I hope that this forum supports link-posting.
If not so, just search for the documentation or ask someone round here.

Additionally, I may try some of the commands in the next few days, as I literally rush through the unexplained commands by (attempting to) using them in programmes.


-- Kolyamatic
-- EDIT: some minor grammatical issues

I've read that and used the functions it has listed, they create the files, as I want, but don't seem to write or read from them.
Title: Re: Writing to files
Post by: gaulthunter on February 18, 2013, 03:48:47 AM
EGSL can do everything Lua can, so you can simply use Lua functions for working with files. You can also use additional EGSL functions - see File Management section in EGSL documentation (http://egsl.retrogamecoding.org/documentation/egsldocumentation.html).
When I use the default Lua syntax, it raises an error in the Eggshell IDE...
Title: Re: Writing to files
Post by: gaulthunter on February 18, 2013, 03:50:11 AM
Let me give it another try, an example someone gave has given me an idea
Title: Re: Writing to files
Post by: gaulthunter on February 18, 2013, 04:02:13 AM
I got it working! Thank you to everyone!