2,733
edits
Red Leader (talk | contribs) (Start editing) |
Red Leader (talk | contribs) (Put in alphabetical order) |
||
Line 4: | Line 4: | ||
== Functions == | == Functions == | ||
=== | === basename() === | ||
Works like standard Unix command basename. Returns the file name from a given path. | |||
<syntaxhighlight lang="nasal"> | |||
io.basename(<path>); | |||
</syntaxhighlight> | |||
=== close(filehandle) === | === close(filehandle) === | ||
Closes the specified file as per ANSI fclose(). | Closes the specified file as per ANSI fclose(). | ||
=== | === dirname() === | ||
Works like standard Unix command dirname. Returns the directory part from a given path. | |||
<syntaxhighlight lang="nasal"> | |||
io.basename(<path>); | |||
</syntaxhighlight> | |||
=== | === flush() === | ||
=== include() === | |||
=== load_nasal() === | |||
=== | === open(filename, mode="r") === | ||
Opens the file with the specified mode (as per ANSI fopen()) and returns a ghost object representing the filehandle. Failures are thrown as runtime errors as per die(). | |||
=== | === read(filehandle, buf, len) === | ||
Attempts to read length bytes from the filehandle into the beginning of the mutable string buf. Failures (including overruns when length > size(buf)) are thrown as runtime errors as per die(). Returns the number of bytes successfully read. | |||
=== | === read_airport_properties() === | ||
Load XML file in FlightGear's native <PropertyList> format. | |||
File will be located in the airport-scenery directories according to | |||
ICAO and filename, i,e in Airports/I/C/A/ICAO.filename.xml | |||
If the second, optional target parameter is set, then the properties are loaded to this node in the global property tree. | |||
Otherwise they are returned as a separate props.Node tree. | |||
Returns the data as a props.Node on success or nil on error. | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
io. | Usage: io.read_properties(<filename> [, <props.Node or property-path>]); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Example: | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
io. | var data = io.read_airport_properties("KSFO", "rwyuse"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 65: | Line 65: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | === readfile() === | ||
Reads and returns a complete file as a string. Failures are thrown as runtime errors as per die(). | |||
<syntaxhighlight lang="nasal"> | |||
io.readfile(file); | |||
</syntaxhighlight> | |||
=== 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. | |||
If the | === readxml() === | ||
Reads an XML file from an absolute path and returns it as property | |||
Returns | tree. All nodes will be of type STRING. Data are only written to | ||
leafs. Attributes are written as regular nodes with the optional | |||
prefix prepended to the name. If the prefix is nil, then attributes | |||
are ignored. Returns nil on error. | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
Usage: | Usage: io.readxml(path[, prefix = "___"]); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
io.readxml(path,prefix); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=== seek(filehandle, position, whence) === | |||
As ANSI fseek(). Attempts to seek to the specified position based on the whence value (which must be one of io.SEEK_SET, io.SEEK_END, or io.SEEK_CUR). | |||
=== stat(filename) === | |||
Calls unix or win32 stat() on the specified file name and returns a seven element array whose contents are, in order: dev, ino, mode, nlink, uid, gid, rdef, size, atime, mtime, ctime. Errors are signaled as exceptions as per die(). | |||
=== tell(filehandle) === | |||
Returns the current seek position of the filehandle. | |||
=== write(filehandle, str) === | |||
Attempts to write the entirety of the specified string to the filehandle. Failures are thrown as runtime errors as per die(). Returns the number of bytes successfully written. | |||
=== write_properties() === | === write_properties() === | ||
Line 95: | Line 112: | ||
io.write_properties("/tmp/foo.xml", data); | io.write_properties("/tmp/foo.xml", data); | ||
io.write_properties("/tmp/foo.xml", "/sim/model"); | io.write_properties("/tmp/foo.xml", "/sim/model"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||