Difference between revisions of "List cast"

From Second Life Wiki
Jump to navigation Jump to search
Line 4: Line 4:
//Extremely useful for feeding user data into llSetPrimitiveParams
//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
//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, Commissioned by WarKirby Magojiro, this function is Public Domain
list list_cast(list in)
list list_cast(list in)
{
{

Revision as of 08:16, 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, Commissioned by WarKirby Magojiro, this function 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.