File.finalize

From OpenEUO
Revision as of 13:08, 24 November 2010 by Ximan (Talk | contribs) (Created page with "== Calling Pattern == Call local f = sl.file(a,b) later: f.finalize() == Example Usage == local t = {[3.14] = 0.7071, [' una ']=1, test='Some "random" string.'} local f = s...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Calling Pattern

Call

local f = sl.file(a,b)

later:

f.finalize()

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 finalize method writes flushes the file buffer (if file was opened in 'write' mode) and closes the underlying file. The file object is no longer valid after this operation, except for reopen calls.

See Also