Nasal library/io: Difference between revisions

Jump to navigation Jump to search
→‎Functions: Doc readln()
(→‎readfile(): Finish doc)
(→‎Functions: Doc readln())
Line 241: Line 241:


=== readln(filehandle) ===
=== readln(filehandle) ===
Reads and returns a single text line from the filehandle. Interprets both "\n" and "\r\n" as end of line markers, and does not include the "\r" or "\n" bytes in the returned string. End of file or error is signaled by returning nil.
{{Nasal doc
|syntax = io.readfile(file);
|text = Reads and returns a single line from the file, advancing the position indicator. Accepts different {{wikipedia|newline}} types, including LF, CR, and CR+LF. Does not include the EOL character(s) in the returned string. End of file or an error is signaled by returning <code>'''nil'''</code>.
|param1 = file
|param1text = File object as returned by {{func link|open}}.
|example1 = var path = getprop("/sim/fg-root") ~ '/Nasal/bits.nas';
var file = io.open(path);
var line = io.readln(file);
print(line); # prints "var bit = [var _ = 1];"
line = io.readln(file);
print(line); # prints "for (var i = 1; i < 32; i += 1)"
}}


=== readxml() ===
=== readxml() ===

Navigation menu