Difference between revisions of "File.tofile"

From OpenEUO
Jump to: navigation, search
m (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 == ...")
 
m (Calling Pattern)
 
Line 3: Line 3:
 
  local f = sl.file(a,b)
 
  local f = sl.file(a,b)
  
  local r = f.tofile(c)
+
  local r = f.tofile(c[,...])
 
Args
 
Args
  c is a nil, null, boolean, number, string, or table
+
  c1...cN are any of: nil, null, boolean, number, string, or table
 
Results
 
Results
 
  r is a boolean
 
  r is a boolean

Latest revision as of 12:03, 24 November 2010

Calling Pattern

Call

local f = sl.file(a,b)
local r = f.tofile(c[,...])

Args

c1...cN are any of: 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).

See Also