Howto:Add new fgcommands to FlightGear: Difference between revisions

Jump to navigation Jump to search
m
Line 10: Line 10:
An overview of fgcommands currently available and supported is provided in [http://gitorious.org/fg/fgdata/blobs/master/Docs/README.commands $FG_ROOT/Docs/README.commands].
An overview of fgcommands currently available and supported is provided in [http://gitorious.org/fg/fgdata/blobs/master/Docs/README.commands $FG_ROOT/Docs/README.commands].


Creating a new fgcommand is fairly simple actually. The source code you need to look at is in [http://gitorious.org/fg/flightgear/blobs/next/src/Main/fg_commands.cxx $FG_SRC/Main/fg_commands.cxx].
Beginning with FlightGear 2.11+, new fgcommands can now also be implemented in [[Nasal]] and registered through new Nasal extension functions:
* '''addcommand(name, func)'''
* '''removecommand(name)'''
 
This allows you to make up new fgcommands just by implementing them in Nasal:
 
<syntaxhighlight lang="php">
addcommand("hello", func {
print("hello");
});
fgcommand("hello");
</syntaxhighlight>
 
Obviously, not all fgcommands can be implemented in Nasal, which is why you may sometimes still have to use C++ - creating a new fgcommand using C++ is also fairly simple actually. The source code you need to look at is in [http://gitorious.org/fg/flightgear/blobs/next/src/Main/fg_commands.cxx $FG_SRC/Main/fg_commands.cxx].




Navigation menu