4,400
edits
mNo edit summary |
m (Robot: Cosmetic changes) |
||
Line 5: | Line 5: | ||
Some interesting ideas for extending Nasal this way have been collected at [[Proposals:Nasal related]]. | Some interesting ideas for extending Nasal this way have been collected at [[Proposals:Nasal related]]. | ||
= Pre-Requisites = | = Pre-Requisites = | ||
In order to work through this article, you will likely need to be interested in FlightGear core development, need to be somewhat familiar with C/C++, as well as with some basic Nasal (given that Nasal itself is implemented in ANSI C, basic C knowledge will mostly do for starters-C++ knowledge will only be required in order to understand the FlightGear side of things). | In order to work through this article, you will likely need to be interested in FlightGear core development, need to be somewhat familiar with C/C++, as well as with some basic Nasal (given that Nasal itself is implemented in ANSI C, basic C knowledge will mostly do for starters-C++ knowledge will only be required in order to understand the FlightGear side of things). | ||
Line 113: | Line 113: | ||
print(result); | print(result); | ||
= Argument Processing = | = Argument Processing = | ||
Consider the callback signature: | Consider the callback signature: | ||
static naRef f_cool (naContext c, naRef me, int argc, naRef* args) | static naRef f_cool (naContext c, naRef me, int argc, naRef* args) | ||
Line 237: | Line 237: | ||
naRef naStringValue(naContext c, naRef n); | naRef naStringValue(naContext c, naRef n); | ||
= Passing Pointers to Nasal scripts = | = Passing Pointers to Nasal scripts = | ||
Things get more complicated if you need to pass a handle to a C/C++ object into a Nasal script. | Things get more complicated if you need to pass a handle to a C/C++ object into a Nasal script. There, you need to use a wrapped handle type called a ghost ("Garbage-collectable Handle to an OutSide Thing"), which has a callback that you need to implement to deal with what happens when the Nasal interpreter garbage collects your object. | ||
Ghost utilities: | Ghost utilities: | ||
Line 254: | Line 254: | ||
For an example how something like this is done in the FlightGear context, you may want to check out $FG_SRC/Scripting/nasal-props.cxx, which wraps the SGPropertyNode class ([[SimGear]]) inside a nasal ghost, so that the C++ class is exposed to Nasal scripts. | For an example how something like this is done in the FlightGear context, you may want to check out $FG_SRC/Scripting/nasal-props.cxx, which wraps the SGPropertyNode class ([[SimGear]]) inside a nasal ghost, so that the C++ class is exposed to Nasal scripts. | ||
= Things to avoid = | = Things to avoid = | ||
And just for completeness: things get *really* complicated if you need to *store* a naRef you got from a Nasal script in a place where the interpreter can't see it. | And just for completeness: things get *really* complicated if you need to *store* a naRef you got from a Nasal script in a place where the interpreter can't see it. | ||
Line 264: | Line 264: | ||
But this API doesn't yet have a corresponding call to release a saved object. Just don't do this, basically. | But this API doesn't yet have a corresponding call to release a saved object. Just don't do this, basically. Always keep your Nasal data in Nasal space. | ||
If you really need to do this, you may however want to check out the gcSave/gcRelease methods of the FGNasalSys class: | If you really need to do this, you may however want to check out the gcSave/gcRelease methods of the FGNasalSys class: | ||
Line 276: | Line 276: | ||
int gcSave(naRef r); | int gcSave(naRef r); | ||
void gcRelease(int key); | void gcRelease(int key); | ||
[[Category:Nasal]] | [[Category:Nasal]] | ||
[[Category:Core Documentation]] | [[Category:Core Documentation]] |