File: object_manipulation.rst

package info (click to toggle)
squirrel3 3.1-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,332 kB
  • sloc: cpp: 12,721; ansic: 917; makefile: 316; python: 40
file content (451 lines) | stat: -rw-r--r-- 14,008 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
.. _api_ref_object_manipulation:

====================
Object manipulation
====================

.. _sq_arrayappend:

.. c:function:: SQRESULT sq_arrayappend(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target array in the stack
    :returns: a SQRESULT
    :remarks: Only works on arrays.

pops a value from the stack and pushes it in the back of the array at the position idx in the stack.





.. _sq_arrayinsert:

.. c:function:: SQRESULT sq_arrayinsert(HSQUIRRELVM v, SQInteger idx, SQInteger destpos)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target array in the stack
    :param SQInteger destpos: the postion in the array where the item has to be inserted
    :returns: a SQRESULT
    :remarks: Only works on arrays.

pops a value from the stack and inserts it in an array at the specified position





.. _sq_arraypop:

.. c:function:: SQRESULT sq_arraypop(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target array in the stack
    :returns: a SQRESULT
    :remarks: Only works on arrays.

pops a value from the back of the array at the position idx in the stack.





.. _sq_arrayremove:

.. c:function:: SQRESULT sq_arrayremove(HSQUIRRELVM v, SQInteger idx, SQInteger itemidx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target array in the stack
    :param SQInteger itemidx: the index of the item in the array that has to be removed
    :returns: a SQRESULT
    :remarks: Only works on arrays.

removes an item from an array





.. _sq_arrayresize:

.. c:function:: SQRESULT sq_arrayresize(HSQUIRRELVM v, SQInteger idx, SQInteger newsize)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target array in the stack
    :param SQInteger newsize: requested size of the array
    :returns: a SQRESULT
    :remarks: Only works on arrays.if newsize if greater than the current size the new array slots will be filled with nulls.

resizes the array at the position idx in the stack.





.. _sq_arrayreverse:

.. c:function:: SQRESULT sq_arrayreverse(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target array in the stack
    :returns: a SQRESULT
    :remarks: Only works on arrays.

reverse an array in place.





.. _sq_clear:

.. c:function:: SQRESULT sq_clear(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT
    :remarks: Only works on tables and arrays.

clears all the element of the table/array at position idx in the stack.





.. _sq_clone:

.. c:function:: SQRESULT sq_clone(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT

Clones the table, array or class instance at the position idx, clones it and pushes the new object in the stack.





.. _sq_createslot:

.. c:function:: SQRESULT sq_createslot(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target table in the stack
    :returns: a SQRESULT
    :remarks: invoke the _newslot metamethod in the table delegate. it only works on tables. [this function is deperecated since version 2.0.5 use sq_newslot() instead]

pops a key and a value from the stack and performs a set operation on the table or class that is at position idx in the stack, if the slot does not exits it will be created.





.. _sq_deleteslot:

.. c:function:: SQRESULT sq_deleteslot(HSQUIRRELVM v, SQInteger idx, SQBool pushval)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target table in the stack
    :param SQBool pushval: if this param is true the function will push the value of the deleted slot.
    :returns: a SQRESULT
    :remarks: invoke the _delslot metamethod in the table delegate. it only works on tables.

pops a key from the stack and delete the slot indexed by it from the table at position idx in the stack, if the slot does not exits nothing happens.





.. _sq_get:

.. c:function:: SQRESULT sq_get(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT
    :remarks: this call will invokes the delegation system like a normal dereference it only works on tables, arrays and userdata. if the function fails nothing will be pushed in the stack.

pops a key from the stack and performs a get operation on the object at the position idx in the stack, and pushes the result in the stack.





.. _sq_getattributes:

.. c:function:: SQRESULT sq_getattributes(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target class in the stack
    :returns: a SQRESULT

Gets the attribute of a class mameber. The function pops a key from the stack and pushes the attribute of the class member indexed by they key from class at position idx in the stack. If key is null the function gets the class level attribute.





.. _sq_getbase:

.. c:function:: SQRESULT sq_getbase(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target class in the stack
    :returns: a SQRESULT

pushes the base class of the 'class' at stored position idx in the stack.





.. _sq_getclass:

.. c:function:: SQRESULT sq_getclass(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target class instance in the stack
    :returns: a SQRESULT

pushes the class of the 'class instance' at stored position idx in the stack.





.. _sq_getdelegate:

.. c:function:: SQRESULT sq_getdelegate(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT

pushes the current delegate of the object at the position idx in the stack.





.. _sq_getfreevariable:

.. c:function:: const SQChar * sq_getfreevariable(HSQUIRRELVM v, SQInteger idx, SQInteger nval)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack(closure)
    :param SQInteger nval: 0 based index of the free variable(relative to the closure).
    :returns: the name of the free variable for pure squirrel closures. NULL in case of error or if the index of the variable is out of range. In case the target closure is a native closure, the return name is always "@NATIVE".
    :remarks: The function works for both squirrel closure and native closure.

gets the value of the free variable of the closure at the position idx in the stack.





.. _sq_getweakrefval:

.. c:function:: SQRESULT sq_getweakrefval(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target weak reference
    :returns: a SQRESULT
    :remarks: if the function fails, nothing is pushed in the stack.

pushes the object pointed by the weak reference at position idx in the stack.





.. _sq_instanceof:

.. c:function:: SQBool sq_instanceof(HSQUIRRELVM v)

    :param HSQUIRRELVM v: the target VM
    :returns: SQTrue if the instance at position -2 in the stack is an instance of the class object at position -1 in the stack.
    :remarks: The function doesn't pop any object from the stack.

Determintes if an object is an instance of a certain class. Expects an istance and a class in the stack.





.. _sq_newmember:

.. c:function:: SQRESULT sq_newmember(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target table in the stack
    :param SQBool bstatic: if SQTrue creates a static member.
    :returns: a SQRESULT
    :remarks: Invokes the _newmember metamethod in the class. it only works on classes.

pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at position idx in the stack, if the slot does not exits it will be created.





.. _sq_newslot:

.. c:function:: SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target table in the stack
    :param SQBool bstatic: if SQTrue creates a static member. This parameter is only used if the target object is a class.
    :returns: a SQRESULT
    :remarks: Invokes the _newslot metamethod in the table delegate. it only works on tables and classes.

pops a key and a value from the stack and performs a set operation on the table or class that is at position idx in the stack, if the slot does not exits it will be created.





.. _sq_next:

.. c:function:: SQRESULT sq_next(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT

Pushes in the stack the next key and value of an array, table or class slot. To start the iteration this function expects a null value on top of the stack; at every call the function will substitute the null value with an iterator and push key and value of the container slot. Every iteration the application has to pop the previous key and value but leave the iterator(that is used as reference point for the next iteration). The function will fail when all slots have been iterated(see Tables and arrays manipulation).





.. _sq_rawdeleteslot:

.. c:function:: SQRESULT sq_rawdeleteslot(HSQUIRRELVM v, SQInteger idx, SQBool pushval)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target table in the stack
    :param SQBool pushval: if this param is true the function will push the value of the deleted slot.
    :returns: a SQRESULT

Deletes a slot from a table without employing the _delslot metamethod. pops a key from the stack and delete the slot indexed by it from the table at position idx in the stack, if the slot does not exits nothing happens.





.. _sq_rawget:

.. c:function:: SQRESULT sq_rawget(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT
    :remarks: Only works on tables and arrays.

pops a key from the stack and performs a get operation on the object at position idx in the stack, without employing delegation or metamethods.





.. _sq_rawnewmember:

.. c:function:: SQRESULT sq_rawnewmember(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target table in the stack
    :param SQBool bstatic: if SQTrue creates a static member.
    :returns: a SQRESULT
    :remarks: it only works on classes.

pops a key, a value and an object(that will be set as attribute of the member) from the stack and performs a new slot operation on the class that is at position idx in the stack, if the slot does not exits it will be created.





.. _sq_rawset:

.. c:function:: SQRESULT sq_rawset(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT
    :remarks: it only works on tables and arrays. if the function fails nothing will be pushed in the stack.

pops a key and a value from the stack and performs a set operation on the object at position idx in the stack, without employing delegation or metamethods.





.. _sq_set:

.. c:function:: SQRESULT sq_set(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT
    :remarks: this call will invoke the delegation system like a normal assignment, it only works on tables, arrays and userdata.

pops a key and a value from the stack and performs a set operation on the object at position idx in the stack.





.. _sq_setattributes:

.. c:function:: SQRESULT sq_setattributes(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target class in the stack.
    :returns: a SQRESULT

Sets the attribute of a class mameber. The function pops a key and a value from the stack and sets the attribute (indexed by they key) on the class at position idx in the stack. If key is null the function sets the class level attribute. If the function succeed, the old attribute value is pushed in the stack.





.. _sq_setdelegate:

.. c:function:: SQRESULT sq_setdelegate(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :returns: a SQRESULT
    :remarks: to remove the delgate from an object is necessary to use null as delegate instead of a table.

pops a table from the stack and sets it as delegate of the object at the position idx in the stack.





.. _sq_setfreevariable:

.. c:function:: SQRESULT sq_setfreevariable(HSQUIRRELVM v, SQInteger idx, SQInteger nval)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index of the target object in the stack
    :param SQInteger nval: 0 based index of the free variable(relative to the closure).
    :returns: a SQRESULT

pops a value from the stack and sets it as free variable of the closure at the position idx in the stack.





.. _sq_weakref:

.. c:function:: void sq_weakref(HSQUIRRELVM v, SQInteger idx)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger idx: index to the target object in the stack
    :returns: a SQRESULT
    :remarks: if the object at idx position is an integer,float,bool or null the object itself is pushed instead of a weak ref.

pushes a weak reference to the object at position idx in the stack.