Nasal library functions: Difference between revisions
Line 107: | Line 107: | ||
Example: | Example: | ||
<syntaxhighlight lang="nasal" enclose="div"> | <syntaxhighlight lang="nasal" enclose="div"> | ||
floor(1.2); # returns 1 | math.floor(1.2); # returns 1 | ||
floor(1.6); # returns 1 | math.floor(1.6); # returns 1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 06:43, 29 May 2015
The FlightGear forum has a subforum related to: Nasal Scripting |
Nasal scripting |
---|
Nasal internals |
---|
Memory Management (GC) |
Please first see: http://plausible.org/nasal/lib.html
size()
keys()
append()
pop()
setsize()
subvec()
Extract items of a vector (equivalent to the left() function for a string) Example :
var currentPath = "/home/xxx/yyy/";
print (directory(currentPath));
returns : ".", "..", "file1", "file2", "file3"
and :
var currentPath = "/home/xxx/yyy/";
print (subvec(directory(currentPath),2));
returns : "file1", "file2", "file3"
var currentPath = "/home/xxx/yyy/";
print (subvec(directory(currentPath),3));
returns : "file2", "file3"
delete()
int()
num(str)
Convert string to number. Returns nil if str is nil, empty string, string with no number.
streq()
cmp()
substr()
chr()
contains()
typeof()
ghosttype(ghost)
Returns a string containing either a descriptive name as passed to naNewGhost or naNewGhost2 in C/C++ while creating the ghost or a unique id (aka the pointer to the C/C++ naGhostType instance) if no name has been set.
compile()
call()
die()
sprintf()
caller()
closure()
find()
split()
rand()
bind()
sort()
id()
math
Trigonometric_functions
Caution: All trigonometric functions works with Radian-values - not with Degree!
To convert this:
radians = degree * math.pi / 180
degree = radians * 180 / math.pi
sin()
cos()
tan()
asin()
acos()
atan2()
exp()
ln()
pow()
sqrt()
floor()
Returns the value rounded downward
Example:
math.floor(1.2); # returns 1
math.floor(1.6); # returns 1
ceil()
fmod()
A modulo-operator, mod(x,y) also works...
The modulo-operation finds the remainder of division of one number by another (sometimes called modulus).
clamp()
periodic()
round()
pi
e
io
- SEEK_SET
- SEEK_CUR
- SEEK_END
- stdin
- stdout
- stderr
stat()
directory()
returns the files in a given directory
e.g. chatter_list = directory( chatter_dir );
Example :
var currentPath = "/home/xxx/yyy/";
print (directory(currentPath));
returns :
- "."
- ".."
- "file1"
- "file2"
- "file3"
To delete the "." and ".." see the subvec() function.