Nasal library/debug: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
No edit summary
Line 7: Line 7:
{{Nasal doc
{{Nasal doc
|syntax = debug.attributes(p[, verbose[, color]]);
|syntax = debug.attributes(p[, verbose[, color]]);
|text = Returns a string showing the attributes of the node, in the form <code>(''type''[, ''attr''[, L''num''[, #''refs'']])</code>. See the table below for explanation.
|text = Returns a string showing the attributes of the node, in the form <code>('''type'''[, '''attr'''[, L'''num'''[, #'''refs''']])</code>. See the table below for explanation.


{{{!}} class="wikitable"
! Data !! Meaning
{{!-}}
{{!}} type {{!!}} Type of node as returned by {{func link|getType()|props|Node}}.
{{!-}}
{{!}} attr {{!!}} Various attribute flags, see {{func link|getAttribute()|props|Node}}. "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.
{{!}}}
|param1 = p
|param1 = p
|param1text = Mandatory <code>props.Node</code> object.
|param1text = Mandatory <code>props.Node</code> object.
Line 15: Line 26:
|param3 = color
|param3 = color
|param3text = Optional bool specifying whether to output the string with an {{wikipedia|ANSI escape code#Colors|ANSI color code}}. Defaults to <code>'''nil'''</code>.
|param3text = Optional bool specifying whether to output the string with an {{wikipedia|ANSI escape code#Colors|ANSI color code}}. Defaults to <code>'''nil'''</code>.
|example1 =  
|example1 = var node = props.globals.getNode("/sim/time/gmt");
print(debug.attributes(node)); # prints "(STRING, AT, #1)" - string, archive, tied, 1 extra ref
|example2 = var node = props.Node.new();
node.setIntValue(12);
node.setAttribute(17);
print(debug.attributes(node)); # prints "(INT, wR)" - integer, write protected, trace read
|example3 = var node = props.globals.getNode("/sim/signals/fdm-initialized");
print(debug.attributes(node)); # prints "(BOOL, L6, #16)" - bool, 6 listeners, 16 extra refs
}}
}}
{| class="wikitable"
! Data !! Meaning
|-
| type || Type of node as returned by {{func link|getType()|props|Node}}.
|}


=== backtrace() ===
=== backtrace() ===

Revision as of 19:38, 17 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()

bt()

benchmark()

benchmark_time()

dump()

isnan()

local()

print_rank()

printerror()

propify()

proptrace()

rank()

string()

tree()

warn()