Nasal library: Difference between revisions

Jump to navigation Jump to search
→‎resolvepath(): Finish docing
(→‎removelistener(): Oops, forgot source links)
(→‎resolvepath(): Finish docing)
Line 1,989: Line 1,989:


=== resolvepath() ===
=== resolvepath() ===
SimGear features its own [[Resolving Paths|path resolving framework]] that takes a relative path and returns an absolute path, checking from base directories such as [[$FG_ROOT]], [[$FG_HOME]], [[$FG_AIRCRAFT]], and the current aircraft directory (<tt>/sim/aircraft-dir</tt>). This function in Nasal takes a path string and returns the absolute path or an empty string if the path couldn't be resolved.
{{Nasal doc
 
|syntax = resolvepath(path);
Example:
|source = {{flightgear file|src/Scripting/NasalSys.cxx|l=604|t=Source}}
<syntaxhighlight lang="nasal">
|text = Takes a relative path as a string and uses [[SimGear]]'s path-resolving framework to return an absolute path as a string. If the path could not be resolved, an empty string is returned. See [[Resolving Paths]] for a detailed description of the algorithm.
var guess_path = func(path...) {
|param1 = path
    var path_concat = string.join(path, "/");
|param1text = Relative path to be completed.
    var file_path = resolvepath(path_concat);
|example1 = print(resolvepath("Nasal/globals.nas")); # prints the equivalent of $FG_ROOT/Nasal/globals.nas
    if (file_path == "") die("Path not found: "~path_concat);
|example2 = print(resolvepath("blah")); # prints nothing; could not be resolved
    return file_path;
}}
}
</syntaxhighlight>


=== setlistener() ===
=== setlistener() ===

Navigation menu