Don't exactly know what you're trying to achieve here, but there are a couple of things I can suggest regarding writing to files and saving data.
1) The
FS API.
Using
fs.open( path, "w" ) you can modify the contents of a file by writing strings to it.
2) The
Textutils API.
Using
textutils.serialize( variable ) you can turn pretty much every Lua datatype into a string that can be converted back using
textutils.unserialize().
3) string.dump()
This will return the string representation of a function (in Lua bytecode) that can be converted back to its (near) original state using
loadstring().
Let's say you have a table...
local player = {
name = "foo";
x = 0;
y = 0;
health = 100;
}
You want to save this player table to a file. Using
textutils.serialize() you can turn it into a single string.
local str_representation = textutils.serialize( player )
Then you can write the string to a file like this.
local h = fs.open( file, "w" )
h.write( str_representation )
h.close()
If you want to get it back into a table, you need to read the file then unserialize it.
local h = fs.open( file, "r" )
local content = h.readAll()
h.close()
local player = textutils.unserialize( content )