Howto:Load a Nasal file at runtime: Difference between revisions
Jump to navigation
Jump to search
m (Category sorting) |
mNo edit summary |
||
Line 19: | Line 19: | ||
* paste the following code into this file using a text editor (such as notepad on Windows) | * paste the following code into this file using a text editor (such as notepad on Windows) | ||
<syntaxhighlight lang="php"> | |||
# test.nas (save in $FG_ROOT/Nasal) | # test.nas (save in $FG_ROOT/Nasal) | ||
var loader = func { | var loader = func { | ||
Line 25: | Line 26: | ||
_setlistener("/sim/signals/nasal-dir-initialized", loader); | _setlistener("/sim/signals/nasal-dir-initialized", loader); | ||
</syntaxhighlight> | |||
This piece of code defines a new function named "loader" that just invokes the io.load_nasal() function to load and execute a Nasal script, the filename being "loadme.nas.txt" (the .txt. extension is just to prevent the file from being loaded during startup). | This piece of code defines a new function named "loader" that just invokes the io.load_nasal() function to load and execute a Nasal script, the filename being "loadme.nas.txt" (the .txt. extension is just to prevent the file from being loaded during startup). | ||
Line 32: | Line 34: | ||
Then create another file containing: | Then create another file containing: | ||
<syntaxhighlight lang="php"> | |||
# loadme.nas.txt | # loadme.nas.txt | ||
print("loadme.txt loaded"); | print("loadme.txt loaded"); | ||
</syntaxhighlight> | |||
[[Category:Howto|Nasal, Load a file at runtime]] | [[Category:Howto|Nasal, Load a file at runtime]] | ||
[[Category:Nasal|Load a Nasal file at runtime]] | [[Category:Nasal|Load a Nasal file at runtime]] |
Revision as of 21:15, 5 January 2012
This article is a stub. You can help the wiki by expanding it. |
Status: Planning
Last updated: 12/2010
Authors: Hooray
References:
This tutorial will document all the steps involved in loading a Nasal file at runtime, Nasal is FlightGear's scripting language.
This tutorial is based on Howto: Create a new Nasal module, you should fully understand that one first.
- create a new plain text file under $FG_ROOT/Nasal/MODULE.nas
- replace MODULE with the name for your new module (for example, use "test")
- paste the following code into this file using a text editor (such as notepad on Windows)
# test.nas (save in $FG_ROOT/Nasal)
var loader = func {
io.load_nasal("loadme.nas.txt");
}
_setlistener("/sim/signals/nasal-dir-initialized", loader);
This piece of code defines a new function named "loader" that just invokes the io.load_nasal() function to load and execute a Nasal script, the filename being "loadme.nas.txt" (the .txt. extension is just to prevent the file from being loaded during startup).
The _setlistener call at the end of the snippet waits for the Nasal system to be initialized before the "loader" function gets called.
Then create another file containing:
# loadme.nas.txt
print("loadme.txt loaded");