Difference between revisions of "List cast"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with '=== List Cast === <lsl> //This function typecasts a list of strings, into the types they appear to be. Extremely useful for feeding user data into llSetPrimitiveParams //Written ...')
 
Line 1: Line 1:
=== List Cast ===
=== List Cast ===
<lsl>
<lsl>
//This function typecasts a list of strings, into the types they appear to be. Extremely useful for feeding user data into llSetPrimitiveParams
//This function typecasts a list of strings, into the types they appear to be.  
//Extremely useful for feeding user data into llSetPrimitiveParams
//It takes a list as an input, and returns that list, with all elements correctly typecast, as output
//Written by Fractured Crystal, 27 Jan 2010, this script is Public Domain
//Written by Fractured Crystal, 27 Jan 2010, this script is Public Domain
list fix(list in)
list list_cast(list in)
{
{
     list out;
     list out;
Line 55: Line 57:
}
}
</lsl>
</lsl>
=== Caveats ===
*Any strings fed into this function (which are meant to stay strings) cannot contain pointed brackets (<>) They will be cast as vectors or rotations, if they do.

Revision as of 09:12, 28 January 2010

List Cast

<lsl> //This function typecasts a list of strings, into the types they appear to be. //Extremely useful for feeding user data into llSetPrimitiveParams //It takes a list as an input, and returns that list, with all elements correctly typecast, as output //Written by Fractured Crystal, 27 Jan 2010, this script is Public Domain list list_cast(list in) {

   list out;
   integer i = 0;
   integer l= llGetListLength(in);
   while(i < l)
   {
       string d= llStringTrim(llList2String(in,i),STRING_TRIM);
       if(d == "")out += "";
       else
       {
           if(llGetSubString(d,0,0) == "<")
           {
               if(llGetSubString(d,-1,-1) == ">")
               {
                   list s = llParseString2List(d,[","],[]);
                   integer sl= llGetListLength(s);
                   if(sl == 3)
                   {
                       out += (vector)d;
                       //jump end;
                   }else if(sl == 4)
                   {
                       out += (rotation)d;
                       //jump end;
                   }
               }
               //either malformed,or identified
               jump end;
           }
           if(llSubStringIndex(d,".") != -1)
           {
               out += (float)d;
           }else
           {
               integer lold = (integer)d;
               if((string)lold == d)out += lold;
               else
               {
                   key kold = (key)d;
                   if(kold)out += [kold];
                   else out += [d];
               }
           }
       }
       @end;
       i += 1;
   }
   
   return out;

} </lsl>

Caveats

  • Any strings fed into this function (which are meant to stay strings) cannot contain pointed brackets (<>) They will be cast as vectors or rotations, if they do.