Howto:Extend Nasal: Difference between revisions

Jump to navigation Jump to search
m
Line 3: Line 3:


== Status (cppbind) ==
== Status (cppbind) ==
As of 03/2013, this article should be considered depreciated, we have [[Nasal/CppBind|a new C++-based API for exposing C/C++ functions/data structures to Nasal and vice versa]] in [https://gitorious.org/fg/simgear/trees/next/simgear/nasal/cppbind $SG_SRC/nasal/cppbind]. Usually, there should be no need to use the bare Nasal APIs anymore for exposing functions/data to Nasal or Nasal-space types to C++, except for people working on the '''cppbind''' framework itself.  
As of 03/2013, this article should be considered depreciated, we have [[Nasal/CppBind|a new C++-based API for exposing C/C++ functions/data structures to Nasal and vice versa]] in {{Git file|gitorious|fg/simgear|next|simgear/nasal/cppbind|pre=$SG_SRC/}}. Usually, there should be no need to use the bare Nasal APIs anymore for exposing functions/data to Nasal or Nasal-space types to C++, except for people working on the '''cppbind''' framework itself.  


The cppbind framework is much more generic and high level than the bare APIs documented here, it includes unit testing support and makes use of modern C++ features like templates and STL support, including SimGear specific types like SGPath/SGGeod etc, its overhead is fairly small (not just performance, but also LoC to create new bindings).
The cppbind framework is much more generic and high level than the bare APIs documented here, it includes unit testing support and makes use of modern C++ features like templates and STL support, including SimGear specific types like SGPath/SGGeod etc, its overhead is fairly small (not just performance, but also LoC to create new bindings).
Line 42: Line 42:
All Nasal related articles can be found in the [http://wiki.flightgear.org/index.php/Category:Nasal Nasal category].
All Nasal related articles can be found in the [http://wiki.flightgear.org/index.php/Category:Nasal Nasal category].


'''Note:''' FlightGear's version of the Nasal interpreter is maintained in the [http://www.simgear.org SimGear] git repository, inside the [gitorious.org/fg/simgear/trees/next/simgear/nasal] folder, the most important header file detailing the internal Nasal API is "[http://simgear.org/doxygen/nasal_8h-source.html nasal.h]", you will want to check this out for the latest changes and information.
'''Note:''' FlightGear's version of the Nasal interpreter is maintained in the [http://www.simgear.org SimGear] git repository, inside the {{Git file|gitorious|fg/simgear|next|simgear/nasal|pre=$SG_SRC/}} folder, the most important header file detailing the internal Nasal API is "[http://simgear.org/doxygen/nasal_8h-source.html nasal.h]", you will want to check this out for the latest changes and information.


You will probably also want to check out the [gitorious.org/fg/simgear/trees/next/simgear/nasal] folder for specific examples on using the various Nasal APIs that are not yet covered here completely.
You will probably also want to check out the {{Git file|gitorious|fg/simgear|next|simgear/nasal|pre=$SG_SRC/}} folder for specific examples on using the various Nasal APIs that are not yet covered here completely.


'''Important:''' As of 05/2009, this article is work in progress, and none of the examples have so far been tested/compiled.  
'''Important:''' As of 05/2009, this article is work in progress, and none of the examples have so far been tested/compiled.  
Line 52: Line 52:


= Intro =
= Intro =
In FlightGear, the simplest way to add new extension functions is to look at the existing functions in [http://gitorious.org/fg/flightgear/blobs/next/src/Scripting/NasalSys.cxx#line482 $FG_SRC/Scripting/NasalSys.cxx](src/Scripting/NasalSys.cxx).
In FlightGear, the simplest way to add new extension functions is to look at the existing functions in {{Git file|gitorious|fg/flightgear|next|src/Scripting/NasalSys.cxx|482|pre=$FG_SRC/}}.


There is a static table of function pointers (named funcs[]) referencing extension functions, along with their corresponding names in Nasal: http://gitorious.org/fg/flightgear/blobs/next/src/Scripting/NasalSys.cxx#line482
There is a static table of function pointers (named funcs[]) referencing extension functions, along with their corresponding names in Nasal: {{Git file|gitorious|fg/flightgear|next|src/Scripting/NasalSys.cxx|482|pre=$FG_SRC/}}
The following is a copy of the extension function list, taken in 05/2009:
The following is a copy of the extension function list, taken in 05/2009:


Line 176: Line 176:


The naRef objects can be manipulated using the functions in [http://simgear.org/doxygen/nasal_8h-source.html nasal.h].
The naRef objects can be manipulated using the functions in [http://simgear.org/doxygen/nasal_8h-source.html nasal.h].
For the latest copy of the file, see: http://gitorious.org/fg/simgear/blobs/next/simgear/nasal/nasal.h
For the latest copy of the file, see: {{Git file|gitorious|fg/simgear|next|simgear/nasal/nasal.h|pre=$SG_SRC/}}


Basically, you can check the type of the reference with the following naIs*() functions:
Basically, you can check the type of the reference with the following naIs*() functions:
Line 311: Line 311:


= Wrapping C++ Classes as Nasal Objects (cppbind) =
= Wrapping C++ Classes as Nasal Objects (cppbind) =
Please see: https://gitorious.org/fg/simgear/trees/next/simgear/nasal/cppbind
Please see: {{Git file|gitorious|fg/simgear|next|simgear/nasal/cppbind|pre=$SG_SRC/}}
<!--
<!--
'''To be written by Hooray & Zakalawe'''
'''To be written by Hooray & Zakalawe'''
395

edits

Navigation menu