Re: [Flightgear-devel] Nasal/*.nas ... order of loading, #include ..., require(...)
On my machine I observe that the various scripts in the Nasal/ directory get loaded in some hard-to-predict order. The scripts get loaded in the order of appearence in the directory. There is no specific order specified and the order might depend on the operating system. On *nixes opendir() and readdir() are used to enumerate the file while on Windows FindFirstFile/FindNextFile do the job. That means that if you write a script called foo.nas, it's hard to know whether it will get processed before or after math.nas and/or props.nas. So the question is, what to do if foo.nas wants to make use of the features provided by the other scripts? I know about the trick of using settimer(stuff, 0). That trick is not recommended. The recommended way of making sure all scripts in the nasal-dir are fully loaded is to use a listener on nasal-dir- initialized. You should find many examples in the nasal directory. But what if we wanted to use math functions in the code that actually runs at the time the scripts are loaded? Use the listener. In particular, does nasal have any sort of #include directive (as in c++) or require or use directive (as in perl)? If so, is it documented somewhere? If not, has anybody thought about how to implement it? Our nasal version does not. If some day we adopt a newer nasal library, it has support for import(foo); to import foo.nas. Greetings, Torsten -- SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
[Flightgear-devel] Nasal/*.nas ... order of loading, #include ..., require(...)
On my machine I observe that the various scripts in the Nasal/ directory get loaded in some hard-to-predict order. That means that if you write a script called foo.nas, it's hard to know whether it will get processed before or after math.nas and/or props.nas. So the question is, what to do if foo.nas wants to make use of the features provided by the other scripts? I know about the trick of using settimer(stuff, 0). But what if we wanted to use math functions in the code that actually runs at the time the scripts are loaded? In particular, does nasal have any sort of #include directive (as in c++) or require or use directive (as in perl)? If so, is it documented somewhere? If not, has anybody thought about how to implement it? -- SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Nasal/*.nas ... order of loading, #include ..., require(...)
On Thu, Feb 11, 2010 at 10:59 PM, John Denker j...@av8n.com wrote: On my machine I observe that the various scripts in the Nasal/ directory get loaded in some hard-to-predict order. That means that if you write a script called foo.nas, it's hard to know whether it will get processed before or after math.nas and/or props.nas. So the question is, what to do if foo.nas wants to make use of the features provided by the other scripts? I know about the trick of using settimer(stuff, 0). The usual trick is to attach a listener to /sim/signals/nasal-dir-initialized. Also, you can load nasal modules dynamically, such as: if (!contains(globals, MPCarriersNW)) { io.load_nasal(getprop(/sim/fg-root) ~ /Aircraft/MPCarrier/Systems/mp-network.nas, MPCarriersNW); -- Csaba/Jester -- SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Nasal/*.nas ... order of loading, #include ..., require(...)
On 02/11/2010 04:11 PM, Csaba Halász wrote: On Thu, Feb 11, 2010 at 10:59 PM, John Denker j...@av8n.com wrote: On my machine I observe that the various scripts in the Nasal/ directory get loaded in some hard-to-predict order. That means that if you write a script called foo.nas, it's hard to know whether it will get processed before or after math.nas and/or props.nas. So the question is, what to do if foo.nas wants to make use of the features provided by the other scripts? I know about the trick of using settimer(stuff, 0). The usual trick is to attach a listener to /sim/signals/nasal-dir-initialized. That is similar to the settimer trick. Either one will bisect the problem. That is, if you have simple pairwise interactions, you can split each pair and thereby control the ordering. But what if the interactions are more complicated, e.g. a depends on b which depends on c which depends on d? How hard would it be to handle the general case? There are standard techniques ... Also, you can load nasal modules dynamically, such as: if (!contains(globals, MPCarriersNW)) { io.load_nasal(getprop(/sim/fg-root) ~ /Aircraft/MPCarrier/Systems/mp-network.nas, MPCarriersNW); That's a powerful procedure, but it only works _after_ io.nas has been loaded ... so AFAICT it doesn't really answer the question I was asking. -- SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel