Nasal Namespaces in-depth: Difference between revisions

Jump to navigation Jump to search
m
mNo edit summary
Line 160: Line 160:


In the C code, there is a naFunc object that represents a function. In addition to specifying the executable part (which is a naCode or naCCode) it specifies the namespace and another naFunc to get the next namespace from. These naFunc’s end up being chained together to form the namespace hierarchy – each link is referred to as a "closure". The builtin closure() function follows the chain through the links (where 0 specifies the first link, etc.) and returns thay closure – a small slice of the variables the function has access to. The builtin bind() does the opposite: it specifies the first link in the chain for that function (its embedded link to the namespace) and possibly another function that spcifies the next namespace and the next function, etc. (or nil if it only has one closure). See [[Nasal Meta-programing]] for more on how they can be used together, but the key thing to remember is that namespaces are built on the backs of functions by using hashes as their key datatype.
In the C code, there is a naFunc object that represents a function. In addition to specifying the executable part (which is a naCode or naCCode) it specifies the namespace and another naFunc to get the next namespace from. These naFunc’s end up being chained together to form the namespace hierarchy – each link is referred to as a "closure". The builtin closure() function follows the chain through the links (where 0 specifies the first link, etc.) and returns thay closure – a small slice of the variables the function has access to. The builtin bind() does the opposite: it specifies the first link in the chain for that function (its embedded link to the namespace) and possibly another function that spcifies the next namespace and the next function, etc. (or nil if it only has one closure). See [[Nasal Meta-programing]] for more on how they can be used together, but the key thing to remember is that namespaces are built on the backs of functions by using hashes as their key datatype.
== Nasal Namespace Browser ==
[[File:Nasal-namespace-browser.png|thumb|Philosopher's latest invention: a Nasal namespace browser]]
Philosopher created a GUI browser for viewing the [[Nasal]] state (Nasal being our built-in,JavaScript-like, FlightGear scripting language). It's sorta like the property browser, except in [[Canvas]], and still a basic prototype, but already pretty useful for debugging purposes. Tested on 2.10, 2.11 and 2.12.
* Close button (or the escape key) closes the dialog, upon which point the code refreshes so that changes made will appear when it is next opened (rapid prototyping).
* Clicking on the title bar (next to the title) will go back in history
* clicking on an entry will go inside of that entry -- either a vector or a hash as both can be viewed (other types being displayed inline).
* Clicking and dragging on the displayed text will scroll the window (hey, it's still a prototype)
To use, place [http://codepad.org/14koLKeg the file] in Nasal/nasal_browser.nas and (preferably) add an entry to the menubar (the name tag should be "Toggle Nasal Browser" or similar and the Nasal script should be «nasal_browser.toggle_window()»).
To learn more, see http://flightgear.org/forums/viewtopic.php?f=71&t=20385

Navigation menu