Library globals

Namespace globals . props

View source

Node class definition.  The class methods simply wrap the
low level extension functions which work on a "ghost" handle to a
SGPropertyNode object stored in the _g field.

Not all of the features of SGPropertyNode are supported.  There is
no support for ties, obviously, as that wouldn't make much sense
from a Nasal context.  The various get/set methods work only on the
local node, there is no equivalent of the "relative path" variants
available in C++; just use node.getNode(path).whatever() instead.

Classes

Node

Node class definition. The class methods simply wrap the low level extension functions which work on a "ghost" handle to a SGPropertyNode object stored in the _g field. Not all of the features of SGPropertyNode are supported. There is no support for ties, obviously, as that wouldn't make much sense from a Nasal context. The various get/set methods work only on the local node, there is no equivalent of the "relative path" variants available in C++; just use node.getNode(path).whatever() instead.

UpdateManager

example usage: this is using the hashlist (which works well with an Emesary notification) basically when the method is called it will call each section (in the lambda) when the value changes by more than the amount specified as the second parameter. It is possible to reference multiple elements from the hashlist in each FromHashList; if either one changes then it will result in the lambda being called. obj.update_items = [ UpdateManager.FromHashList(["VV_x","VV_y"], 0.01, func(val) { obj.VV.setTranslation (val.VV_x, val.VV_y + pitch_offset); }), UpdateManager.FromHashList(["pitch","roll"], 0.025, func(hdp) { obj.ladder.setTranslation (0.0, hdp.pitch * pitch_factor+pitch_offset); obj.ladder.setCenter (118,830 - hdp.pitch * pitch_factor-pitch_offset); obj.ladder.setRotation (-hdp.roll_rad); obj.roll_pointer.setRotation (hdp.roll_rad); }), props.UpdateManager.FromProperty("velocities/airspeed-kt", 0.01, func(val) { obj.ias_range.setTranslation(0, val * ias_range_factor); }), props.UpdateManager.FromPropertyHashList(["orientation/alpha-indicated-deg", "orientation/side-slip-deg"], 0.1, func(val) { obj.VV_x = val.property["orientation/side-slip-deg"].getValue()*10; # adjust for view obj.VV_y = val.property["orientation/alpha-indicated-deg"].getValue()*10; # adjust for view obj.VV.setTranslation (obj.VV_x, obj.VV_y); }), ] ==== the update loop then becomes ====== foreach(var update_item; me.update_items) { # hdp is a data provider that can be used as the hashlist for the property # update from hash methods. update_item.update(hdp); }

Functions

compileCondition

Compiles a <condition> property branch according to the rules set out in $FG_ROOT/Docs/README.conditions into a Condition object. The 'test' method of the returend object can be used to evaluate the condition. The function returns nil on error.

condition

Evaluates a <condition> property branch according to the rules set out in $FG_ROOT/Docs/README.conditions. Undefined conditions and a nil argument are "true". The function dumps the condition branch and returns nil on error.

copy

Recursively copy property branch from source Node to destination Node. Doesn't copy aliases. Copies attributes if optional third argument is set and non-zero.

createNodeObjectsFromHash

createNodeObjectsFromHash - create nasal node objects from hash property_list: hash; where keys are variable names and values are property paths { foo: "/some/prop/foo", bar: "/some/other/prop", } namespace: optional; variables (objects) are created in this namespace defaults to namespace of caller, e.g. after calling this you can use foo.getValue() or bar.addChild()

dump

Useful debugging utility. Recursively dumps the full state of a Node object to the console. Try binding "props.dump(props.globals)" to a key for a fun hack.

getNode

Shortcut for props.globals.getNode().

nodeList

Turns about anything into a list of props.Nodes, including ghosts, path strings, vectors or hashes containing, as well as functions returning any of the former and in arbitrary nesting. This is meant to be used in functions whose main purpose is to handle collections of properties.

runBinding

Runs <binding> as described in $FG_ROOT/Docs/README.commands using a given module by default, and returns 1 if fgcommand() succeeded, or 0 otherwise. The module name won't override a <module> defined in the binding.

setAll

Sets all indexed property children to a single value. arg[0] specifies a property name (e.g. /controls/engines/engine), arg[1] a path under each node of that name to set (e.g. "throttle"), arg[2] is the value.

wrap

Utility. Turns any ghosts it finds (either solo, or in an array) into Node objects.

wrapNode

Utility. Returns a new object with its superclass/parent set to the Node object and its _g (ghost) field set to the specified object. Nasal's literal syntax can be pleasingly terse. I like that. :)

Variables

globals

Global property tree. Set once at initialization. Is that OK? Does anything ever call globals.set_props() from C++? May need to turn this into a function if so.