2,732
edits
Red Leader (talk | contribs) (→open(): Add examples) |
Red Leader (talk | contribs) (→Functions: Doc read()) |
||
Line 167: | Line 167: | ||
}} | }} | ||
=== read( | === read() === | ||
{{Nasal doc | |||
|syntax = io.read(file, buf, len); | |||
|text = Reads a given number of bytes from the given file and places those bytes into the given buffer. The bytes will be read from the position of the position indicator (this can be changed using {{func link|seek}}). Failures are thrown as runtime errors. Returns the number of bytes successfully read. | |||
|param1 = file | |||
|param1text = File object as returned by {{func link|open}}. | |||
|param2 = buf | |||
|param2text = Buffer to read bytes into. A new buffer can be created using <code>bits.buf(size)</code>. Must not be smaller than '''len'''. | |||
|param3 = len | |||
|param3text = Number of bytes to read as an integer. The position indicator will be advanced by this number of bytes. Must not be greater than the size of '''buf'''. | |||
|example1 = var path = getprop("/sim/fg-root") ~ '/Nasal/geo.nas'; | |||
var file = io.open(path); | |||
var len = 5; | |||
var buf = bits.buf(len); | |||
io.read(file, buf, len); | |||
print(buf); # prints "# geo" | |||
io.read(file, buf, len); | |||
print(buf); # prints " func" | |||
io.close(file); | |||
}} | |||
=== read_airport_properties() === | === read_airport_properties() === |