Template:CppBind Ideas

From FlightGear wiki
Revision as of 19:14, 11 May 2014 by Hooray (talk | contribs) (http://forum.flightgear.org/viewtopic.php?f=5&t=22809&p=208983#p208980)
Jump to navigation Jump to search

FlightGear's built-in Nasal scripting language comes with a set of standard libraries, and can be extended using FlightGear specific APIs.

Exposing simulator internals to scripting space is a fairly common and useful thing, because it enables base package developers to access these internals without having to build FlightGear from source, so the barrier to entry is significantly lower and we've seen an increasing number of novel features purely implemented in scripting space, due to powerful APIs being available to aircraft developers and other base package developers.

Until FlightGear 2.8, the Nasal scripting engine only provided a C API to expose such hooks/bindings to scripting space or to expose scripting space data structures back to C/C++.

Unlike the core Nasal engine itself (which is C), FlightGear however is mostly written and being developed in C++. For quite a while, that meant that the Nasal APIs were a bit low-level, and sometimes also awkward to use when making functions, data structures or objects accessible between C++ and Nasal.

Thanks to development on Tom's Canvas system, there's now a new bindings framework to be found in $SG_SRC/simgear/nasal/cppbind. This is fully object oriented and supports modern C++ features by operating through classes and methods with full STL support, abstracting most common operations away.


After working through the Nasal/CppBind article, some of the more useful things to play with in the beginning, would be exposing additional SG/FG classes to Nasal space, such as for example:

  • SGPath Done Done (by TheTom)
  • FGProtocol, to implement I/O protocols via Nasal (and help solve ticket #396 and support AJAX, REST, JSON or WebSockets) 30}% completed [1] [2] [3] (stubs available at [4])
  • the loglist/SG_LOG() logging buffer machinery [5]
  • expose VoiceSynthesizer/FLITE TTS[6] to Nasal to get rid of ATC chatter [7] Not done Not done
  • the SGSubsystem interface to register scripted SGSubsystems
  • flight path history [8] Done Done (by TheTom)
  • the flight recorder system (replay buffers) Not done Not done
  • State machines e.g. to help clean up the ND code [9]
  • the autopilot system [10] [11] [12] (there are certain Nasal GC issues, so that we ask people not to implement FDM-coupled Nasal code like autopilots)
  • exposing the sound manager, so that scripts can directly play audio files [13]
  • exposing the random buildings system [14] Pending Pending [15]
  • There's also a pending feature request (ticket #619) to implement USB-HID support [16].
  • effects framework ?
  • Howto:Using OpenCL in FlightGear
  • Nasal/HLA bindings, so that we can run certain scripts as HLA federates outside the fgfs process space (such as bombable or local weather)
Note  Before working on anything related, please do get in touch with other contributors to ensure that this list is still up-to-date.

For more technical Nasal questions (C API, internals etc), you'll probably want to refer to Philosopher, TheTom, Zakalawe or Hooray on the forum - TheTom and Zakalawe can also provide help on using cppbind, having both used it extensively during the last months.