Nasal library/debug: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎Functions: Doc backtrace() and bt())
Line 37: Line 37:


=== backtrace() ===
=== backtrace() ===
{{Nasal doc
|syntax = debug.backtrace([desc]);
|text = When called, this function prints the {{wikipedia|backtrace}}, also printing the local variables at each level.
|param1 = desc
|param1text = Optional extra description to add.
|example1 = var myFunc = func(a){
    multiply(a, 2);
}
var multiply = func(x, y){
    debug.backtrace();
}
myFunc(2);
|example2 = var myFunc = func(a){
    multiply(a, 2);
}
var multiply = func(x, y){
    debug.backtrace("multiply() function");
}
myFunc(2);
}}
=== bt() ===
=== bt() ===
{{Nasal doc
|syntax = debug.bt([desc]);
|text = Shortcut for {{func link|backtrace()|page=this}}. See doc there
}}
=== benchmark() ===
=== benchmark() ===
=== benchmark_time() ===
=== benchmark_time() ===

Revision as of 15:34, 18 November 2016

WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.

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 This is a link to a Wikipedia article. 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 This is a link to a Wikipedia article, 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()

benchmark_time()

dump()

isnan()

local()

print_rank()

printerror()

propify()

proptrace()

rank()

string()

tree()

warn()