Author Topic: Writing to files  (Read 5491 times)

gaulthunter

  • Guest
Writing to files
« 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?

kolyamatic

  • Guest
Re: Writing to files
« Reply #1 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

Tomaaz

  • Guest
Re: Writing to files
« Reply #2 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.

cvirus

  • Guest
Re: Writing to files
« Reply #3 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

« Last Edit: February 09, 2013, 06:58:27 PM by cvirus »

Tomaaz

  • Guest
Re: Writing to files
« Reply #4 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)

lelldorin

  • Guest
Re: Writing to files
« Reply #5 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 :-)

Tomaaz

  • Guest
Re: Writing to files
« Reply #6 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)

lelldorin

  • Guest
Re: Writing to files
« Reply #7 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 ;-)

gaulthunter

  • Guest
Re: Writing to files
« Reply #8 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.

gaulthunter

  • Guest
Re: Writing to files
« Reply #9 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.
When I use the default Lua syntax, it raises an error in the Eggshell IDE...

gaulthunter

  • Guest
Re: Writing to files
« Reply #10 on: February 18, 2013, 03:50:11 AM »
Let me give it another try, an example someone gave has given me an idea

gaulthunter

  • Guest
Re: Writing to files
« Reply #11 on: February 18, 2013, 04:02:13 AM »
I got it working! Thank you to everyone!