Nasal library/debug
Jump to navigation
Jump to search
Work in progress This article or section will be worked on in the upcoming hours or days. See history for the latest developments. |
The FlightGear forum has a subforum related to: Nasal Scripting |
Nasal scripting |
---|
Nasal internals |
---|
Memory Management (GC) |
This page contains documentation for the debug
namespace in Nasal. This namespace provides various useful APIs for debugging Nasal code. The debug
namespace is sourced from fgdata/Nasal/debug.nas.
Functions
attributes()
debug.attributes(p[, verbose[, color]]);
Returns a string showing the attributes of the node, in the form (type[, attr[, Lnum[, #refs]])
. See the table below for explanation.
Data | Meaning |
---|---|
type | Type of node as returned by props.Node.getType() .
|
attr | Various attribute flags, see props.Node.getAttribute() . "r" = read protected, "w" = write protected, "R" = trace read, "W" = trace write, "A" = archive, "U" = userarchive, "P" = preserve, and "T" = tied.
|
num | Number of listeners, if any. |
refs | This argument will be shown if verbose is true. Tells the number of references to the node. Note that all nodes have two references by default, but this tells the number of extra references. |
- p
- Mandatory
props.Node
object. - verbose
- Optional bool specifying whether to show the number of times the node is referenced. Defaults to 1 (true).
- color
- Optional bool specifying whether to output the string with an ANSI color code . Defaults to
nil
.
Examples
var node = props.globals.getNode("/sim/time/gmt");
print(debug.attributes(node)); # prints "(STRING, AT, #1)" - string, archive, tied, 1 extra ref
var node = props.Node.new();
node.setIntValue(12);
node.setAttribute(17);
print(debug.attributes(node)); # prints "(INT, wR)" - integer, write protected, trace read
var node = props.globals.getNode("/sim/signals/fdm-initialized");
print(debug.attributes(node)); # prints "(BOOL, L6, #16)" - bool, 6 listeners, 16 extra refs
backtrace()
debug.backtrace([desc]);
When called, this function prints the backtrace , also printing the local variables at each level.
- desc
- Optional extra description to add.
Examples
var myFunc = func(a){
multiply(a, 2);
}
var multiply = func(x, y){
debug.backtrace();
}
myFunc(2);
var myFunc = func(a){
multiply(a, 2);
}
var multiply = func(x, y){
debug.backtrace("multiply() function");
}
myFunc(2);
bt()
debug.bt([desc]);
Shortcut for backtrace()
. See doc there
benchmark()
debug.benchmark(label, fn[, repeat[, output]]);
- label
- Label to add to the output.
- fn
- Function to call.
- repeat
- output