20,741
edits
(→Intro) |
(→Intro) |
||
| Line 3: | Line 3: | ||
== Intro == | == Intro == | ||
Until FlightGear 2.8, FlightGear's built-in [[Nasal]] scripting engine only provided a C API to expose hooks/bindings to scripting space or to expose scripting space data structures back to C/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 | Until FlightGear 2.8, FlightGear's built-in [[Nasal]] scripting engine only provided a C API to expose hooks/bindings to scripting space or to expose scripting space data structures back to C/C++. 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. | ||
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 | Thanks to Tom's [[Canvas]] system, there's now a new bindings framework to be found in simgear/nasal/cppbind. This is fully object oriented and supports modern C++ features. | ||
You will find that most of the "old" code in $FG_SRC/Scripting still uses those old C-APIs for interacting with the Nasal engine. Only the new code, #include'ing <simgear/nasal/cppbind>, uses boost templates to hide low level details. | You will find that most of the "old" code in $FG_SRC/Scripting still uses those old C-APIs for interacting with the Nasal engine. Only the new code, #include'ing <simgear/nasal/cppbind>, uses boost templates to hide low level details. | ||
| Line 15: | Line 17: | ||
Meanwhile, we suggest to favor cppbind over the old, low-level, approach, it isn't only much more elegant, but also saves you tons of typing, too - and will do certain error-checking automatically, that you would otherwise have to implement manually. | Meanwhile, we suggest to favor cppbind over the old, low-level, approach, it isn't only much more elegant, but also saves you tons of typing, too - and will do certain error-checking automatically, that you would otherwise have to implement manually. | ||
After working through this article, tome of the more straightforward things to play with, would be exposing | After working through this article, tome of the more straightforward things to play with i the beginning, would be exposing additional SG/FG classes to Nasal space, such as the SGSubsystem interface to register scripted SGSubsystems, or the autopilot system or exposing the random buildings system [http://forum.flightgear.org/viewtopic.php?f=5&t=21131&p=192489&hilit=cppbind#p192489]. There's also a pending feature request ({{Issue|619}}) to implement USB-HID support [http://forum.flightgear.org/viewtopic.php?f=24&t=20159&p=185021&hilit=cppbind#p185021]. | ||
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. | 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. | ||