Nasal library/io: Difference between revisions

Jump to navigation Jump to search
→‎Functions: Doc flush(), fix doc
(→‎Functions: Doc dirname())
(→‎Functions: Doc flush(), fix doc)
Line 22: Line 22:
|syntax = io.close(file);
|syntax = io.close(file);
|text = Closes the specified file. Returns <code>'''nil'''</code>.
|text = Closes the specified file. Returns <code>'''nil'''</code>.
|param1 = path
|param1 = file
|param1text = Path as a string.
|param1text = File object as returned by {{func link|open()}}.
|example1 = var path = getprop("/sim/fg-root") ~ '/keyboard.xml';
|example1 = var path = getprop("/sim/fg-root") ~ '/keyboard.xml';
var file = io.open(path);
var file = io.open(path);
Line 45: Line 45:


=== flush() ===
=== flush() ===
{{Nasal doc
|syntax = io.flush(file);
|text = Flushes the file's buffer. This means that the contents of the buffer (a kind of temporary storage) are written to the actual file on the hard disk. Note that the buffer is also flushed when {{func link|close()}} is called.
|param1 = file
|param1text = File object as returned by {{func link|open()}}.
|example1 = var path = getprop("/sim/fg-home") ~ '/Export/demo.txt';
var file = io.open(path, "w+"); # create and open file
io.write(file, "Hello, World!"); # write (to the buffer)
var file2 = io.open(path); # open the file separatly
var b = bits.buf(13); # create a buffer
io.read(file2, b, 13); # read file
print(b); # prints nothing
io.flush(file); # flush buffer to file
io.read(file2, b, 13); # read file again
print(b); # prints "Hello, World!"
io.close(file); # close
io.close(file2);
}}
=== include() ===
=== include() ===
=== load_nasal() ===
=== load_nasal() ===

Navigation menu