File.tofile
From OpenEUO
Revision as of 13:02, 24 November 2010 by Ximan (Talk | contribs) (Created page with "== Calling Pattern == Call local f = sl.file(a,b) local r = f.tofile(c) Args c is a nil, null, boolean, number, string, or table Results r is a boolean == Example Usage == ...")
Calling Pattern
Call
local f = sl.file(a,b)
local r = f.tofile(c)
Args
c is a nil, null, boolean, number, string, or table
Results
r is a boolean
Example Usage
local t = {[3.14] = 0.7071, [' una ']=1, test='Some "random" string.'}
local f = sl.file(getinstalldir()..'scripts/testwrite.dat', 'write')
f.tofile(t)
f.finalize()
f = nil
local g = sl.file(getinstalldir()..'scripts/testwrite.dat', 'read')
local v = g.readnext()
g = nil
print(sl.keyvalstr(v))
--> table keys:values = {
una :1,
test:Some "random" string.,
3.14:0.7071,
}
Description
The tofile method writes the given data to a structured file and flushes the file buffer. In version 0.06 will return a boolean denoting success or failure.
Upon Error
Tofile fails silently if passed an invalid type (function, thread, userdata).