Difference between revisions of "ListCast"
Jump to navigation
Jump to search
Line 17: | Line 17: | ||
if (type == TYPE_INTEGER) | if (type == TYPE_INTEGER) | ||
while ((--x) >= 0) | while ((--x) >= 0) | ||
result = | result = [llList2Integer(mixedList, x)] + result; | ||
else if (type == TYPE_FLOAT) | else if (type == TYPE_FLOAT) | ||
while ((--x) >= 0) | while ((--x) >= 0) | ||
result = | result = [llList2Float(mixedList, x)] + result; | ||
else if (type == TYPE_VECTOR) | else if (type == TYPE_VECTOR) | ||
while ((--x) >= 0) | while ((--x) >= 0) | ||
result = | result = [(vector)llList2String(mixedList, x)] + result; | ||
else if (type == TYPE_ROTATION) | else if (type == TYPE_ROTATION) | ||
while ((--x) >= 0) | while ((--x) >= 0) | ||
result = | result = [(rotation)llList2String(mixedList, x)] + result; | ||
else if (type == TYPE_STRING) | else if (type == TYPE_STRING) | ||
while ((--x) >= 0) | while ((--x) >= 0) | ||
result = | result = [llList2String(mixedList, x)] + result; | ||
else if (type == TYPE_KEY) | else if (type == TYPE_KEY) | ||
while ((--x) >= 0) | while ((--x) >= 0) | ||
result = | result = [llList2Key(mixedList, x)] + result; | ||
else result = | else result = mixedList; | ||
return | return result; | ||
}</lsl> | }</lsl> | ||
{{LSLC|Examples}} | {{LSLC|Examples}} |
Revision as of 18:22, 17 January 2009
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: list listCast( list mixedList, integer type );
Iterates through the contents of a list, producing a resulting list whose contents are cast to a single type. Please refer to llGetListEntryType() for valid types. This function is useful for converting a list to a type which is more memory efficient, or to a type that you know you are going to access a lot (in order to remove extra casting later-on).
Returns a list A list whose contents are all one type.
• list | mixedList | – | The list to cast, its contents may be anything. | |
• integer | type | – | The type of variable to cast all entries to. |
Examples
Implementation
<lsl>list listCast(list mixedList, integer type) {
list result = []; integer x = mixedList != [];
if (type == TYPE_INTEGER) while ((--x) >= 0) result = [llList2Integer(mixedList, x)] + result; else if (type == TYPE_FLOAT) while ((--x) >= 0) result = [llList2Float(mixedList, x)] + result; else if (type == TYPE_VECTOR) while ((--x) >= 0) result = [(vector)llList2String(mixedList, x)] + result; else if (type == TYPE_ROTATION) while ((--x) >= 0) result = [(rotation)llList2String(mixedList, x)] + result; else if (type == TYPE_STRING) while ((--x) >= 0) result = [llList2String(mixedList, x)] + result; else if (type == TYPE_KEY) while ((--x) >= 0) result = [llList2Key(mixedList, x)] + result; else result = mixedList;
return result;
}</lsl>