RetroBASIC
Retrogamecoding(.org) => EGSL => Topic started 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?
-
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
-
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).
-
Simple example to write into a file using LUA.
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)
-
And this is how it looks with additional EGSL function:
a = open("test2.txt", "w")
fprint(a, "Writing to text.txt file with EGSL and LUA")
close(a)
-
And this is how it looks with additional EGSL function:
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 :-)
-
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.
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)
-
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 ;-)
-
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.
-
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...
-
Let me give it another try, an example someone gave has given me an idea
-
I got it working! Thank you to everyone!