1,376
edits
(→sort()) |
No edit summary |
||
| Line 16: | Line 16: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = append(vector, element[, element[, ...]]); | |syntax = append(vector, element[, element[, ...]]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=45|t=Source}} | ||
|text = This function appends, or adds, the given element(s) to the end of the vector given in the first argument. Returns the vector operated on. | |text = This function appends, or adds, the given element(s) to the end of the vector given in the first argument. Returns the vector operated on. | ||
|param1 = vector | |param1 = vector | ||
| Line 35: | Line 35: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = bind(function, locals[, outer_scope]); | |syntax = bind(function, locals[, outer_scope]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=638|t=Source}} | ||
|text = This creates a new function object. A function in Nasal is three things: the actual code, a hash/namespace of local variables available to the function namespace, and the closure object of that namespace. These correspond to the three arguments respectively. | |text = This creates a new function object. A function in Nasal is three things: the actual code, a hash/namespace of local variables available to the function namespace, and the closure object of that namespace. These correspond to the three arguments respectively. | ||
|param1 = function | |param1 = function | ||
| Line 78: | Line 78: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = call(func[, args[, me[, locals[, error]]]); | |syntax = call(func[, args[, me[, locals[, error]]]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=376|t=Source}} | ||
|text = Calls the given function with the given arguments and returns the result. This function is very useful as it allows much more control over function calls and catches any errors or {{func link|die()}} calls that would normally trigger run-time errors cancelling execution of the script otherwise. | |text = Calls the given function with the given arguments and returns the result. This function is very useful as it allows much more control over function calls and catches any errors or {{func link|die()}} calls that would normally trigger run-time errors cancelling execution of the script otherwise. | ||
|param1 = func | |param1 = func | ||
| Line 141: | Line 141: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = caller([level]); | |syntax = caller([level]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=540|t=Source}} | ||
|text = Returns a vector containing a record from the current call stack. The level numbering starts from the currently executing function (level 0). Level 1 (the default) is the caller of the current function, and so on. | |text = Returns a vector containing a record from the current call stack. The level numbering starts from the currently executing function (level 0). Level 1 (the default) is the caller of the current function, and so on. | ||
| Line 192: | Line 192: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = chr(code); | |syntax = chr(code); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=240|t=Source}} | ||
|text = Returns a character as per the single argument. Extended ASCII is supported (see http://www.asciitable.com/ for a list of supported characters), although this may vary between different systems. For a list of the most commonly used characters, see the {{wikipedia|ASCII#ASCII printable code chart|ASCII printable code chart}} ('''Dec''' column). The following table lists supported control characters, along with their equivalent control characters in Nasal strings. {{Note|In Nasal, only strings enclosed with double-quotes (<code>"string"</code>) supports control chracters. Strings in single quotes (<code>'string'</code>) do not.}} | |text = Returns a character as per the single argument. Extended ASCII is supported (see http://www.asciitable.com/ for a list of supported characters), although this may vary between different systems. For a list of the most commonly used characters, see the {{wikipedia|ASCII#ASCII printable code chart|ASCII printable code chart}} ('''Dec''' column). The following table lists supported control characters, along with their equivalent control characters in Nasal strings. {{Note|In Nasal, only strings enclosed with double-quotes (<code>"string"</code>) supports control chracters. Strings in single quotes (<code>'string'</code>) do not.}} | ||
{{{!}} class="wikitable" | {{{!}} class="wikitable" | ||
| Line 216: | Line 216: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = closure(func[, level]); | |syntax = closure(func[, level]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=557|t=Source}} | ||
|text = Returns the hash table containing the lexical namespace of the given function. The level numbering start with level 0 being the namespace of '''func'''. | |text = Returns the hash table containing the lexical namespace of the given function. The level numbering start with level 0 being the namespace of '''func'''. | ||
|param1 = func | |param1 = func | ||
| Line 236: | Line 236: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = cmp(a, b); | |syntax = cmp(a, b); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=169|t=Source}} | ||
|text = Compares two strings, returning -1 if '''a''' is less than '''b''', 0 if they are identical and 1 if '''a''' is greater than '''b'''. | |text = Compares two strings, returning -1 if '''a''' is less than '''b''', 0 if they are identical and 1 if '''a''' is greater than '''b'''. | ||
|param1 = a | |param1 = a | ||
| Line 251: | Line 251: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = compile(code[, filename]); | |syntax = compile(code[, filename]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=349|t=Source}} | ||
|text = Compiles the specified code string and returns a function object bound to the current lexical context. If there is an error, the function dies, with the argument to {{func link|die()}} being '''filename'''. | |text = Compiles the specified code string and returns a function object bound to the current lexical context. If there is an error, the function dies, with the argument to {{func link|die()}} being '''filename'''. | ||
|param1 = code | |param1 = code | ||
| Line 310: | Line 310: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = contains(hash, key); | |syntax = contains(hash, key); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=249|t=Source}} | ||
|text = Returns 1 (True) if the hash contains the specified key, or 0 (False) if not. | |text = Returns 1 (True) if the hash contains the specified key, or 0 (False) if not. | ||
|param1 = hash | |param1 = hash | ||
| Line 330: | Line 330: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = contains(vector, item); | |syntax = contains(vector, item); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=249|t=Source}} | ||
|text = Returns 1 (True) if the vector contains the specified item, or 0 (False) if not. | |text = Returns 1 (True) if the vector contains the specified item, or 0 (False) if not. | ||
|param1 = vector | |param1 = vector | ||
| Line 346: | Line 346: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = delete(hash, key); | |syntax = delete(hash, key); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=118|t=Source}} | ||
|text = Deletes the key from the hash if it exists. Operationally, this is NOT identical to setting the hash value specified by the key to <code>'''nil'''</code> as the key will stay in the hash (at least for a while). This variant potentially frees storage by deleting the reference to the key and by shrinking the hash. Returns the hash that has been operated on. | |text = Deletes the key from the hash if it exists. Operationally, this is NOT identical to setting the hash value specified by the key to <code>'''nil'''</code> as the key will stay in the hash (at least for a while). This variant potentially frees storage by deleting the reference to the key and by shrinking the hash. Returns the hash that has been operated on. | ||
|param1 = hash | |param1 = hash | ||
| Line 365: | Line 365: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = die(error); | |syntax = die(error); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=417|t=Source}} | ||
|text = Terminates execution and unwinds the stack. The place and the line will be added to the '''error'''. This invokes the same internal exception handler used for internal runtime errors. Use this to signal fatal errors, or to implement exception handling. The error thrown (including internal runtime errors) can be caught with {{func link|call()}}. | |text = Terminates execution and unwinds the stack. The place and the line will be added to the '''error'''. This invokes the same internal exception handler used for internal runtime errors. Use this to signal fatal errors, or to implement exception handling. The error thrown (including internal runtime errors) can be caught with {{func link|call()}}. | ||
|param1 = error | |param1 = error | ||
| Line 379: | Line 379: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = find(needle, haystack); | |syntax = find(needle, haystack); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=586|t=Source}} | ||
|text = Finds and returns the index of the first occurrence of the string '''needle''' in the string '''haystack''', or -1 if no such occurrence was found. | |text = Finds and returns the index of the first occurrence of the string '''needle''' in the string '''haystack''', or -1 if no such occurrence was found. | ||
|param1 = needle | |param1 = needle | ||
| Line 393: | Line 393: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = ghosttype(ghost); | |syntax = ghosttype(ghost); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=336|t=Source}} | ||
|text = Returns a string containing either a descriptive name of a ghost (a raw C/C++ object), or a unique id (the pointer to the C/C++ <code>naGhostType</code> instance) if no name has been set. Ghost is an acronym that stands for '''G'''arbage-collected '''H'''andle to '''O'''ut'''S'''ide '''T'''hingy. | |text = Returns a string containing either a descriptive name of a ghost (a raw C/C++ object), or a unique id (the pointer to the C/C++ <code>naGhostType</code> instance) if no name has been set. Ghost is an acronym that stands for '''G'''arbage-collected '''H'''andle to '''O'''ut'''S'''ide '''T'''hingy. | ||
|param1 = ghost | |param1 = ghost | ||
| Line 403: | Line 403: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = id(object); | |syntax = id(object); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=706|t=Source}} | ||
|text = Returns a string containing information on the type and ID of the object provided in the single argument. The information is returned in the form of <code>'''<type>''':'''<id>'''</code>, where '''<type>''' is the type of object, and '''<id>''' is the ID. | |text = Returns a string containing information on the type and ID of the object provided in the single argument. The information is returned in the form of <code>'''<type>''':'''<id>'''</code>, where '''<type>''' is the type of object, and '''<id>''' is the ID. | ||
|param1 = object | |param1 = object | ||
| Line 413: | Line 413: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = int(number); | |syntax = int(number); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=125|t=Source}} | ||
|text = Returns the integer part of the numeric value of the single argument, or <code>'''nil'''</code> if none exists. | |text = Returns the integer part of the numeric value of the single argument, or <code>'''nil'''</code> if none exists. | ||
|param1 = number | |param1 = number | ||
| Line 425: | Line 425: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = keys(hash); | |syntax = keys(hash); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=36|t=Source}} | ||
|text = Returns a vector containing the list of keys found in the single hash argument. | |text = Returns a vector containing the list of keys found in the single hash argument. | ||
|param1 = hash | |param1 = hash | ||
| Line 441: | Line 441: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = left(string, length); | |syntax = left(string, length); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=214|t=Source}} | ||
|version = 2.12 | |version = 2.12 | ||
|commit = {{simgear commit|bd7163|t=commit}} | |commit = {{simgear commit|bd7163|t=commit}} | ||
| Line 455: | Line 455: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = num(number); | |syntax = num(number); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=149|t=Source}} | ||
|text = Returns the numerical value of the single string argument, or <code>'''nil'''</code> if none exists. | |text = Returns the numerical value of the single string argument, or <code>'''nil'''</code> if none exists. | ||
|param1 = number | |param1 = number | ||
| Line 467: | Line 467: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = pop(vector); | |syntax = pop(vector); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=85|t=Source}} | ||
|text = Removes and returns the last element of the single vector argument, or <code>'''nil'''</code> if the vector is empty. | |text = Removes and returns the last element of the single vector argument, or <code>'''nil'''</code> if the vector is empty. | ||
|param1 = vector | |param1 = vector | ||
| Line 486: | Line 486: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = range([start, ]stop[, step]); | |syntax = range([start, ]stop[, step]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=756|t=Source}} | ||
|text = Creates a vector of numbers starting from <code>start</code> (default 0) up to but not including <code>stop</code>, incremented by <code>step</code> (default 1). Note: To specify <code>step</code>, you must also provide <code>start</code>; otherwise the second argument is interpreted as <code>stop</code>. | |text = Creates a vector of numbers starting from <code>start</code> (default 0) up to but not including <code>stop</code>, incremented by <code>step</code> (default 1). Note: To specify <code>step</code>, you must also provide <code>start</code>; otherwise the second argument is interpreted as <code>stop</code>. | ||
|param1 = start | |param1 = start | ||
| Line 524: | Line 524: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = removeat(vector, index); | |syntax = removeat(vector, index); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=72|t=Source}} | ||
|text = Removes the element at the specified index from the vector and returns it. | |text = Removes the element at the specified index from the vector and returns it. | ||
|param1 = vector | |param1 = vector | ||
| Line 539: | Line 539: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = right(string, length); | |syntax = right(string, length); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=226|t=Source}} | ||
|version = 2.12 | |version = 2.12 | ||
|commit = {{simgear commit|bd7163|t=commit}} | |commit = {{simgear commit|bd7163|t=commit}} | ||
| Line 553: | Line 553: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = setsize(vector, size); | |syntax = setsize(vector, size); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=91|t=Source}} | ||
|text = Sets the size of a vector. The first argument specifies a vector, the second a number representing the desired size of that vector. If the vector is currently larger than the specified size, it is truncated. If it is smaller, it is padded with <code>'''nil'''</code> entries. Returns the vector operated upon. | |text = Sets the size of a vector. The first argument specifies a vector, the second a number representing the desired size of that vector. If the vector is currently larger than the specified size, it is truncated. If it is smaller, it is padded with <code>'''nil'''</code> entries. Returns the vector operated upon. | ||
|param1 = vector | |param1 = vector | ||
| Line 572: | Line 572: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = size(object); | |syntax = size(object); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=26|t=Source}} | ||
|text = Returns the size of the single argument. For strings, this is the length in bytes. For vectors, this is the number of elements. For hashes, it is the number of key/value pairs. If the argument is <code>'''nil'''</code> or a number, this error will be thrown: <code>object has no size()</code>. | |text = Returns the size of the single argument. For strings, this is the length in bytes. For vectors, this is the number of elements. For hashes, it is the number of key/value pairs. If the argument is <code>'''nil'''</code> or a number, this error will be thrown: <code>object has no size()</code>. | ||
|param1 = object | |param1 = object | ||
| Line 594: | Line 594: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = sort(vector, function); | |syntax = sort(vector, function); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=678|t=Source}} | ||
|text = Returns a vector containing the elements in the input '''vector''' sorted in according to the rule given by '''function'''. Implemented with the ANSI C {{func link|qsort()|link=http://www.cplusplus.com/reference/cstdlib/qsort/}}, <code>sort()</code> is stable. This means that if the rules in the first example are used, equal elements in the output vector will appear in the same relative order as they do in the input. It is run in a loop, so '''function''' is run several times. | |text = Returns a vector containing the elements in the input '''vector''' sorted in according to the rule given by '''function'''. Implemented with the ANSI C {{func link|qsort()|link=http://www.cplusplus.com/reference/cstdlib/qsort/}}, <code>sort()</code> is stable. This means that if the rules in the first example are used, equal elements in the output vector will appear in the same relative order as they do in the input. It is run in a loop, so '''function''' is run several times. | ||
|param1 = vector | |param1 = vector | ||
| Line 645: | Line 645: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = split(delimiter, string); | |syntax = split(delimiter, string); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=596|t=Source}} | ||
|text = Splits the input string into a vector of substrings bounded by occurrences of the delimiter substring. See [[Nasal_library/string#string.join(sep,list)|string.join()]]. | |text = Splits the input string into a vector of substrings bounded by occurrences of the delimiter substring. See [[Nasal_library/string#string.join(sep,list)|string.join()]]. | ||
|param1 = delimiter | |param1 = delimiter | ||
| Line 659: | Line 659: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = <nowiki>sprintf(format[, arg[, arg, [...]]]);</nowiki> | |syntax = <nowiki>sprintf(format[, arg[, arg, [...]]]);</nowiki> | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=491|t=Source}} | ||
|text = Creates and returns a string formatted using ANSI C {{func link|vsnprintf()|link=http://en.cppreference.com/w/c/io/vfprintf}} <ref> | |text = Creates and returns a string formatted using ANSI C {{func link|vsnprintf()|link=http://en.cppreference.com/w/c/io/vfprintf}} <ref> | ||
{{Cite web | {{Cite web | ||
| Line 758: | Line 758: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = streq(a, b); | |syntax = streq(a, b); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=164|t=Source}} | ||
|text = Tests the string values of the two arguments for equality. This function is needed because the <code>'''=='''</code> operator (see [[Nasal_Operators#Equality|Nasal Operators]]) tests for numeric equality first. If either or both the arguments are not strings, 0 (False) will be returned. Returns either 0 (False) or 1 (True). {{Note|This function is rarely required in typical code.}} | |text = Tests the string values of the two arguments for equality. This function is needed because the <code>'''=='''</code> operator (see [[Nasal_Operators#Equality|Nasal Operators]]) tests for numeric equality first. If either or both the arguments are not strings, 0 (False) will be returned. Returns either 0 (False) or 1 (True). {{Note|This function is rarely required in typical code.}} | ||
|param1 = a | |param1 = a | ||
| Line 773: | Line 773: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = substr(string, start [, length]); | |syntax = substr(string, start [, length]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=194|t=Source}} | ||
|text = Similar the {{func link|subvec()}}, but operates on strings. Computes and returns a substring. The first argument specifies a string, the second is the index of the start of a substring, the optional third argument specifies a length (the default is to return the rest of the string from the start). | |text = Similar the {{func link|subvec()}}, but operates on strings. Computes and returns a substring. The first argument specifies a string, the second is the index of the start of a substring, the optional third argument specifies a length (the default is to return the rest of the string from the start). | ||
|param1 = string | |param1 = string | ||
| Line 791: | Line 791: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = subvec(vector, start[, length]); | |syntax = subvec(vector, start[, length]); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=98|t=Source}} | ||
|text = Returns a sub-range of a vector. The first argument specifies a vector, the second a starting index, and the optional third argument indicates a length (the default is to the end of the vector). | |text = Returns a sub-range of a vector. The first argument specifies a vector, the second a starting index, and the optional third argument indicates a length (the default is to the end of the vector). | ||
|param1 = vector | |param1 = vector | ||
| Line 818: | Line 818: | ||
{{Nasal doc | {{Nasal doc | ||
|syntax = typeof(object); | |syntax = typeof(object); | ||
|source = {{simgear file|simgear/nasal/lib.c|l= | |source = {{simgear file|simgear/nasal/lib.c|l=287|t=Source}} | ||
|text = Returns a string indicating the whether the object is <code>'''nil'''</code>, a scalar (number or string), a vector, a hash, a function, or a ghost. | |text = Returns a string indicating the whether the object is <code>'''nil'''</code>, a scalar (number or string), a vector, a hash, a function, or a ghost. | ||
|param1 = object | |param1 = object | ||
edits