Using Nasal with FlightGear

This document is a tutorial on how to interface Nasal scripts with FlightGear. It is not an introduction to the Nasal language itself. For that, see Andy's Nasal website at http://www.plausible.org/nasal. The information there is sparse, but you should have it ready for reference while reading this document.

Basic Nasal/FlightGear Integration

Calling Nasal from Configuration File Bindings

Nasal scripts can be used as FGBinding objects, and can therefore appear anywhere in a configuration file (keyboard, mouse and joystick bindings, etc...) that accepts a <binding> tag. The relevant command type is "nasal", and you place your Nasal code inside of the <script> tag:
<binding>
 <command>nasal</command>
 <script>
  print("Binding Invoked!");
 </script>
</binding>

The code above invokes the print() function. This is a simple extension function that simply prints out its arguments, in order, to the FlightGear console as a single-line log entry. It is useful for debugging, but little else.

Some command have SGPropertyNode arguments. This argument is available as a props.Node object and is returned from the built-in cmdarg() function. See below for full documentation, but as an example the following "joystick axis" binding will print the current axis value to the console:

<binding>
 <command>nasal</command>
 <script>print(cmdarg().getNode("value").getValue());</script>
</binding>

Note that the current imple