2,732
edits
m (→Intro) |
Red Leader (talk | contribs) (Minor edits) |
||
Line 1: | Line 1: | ||
{{Nasal Internals}} | {{Nasal Internals}} | ||
This article is dedicated to describing how to write custom C/C++ extension functions in order to ''extend the [[Nasal]] scripting interpreter'' in FlightGear, for example in order to expose new or existing FlightGear APIs to the Nasal scripting engine, so that Nasal scripts can access additional FlightGear internals. | This article is dedicated to describing how to write custom C/C++ extension functions in order to '''extend the [[Nasal]] scripting interpreter''' in FlightGear, for example in order to expose new or existing FlightGear APIs to the Nasal scripting engine, so that Nasal scripts can access additional FlightGear internals. | ||
<!-- Some interesting ideas for extending Nasal this way have been collected at [[Proposals:Nasal related]]. Article was deleted 1 July 2014. /Johan G, 12 December 2014 --> | <!-- Some interesting ideas for extending Nasal this way have been collected at [[Proposals:Nasal related]]. Article was deleted 1 July 2014. /Johan G, 12 December 2014 --> | ||
Line 48: | Line 48: | ||
== Intro == | == Intro == | ||
In FlightGear, the simplest way to add new extension functions is to look at the existing functions at {{flightgear file|src/Scripting/NasalSys.cxx | In FlightGear, the simplest way to add new extension functions is to look at the existing functions at {{flightgear file|src/Scripting/NasalSys.cxx}}. | ||
There is a static table of function pointers (named funcs[]) referencing extension functions, along with their corresponding names in Nasal: {{flightgear file|src/Scripting/NasalSys.cxx|l= | There is a static table of function pointers (named funcs[]) referencing extension functions, along with their corresponding names in Nasal: {{flightgear file|src/Scripting/NasalSys.cxx|l=797}}. | ||
The following is a copy of the extension function list, taken in 11/2015: | The following is a copy of the extension function list, taken in 11/2015: | ||
Line 93: | Line 93: | ||
You will need to add your new extension function to this list of static functions, preferably following the existing naming convention (i.e. "f_" prefix). | You will need to add your new extension function to this list of static functions, preferably following the existing naming convention (i.e. "f_" prefix). | ||
If your extension functions are likely to be fairly low level, and will thus be provided with a more abstract wrapper in Nasal space, these functions should use a prepended undercore ("_"), such as the {{func link| | If your extension functions are likely to be fairly low level, and will thus be provided with a more abstract wrapper in Nasal space, these functions should use a prepended undercore ("_"), such as the {{func link|fgcommand()|pre=_}}, {{func link|setlistener()|pre=_}}, {{func link|cmdarg()|pre=_}} and {{func link|interpolate()|pre=_}} functions. | ||
== Extension function signature == | == Extension function signature == |