Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Utility Pair_List_Parser  

Pair_List_Parser

Test Script

Category: Utility
By : kagefumi
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Pair_List_Parser
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Pair_List_Parser_1.lsl
Get file # 2. Pair_List_Parser_2.lsl
1 default
2 {
4 {
5 list pair_list = [];
6 pair_list = plSet(pair_list, ["aaa"], [1.23]);
7 pair_list = plSet(pair_list, ["bbb", "ccc"], [<1.11, 2.22, 3.33>, "hogehoge"]);
8 llSay(0, llDumpList2String(plGet(pair_list, ["aaa", "bbb"]), ","));
9 pair_list = plSet(pair_list, ["bbb"], ["piyopiyo"]);
10 llSay(0, llDumpList2String(pair_list, ","));
11 llSay(0, llDumpList2String(plKeys(pair_list), ","));
12 llSay(0, llDumpList2String(plValues(pair_list), ","));
13 }
14 }

Pair_List_Parser

The Main Script

Category: Utility
By : kagefumi
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

1 //===============================================
2 //
3 // Pair List.
4 //
5 // Example
6 // pair_list
7 // => ["MicroSoft", "Xbox360", "Sony", "PlayStation3"];
8 // plGet(pair_list, ["Sony"] );
9 // => ["PlayStation3"]
10 // plSet(pair_list, ["Apple"], ["iPhone"]);
11 // => ["MicroSoft", "Xbox360", "Sony", "PlayStation3", "Apple", "iPhone"]
12 // plKeys(pair_list);
13 // => ["MicroSoft", "Sony"]
14 // plValues(pair_list);
15 // => ["Xbox360", "PlayStation3"]
16 //
17 //===============================================
18
19 //
20 // Gets elements from pair list.
21 //
22 list plGet(list pair_list, list keys)
23 {
24 list results = [];
25 integer keys_length = llGetListLength(keys);
26 integer pair_list_length = llGetListLength(pair_list);
27 integer i;
28 for (i = 0; i < keys_length; i++)
29 {
30 string xkey = llList2String(keys, i);
31 integer key_index = llListFindList(pair_list, [xkey]);
32 if(0 <= key_index && key_index <pair_list_length - 1)
33 {
34 integer type = llGetListEntryType(pair_list, key_index + 1);
35 if(type == TYPE_FLOAT)
36 {
37 results += llList2Float(pair_list, key_index + 1);
38 }
39 else if(type == TYPE_INTEGER)
40 {
41 results += llList2Integer(pair_list, key_index + 1);
42 }
43 else if(type == TYPE_INVALID)
44 {
45 results += "???";
46 }
47 else if(type == TYPE_KEY)
48 {
49 results += llList2Key(pair_list, key_index + 1);
50 }
51 else if(type == TYPE_ROTATION)
52 {
53 results += llList2Rot(pair_list, key_index + 1);
54 }
55 else if(type == TYPE_STRING)
56 {
57 results += llList2String(pair_list, key_index + 1);
58 }
59 else if(type == TYPE_VECTOR)
60 {
61 results += llList2Vector(pair_list, key_index + 1);
62 }
63 else
64 {
65 }
66 }
67 else
68 {
69 llSay(DEBUG_CHANNEL, "Invalid element in " + llDumpList2String(pair_list, ","));
70 results += "???";
71 }
72 }
73 return results;
74 }
75
76 //
77 // Sets elements to pair list.
78 //
79 list plSet(list pair_list, list keys, list values)
80 {
81 integer keys_length = llGetListLength(keys);
82 integer values_length = llGetListLength(values);
83 integer i;
84 for (i = 0; (i < keys_length) && (i < values_length); i++)
85 {
86 string xkey = llList2String(keys, i);
87 integer index = llListFindList(pair_list, [xkey]);
88 integer type = llGetListEntryType(values, i);
89 if(0 <= index)
90 {
91 if(type == TYPE_FLOAT)
92 {
93 float value = llList2Float(values, i);
94 pair_list = llListReplaceList(pair_list, [value], index + 1, index + 1);
95 }
96 else if(type == TYPE_INTEGER)
97 {
98 integer value = llList2Integer(values, i);
99 pair_list = llListReplaceList(pair_list, [value], index + 1, index + 1);
100 }
101 else if(type == TYPE_INVALID)
102 {
103 }
104 else if(type == TYPE_KEY)
105 {
106 key value = llList2Key(values, i);
107 pair_list = llListReplaceList(pair_list, [value], index + 1, index + 1);
108 }
109 else if(type == TYPE_ROTATION)
110 {
111 rotation value = llList2Rot(values, i);
112 pair_list = llListReplaceList(pair_list, [value], index + 1, index + 1);
113 }
114 else if(type == TYPE_STRING)
115 {
116 string value = llList2String(values, i);
117 pair_list = llListReplaceList(pair_list, [value], index + 1, index + 1);
118 }
119 else if(type == TYPE_VECTOR)
120 {
121 vector value = llList2Vector(values, i);
122 pair_list = llListReplaceList(pair_list, [value], index + 1, index + 1);
123 }
124 else
125 {
126 llSay(DEBUG_CHANNEL, "Invalid element in " + llDumpList2String(values, ","));
127 }
128 }
129 else
130 {
131 if(type == TYPE_FLOAT)
132 {
133 float value = llList2Float(values, i);
134 pair_list += xkey;
135 pair_list += value;
136 }
137 else if(type == TYPE_INTEGER)
138 {
139 integer value = llList2Integer(values, i);
140 pair_list += xkey;
141 pair_list += value;
142 }
143 else if(type == TYPE_INVALID)
144 {
145 }
146 else if(type == TYPE_KEY)
147 {
148 key value = llList2Key(values, i);
149 pair_list += xkey;
150 pair_list += value;
151 }
152 else if(type == TYPE_ROTATION)
153 {
154 rotation value = llList2Rot(values, i);
155 pair_list += xkey;
156 pair_list += value;
157 }
158 else if(type == TYPE_STRING)
159 {
160 string value = llList2String(values, i);
161 pair_list += xkey;
162 pair_list += value;
163 }
164 else if(type == TYPE_VECTOR)
165 {
166 vector value = llList2Vector(values, i);
167 pair_list += xkey;
168 pair_list += value;
169 }
170 else
171 {
172 llSay(DEBUG_CHANNEL, "Invalid element in " + llDumpList2String(values, ","));
173 }
174 }
175 }
176 return pair_list;
177 }
178
179 //
180 // Gets keys from pair list.
181 //
182 list plKeys(list pair_list)
183 {
184 return llList2ListStrided(llListInsertList(pair_list, ["?"], 0), 0, -1, 2);
185 }
186
187 //
188 // Gets values from pair list.
189 //
190 list plValues(list pair_list)
191 {
192 return llList2ListStrided(pair_list, 0, -1, 2);
193 }

Back to the Best Free Tools in Second Life and OpenSim.