|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
11-27-2003 23:19
I think one thing that's really missing in the LSL list implimentation is a good llParseList2String() function. For that, we either have to loop through each element of our list and dump it into a string, or use llList2CSV(). The latter is unreliable, and the former is a hefty memory-consumer and can be *excruciatingly slow* for lists with significant length.
string llParseList2String(list src, string seperator);
//Basicly does the same thing as llParseString2List(), but backwards, parsing the given list back into a string with 'seperator' seperating each element.
==Chris
|
|
Gaudeon Wu
Hermit
Join date: 5 May 2003
Posts: 142
|
11-27-2003 23:48
Remeber back in June when we were talking about this  I bumped that thread I wonder if two threads will be more effective then one was lmao  I guess it's more of a convenience then anything but it would be nice to have  Anyway, I wanted it then and it still would be nice to have so... seconded 
|
|
ZHugh Becquerel
Registered User
Join date: 24 Oct 2003
Posts: 68
|
11-29-2003 01:18
list mylist;
mylist = FillList();
llWhisper(0, (string)mylist );
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
11-30-2003 11:43
Thats good when you want to get debug Zhugh, but that just mushes elements together, not good for transferring a list between two objects using an llSay, or between two scripts using a linkmessage. llList2CSV() is also a bit flimsy... it adds spaces where you think there shouldnt be.
|
|
Xylor Baysklef
Scripting Addict
Join date: 4 May 2003
Posts: 109
|
11-30-2003 15:38
I use these when I need to keep type info to pass lists using llSay, llMessageLinked, etc: //////////////////////////////////////////// // ListToString and StringToList Script // // Written by Xylor Baysklef ////////////////////////////////////////////
/////////////// CONSTANTS /////////////////// // This is the seperator to use instead of // a comma. string FIELD_SEPERATOR = "~!~"; ///////////// END CONSTANTS /////////////////
///////////// GLOBAL VARIABLES /////////////// /////////// END GLOBAL VARIABLES /////////////
// This function converts a list of data into // a string with a seperator between each value. string ListToString(list data, string seperator) { integer Length = llGetListLength(data); // Just return an empty string if the list is empty. if (Length == 0) return ""; string Result; integer i; integer Type; // Loop through all but the last entry. for (i = 0; i < Length - 1; i++) { Type = llGetListEntryType(data, i); Result += (string) Type + seperator + llList2String(data, i) + seperator; } // Add the last entry, without a seperator at the end. Type = llGetListEntryType(data, -1); Result += (string) Type + seperator + llList2String(data, -1); return Result; }
// This function turns a string into a list, using a // field seperator. It assumes the string was produced // by the function ListToString. list StringToList(string data, string FIELD_SEPERATOR) { list Result; // First split up the string using the field seperator. list Parsed = llParseString2List(data, [FIELD_SEPERATOR], []); integer Length = llGetListLength(Parsed); // Make sure the list is of even length. if (Length % 2 != 0) { llSay(0, "StringToList::Invalid String"); return; } // Loop through the list, two at a time. The first // entry of each pair is the type, the second is the value. integer i; for (i = 0; i < Length; i += 2) { integer Type = (integer) llList2String(Parsed, i); string Value = llList2String(Parsed, i + 1); if (Type == TYPE_INTEGER) { Result += (integer) Value; } else if (Type == TYPE_FLOAT) { Result += (float) Value; } else if (Type == TYPE_VECTOR) { Result += (vector) Value; } else if (Type == TYPE_ROTATION) { Result += (rotation)Value; } else if (Type == TYPE_KEY) { Result += (key) Value; } else // TYPE_STRING Result += Value; } return Result; }
default { state_entry() { list Source = ["ABC", 1.0, 128, <1, 1, 1>, ZERO_ROTATION]; string Packet = ListToString(Source, FIELD_SEPERATOR); list Dest = StringToList(Packet, FIELD_SEPERATOR); llSay(0, "Source: " + llList2CSV(Source)); llSay(0, "Packet: " + Packet); llSay(0, "Dest: " + llList2CSV(Dest)); } }
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
11-30-2003 17:22
:  igh:: I dont think you two get the picture Looping over every element in a list is a chore for the script, for my current project, its the biggest bottleneck. It eventually takes > 3 seconds to parse the list, causing mass hysteria umong people like me, who like things done as fast as possible.
|