User:Pedro Oval/Table of implicit type conversions for list extracting functions

From Second Life Wiki
< User:Pedro Oval
Revision as of 09:42, 30 October 2011 by Pedro Oval (talk | contribs) (Add test code for review)
Jump to navigation Jump to search

This table tells whether an implicit type cast is supported by llList2* depending on the item type in the list. Last tested with this server version: Second Life Server 11.10.18.243270


List item type:
Function:
string key integer float vector rotation
llList2String YES YES YES YES YES YES
llList2Key YES YES no no no no
llList2Integer YES no YES YES no no
llList2Float YES no YES YES no no
llList2Vector no no no no YES no
llList2Rot no no no no no YES

The non-supported conversions for llList2Key return (key)"".

The non-supported conversions for llList2Integer return 0.

The non-supported conversions for llList2Float return 0.0.

The non-supported conversions for llList2Vector return ZERO_VECTOR.

The non-supported conversions for llList2Rot return ZERO_ROTATION.

In short: llList2String can be applied to all types. A string element can be extracted by all functions except llList2Vector and llList2Rot. integer and float are interchangeable. No other implicit conversions are supported.

Test code

Here's the program used to elaborate the above table:

<lsl> string CheckResults(integer ExpectedYes, integer ExpectedNo) {

   if (ExpectedYes && ExpectedNo)
   {
       // Inconsistent check - revise code
       return "*INCONSISTENT*";
   }
   if (!ExpectedYes && !ExpectedNo)
   {
       // Neither of the checks is met
       return "*UNEXPECTED*";
   }
   if (ExpectedYes)
       return " YES";
   return "  no ";

}

string v2s(vector v) {

   return "<"+(string)v.x+", "+(string)v.y+", "+(string)v.z+">";

}

string r2s(rotation r) {

   return "<"+(string)r.x+", "+(string)r.y+", "+(string)r.z+", "+(string)r.s+">";

}

default {

   state_entry()
   {
       string line;
       string s;
       key k;
       integer i;
       float f;
       vector v;
       rotation r;
       
       line = "llList2String ";
       s = "¡!¿?";
       k = (key)"01234567-89ab-cdef-0123-456789abcdef";
       i = -314159;
       f = -3.141592e33;
       v = <-1.22, 0.0, 9.9e9>;
       r = <0.33, 0.66, 0.33, 0.589>;
       line += CheckResults(llList2String([s], 0) == s,         llList2String([s], 0) == "");
       line += CheckResults(llList2String([k], 0) == (string)k, llList2String([k], 0) == "");
       line += CheckResults(llList2String([i], 0) == (string)i, llList2String([i], 0) == "");
       line += CheckResults(llList2String([f], 0) == (string)f, llList2String([f], 0) == "");
       // we can't compare to (string)v because (string)v returns 5 decimals per component instead of the usual 6
       line += CheckResults(llList2String([v], 0) == v2s(v),    llList2String([v], 0) == "");
       // same caveat as above
       line += CheckResults(llList2String([r], 0) == r2s(r),    llList2String([r], 0) == "");
       llOwnerSay(line);
       
       line = "llList2Key ";
       line += CheckResults(llList2Key([s], 0) == (key)s,           llList2Key([s], 0) == (key)"");
       line += CheckResults(llList2Key([k], 0) == k,                llList2Key([k], 0) == (key)"");
       line += CheckResults(llList2Key([i], 0) == (key)((string)i), llList2Key([i], 0) == (key)"");
       line += CheckResults(llList2Key([f], 0) == (key)((string)f), llList2Key([f], 0) == (key)"");
       line += CheckResults(llList2Key([v], 0) == (key)v2s(v),      llList2Key([v], 0) == (key)"");
       line += CheckResults(llList2Key([r], 0) == (key)r2s(r),      llList2Key([r], 0) == (key)"");
       llOwnerSay(line);
       
       line = "llList2Integer ";
       s = "234";
       k = (key)"234";
       i = 234;
       f = 234.1;
       v = <234.0, 30.0, 20.0>;
       r = <1.0, 1.0, 1.0, 1.0>;
       line += CheckResults(llList2Integer([s], 0) == (integer)s,           llList2Integer([s], 0) == 0);
       line += CheckResults(llList2Integer([k], 0) == (integer)((string)k), llList2Integer([k], 0) == 0);
       line += CheckResults(llList2Integer([i], 0) == i,                    llList2Integer([i], 0) == 0);
       line += CheckResults(llList2Integer([f], 0) == (integer)f,           llList2Integer([f], 0) == 0);
       line += CheckResults(llList2Integer([v], 0) == (integer)v.x,         llList2Integer([v], 0) == 0);
       line += CheckResults(llList2Integer([r], 0) == (integer)r.x,         llList2Integer([r], 0) == 0);
       llOwnerSay(line);
       line = "llList2Float ";
       s = "234.1";
       k = (key)"234.1";
       i = 234;
       f = 234.1;
       v = <234.1, 30.0, 20.0>;
       r = <0.33, 0.66, 0.33, 0.589>;
       line += CheckResults(llList2Float([s], 0) == (float)s,           llList2Float([s], 0) == 0.0);
       line += CheckResults(llList2Float([k], 0) == (float)((string)k), llList2Float([k], 0) == 0.0);
       line += CheckResults(llList2Float([i], 0) == (float)i,           llList2Float([i], 0) == 0.0);
       line += CheckResults(llList2Float([f], 0) == f,                  llList2Float([f], 0) == 0.0);
       line += CheckResults(llList2Float([v], 0) == v.x,                llList2Float([v], 0) == 0.0);
       line += CheckResults(llList2Float([r], 0) == r.x,                llList2Float([r], 0) == 0.0);
       llOwnerSay(line);
       
       line = "llList2Vector ";
       s = "<1.3, 1.4, 1.5>";
       k = (key)s;
       line += CheckResults(llList2Vector([s], 0) == (vector)s,           llList2Vector([s], 0) == ZERO_VECTOR);
       line += CheckResults(llList2Vector([k], 0) == (vector)((string)k), llList2Vector([k], 0) == ZERO_VECTOR);
       line += CheckResults(llList2Vector([i], 0) == <i, 0, 0>,           llList2Vector([i], 0) == ZERO_VECTOR);
       line += CheckResults(llList2Vector([f], 0) == <f, 0, 0>,           llList2Vector([f], 0) == ZERO_VECTOR);
       line += CheckResults(llList2Vector([v], 0) == v,                   llList2Vector([v], 0) == ZERO_VECTOR);
       line += CheckResults(llList2Vector([r], 0) == <r.x,r.y,r.z>,       llList2Vector([r], 0) == ZERO_VECTOR);
       llOwnerSay(line);
       
       line = "llList2Rot ";
       s = "<1.3, 1.4, 1.5, 1.6>";
       k = (key)s;
       line += CheckResults(llList2Rot([s], 0) == (rotation)s,           llList2Rot([s], 0) == ZERO_ROTATION);
       line += CheckResults(llList2Rot([k], 0) == (rotation)((string)k), llList2Rot([k], 0) == ZERO_ROTATION);
       line += CheckResults(llList2Rot([i], 0) == <i, 0, 0, 0>,          llList2Rot([i], 0) == ZERO_ROTATION);
       line += CheckResults(llList2Rot([f], 0) == <f, 0, 0, 0>,          llList2Rot([f], 0) == ZERO_ROTATION);
       line += CheckResults(llList2Rot([v], 0) == <v.x, v.y, v.z, 0>,    llList2Rot([v], 0) == ZERO_ROTATION);
       line += CheckResults(llList2Rot([r], 0) == r,                     llList2Rot([r], 0) == ZERO_ROTATION);
       llOwnerSay(line);
   }

} </lsl>