Nasal scripting language
| The FlightGear forum has a subforum related to: Nasal Scripting |
| Nasal scripting |
|---|
| Nasal internals |
|---|
| Memory Management (GC) |
Nasal is FlightGear's built-in scripting language, standing for "not another scripting language". Originally written and developed by Andy Ross for a personal project, it was integrated into FlightGear in November 2003, and has been continuously developed, improved, and refined since then. Over time, it has become probably FlightGear's most powerful, and has been used to create a huge variety of systems, ranging from wildfires to Control Display Units.
Nasal uses some of the concepts of ECMA/JavaScript, Python and Perl and implements a simple but complete way of Object Oriented Programming (OOP). It supports the reading and writing of internal properties, accessing internal data via extension functions, creating GUI dialogs and much more within FlightGear.
Please see the right navigation bar "Nasal scripting" to get more information and tutorials about Nasal itself.
Features
Design
- Designed as an extension language, well suited for embedded applications
- Small Interpreter, written in ANSI C, even smaller than lua
- Nasal's VM uses internally a stack machine model and is stackless for interpreted code
- Nasal provides optional bindings for libraries such as gtk, cairo, regex, readline, sqlite or unix, and does not depend on any third party libraries other than the standard C library
- Nasal is threadsafe and does not use a global interpreter lock (i.e. GIL/GVL in Python or Ruby)
- Metaprogramming and Unicode support
- Support for multiple execution contexts and subcontexts
Getting started
First Nasal script
A Hello World example:
# to be saved in $FG_ROOT/Nasal/hello.nas
print("Hello World!");Fibonacci
An example of calculating fib(10000000) % 16777216:
var fibonacci = func(n) {
if (n == 0) return 0;
if (n == 1) return 1;
var a = 0;
var b = 1;
for (var i = 2; i <= n; i += 1) {
(a, b) = (b, (a + b) & 16777215)
}
return b;
};
var n = 10000000;
var start = systime();
var result = fibonacci(n);
var end = systime();
var elapsed = end - start;
print("Fibonacci(", n, ") mod 16777216 = ", result);
print("Time elapsed: ", elapsed, " seconds");Writing simple scripts
|
|
Syntax
Variables and operators
See Nasal Variables and Nasal Operators for more info.
Conditionals and loops
See Nasal Conditionals and Nasal Loops.
Functions
|
|
Objects
|
|
Namespaces
|
|
Library
See the navigation bar "Nasal scripting" for more info.