Difference between revisions of "ListCast"

From Second Life Wiki
Jump to navigation Jump to search
(New page: {{LSL_Function |func=listCast |func_desc=Iterates through the contents of a list, producing a resulting list whose contents are cast to a single type. Please refer to [[LlGetListEntryType|...)
 
Line 5: Line 5:
|return_text=A list whose contents are all one type.
|return_text=A list whose contents are all one type.
|p1_type=list|p1_name=mixedList|p1_desc=The list to cast, its contents may be anything.
|p1_type=list|p1_name=mixedList|p1_desc=The list to cast, its contents may be anything.
|p2_type=integer|p2_name=type|p2_desc=One of the TYPE_* variables, see [[LlGetListEntryType|llGetListEntryType()]] for more details.
|p2_type=integer|p2_name=type|p2_desc=One of the <code>TYPE_*</code> variables, see [[LlGetListEntryType|llGetListEntryType()]] for more details.
|mode=user
|mode=user
|cat1=Examples
|cat1=Examples

Revision as of 18:17, 17 January 2009

Summary

Function: list listCast( list mixedList, integer <span title="One of the TYPE_* variables, see llGetListEntryType() for more details." style="border-bottom:1px dotted; cursor:help;">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 One of the TYPE_* variables, see llGetListEntryType() for more details.

Examples

Implementation

<lsl>list listCast(list mixedList, integer type) {

   list result = []; integer x = mixedList != [];
   if (type == TYPE_INTEGER) 
       while ((--x) >= 0) 
           result = (result = []) + [llList2Integer(mixedList, x)] + result;
   else if (type == TYPE_FLOAT) 
       while ((--x) >= 0) 
           result = (result = []) + [llList2Float(mixedList, x)] + result;
   else if (type == TYPE_VECTOR) 
       while ((--x) >= 0) 
           result = (result = []) + [(vector)llList2String(mixedList, x)] + result;
   else if (type == TYPE_ROTATION) 
       while ((--x) >= 0) 
           result = (result = []) + [(rotation)llList2String(mixedList, x)] + result;
   else if (type == TYPE_STRING) 
       while ((--x) >= 0) 
           result = (result = []) + [llList2String(mixedList, x)] + result;
   else if (type == TYPE_KEY) 
       while ((--x) >= 0) 
           result = (result = []) + [llList2Key(mixedList, x)] + result;
   else result = (mixedList = []) + mixedList;
   return (result = mixedList = []) + result;

}</lsl>