object_manipulation.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. .. _api_ref_object_manipulation:
  2. ====================
  3. Object manipulation
  4. ====================
  5. .. _sq_arrayappend:
  6. .. c:function:: SQRESULT sq_arrayappend(HSQUIRRELVM v, SQInteger idx)
  7. :param HSQUIRRELVM v: the target VM
  8. :param SQInteger idx: index of the target array in the stack
  9. :returns: a SQRESULT
  10. :remarks: Only works on arrays.
  11. pops a value from the stack and pushes it in the back of the array at the position idx in the stack.
  12. .. _sq_arrayinsert:
  13. .. c:function:: SQRESULT sq_arrayinsert(HSQUIRRELVM v, SQInteger idx, SQInteger destpos)
  14. :param HSQUIRRELVM v: the target VM
  15. :param SQInteger idx: index of the target array in the stack
  16. :param SQInteger destpos: the position in the array where the item has to be inserted
  17. :returns: a SQRESULT
  18. :remarks: Only works on arrays.
  19. pops a value from the stack and inserts it in an array at the specified position
  20. .. _sq_arraypop:
  21. .. c:function:: SQRESULT sq_arraypop(HSQUIRRELVM v, SQInteger idx)
  22. :param HSQUIRRELVM v: the target VM
  23. :param SQInteger idx: index of the target array in the stack
  24. :returns: a SQRESULT
  25. :remarks: Only works on arrays.
  26. pops a value from the back of the array at the position idx in the stack.
  27. .. _sq_arrayremove:
  28. .. c:function:: SQRESULT sq_arrayremove(HSQUIRRELVM v, SQInteger idx, SQInteger itemidx)
  29. :param HSQUIRRELVM v: the target VM
  30. :param SQInteger idx: index of the target array in the stack
  31. :param SQInteger itemidx: the index of the item in the array that has to be removed
  32. :returns: a SQRESULT
  33. :remarks: Only works on arrays.
  34. removes an item from an array
  35. .. _sq_arrayresize:
  36. .. c:function:: SQRESULT sq_arrayresize(HSQUIRRELVM v, SQInteger idx, SQInteger newsize)
  37. :param HSQUIRRELVM v: the target VM
  38. :param SQInteger idx: index of the target array in the stack
  39. :param SQInteger newsize: requested size of the array
  40. :returns: a SQRESULT
  41. :remarks: Only works on arrays. If newsize if greater than the current size the new array slots will be filled with nulls.
  42. resizes the array at the position idx in the stack.
  43. .. _sq_arrayreverse:
  44. .. c:function:: SQRESULT sq_arrayreverse(HSQUIRRELVM v, SQInteger idx)
  45. :param HSQUIRRELVM v: the target VM
  46. :param SQInteger idx: index of the target array in the stack
  47. :returns: a SQRESULT
  48. :remarks: Only works on arrays.
  49. reverse an array in place.
  50. .. _sq_clear:
  51. .. c:function:: SQRESULT sq_clear(HSQUIRRELVM v, SQInteger idx)
  52. :param HSQUIRRELVM v: the target VM
  53. :param SQInteger idx: index of the target object in the stack
  54. :returns: a SQRESULT
  55. :remarks: Only works on tables and arrays.
  56. clears all the element of the table/array at position idx in the stack.
  57. .. _sq_clone:
  58. .. c:function:: SQRESULT sq_clone(HSQUIRRELVM v, SQInteger idx)
  59. :param HSQUIRRELVM v: the target VM
  60. :param SQInteger idx: index of the target object in the stack
  61. :returns: a SQRESULT
  62. Clones the table, array or class instance at the position idx, clones it and pushes the new object in the stack.
  63. .. _sq_createslot:
  64. .. c:function:: SQRESULT sq_createslot(HSQUIRRELVM v, SQInteger idx)
  65. :param HSQUIRRELVM v: the target VM
  66. :param SQInteger idx: index of the target table in the stack
  67. :returns: a SQRESULT
  68. :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]
  69. 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.
  70. .. _sq_deleteslot:
  71. .. c:function:: SQRESULT sq_deleteslot(HSQUIRRELVM v, SQInteger idx, SQBool pushval)
  72. :param HSQUIRRELVM v: the target VM
  73. :param SQInteger idx: index of the target table in the stack
  74. :param SQBool pushval: if this param is true the function will push the value of the deleted slot.
  75. :returns: a SQRESULT
  76. :remarks: invoke the _delslot metamethod in the table delegate. it only works on tables.
  77. 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.
  78. .. _sq_get:
  79. .. c:function:: SQRESULT sq_get(HSQUIRRELVM v, SQInteger idx)
  80. :param HSQUIRRELVM v: the target VM
  81. :param SQInteger idx: index of the target object in the stack
  82. :returns: a SQRESULT
  83. :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.
  84. 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.
  85. .. _sq_getattributes:
  86. .. c:function:: SQRESULT sq_getattributes(HSQUIRRELVM v, SQInteger idx)
  87. :param HSQUIRRELVM v: the target VM
  88. :param SQInteger idx: index of the target class in the stack
  89. :returns: a SQRESULT
  90. Gets the attribute of a class member. The function pops a key from the stack and pushes the attribute of the class member indexed by they key from a class at position idx in the stack. If key is null the function gets the class level attribute.
  91. .. _sq_getbase:
  92. .. c:function:: SQRESULT sq_getbase(HSQUIRRELVM v, SQInteger idx)
  93. :param HSQUIRRELVM v: the target VM
  94. :param SQInteger idx: index of the target class in the stack
  95. :returns: a SQRESULT
  96. pushes the base class of the 'class' at stored position idx in the stack.
  97. .. _sq_getclass:
  98. .. c:function:: SQRESULT sq_getclass(HSQUIRRELVM v, SQInteger idx)
  99. :param HSQUIRRELVM v: the target VM
  100. :param SQInteger idx: index of the target class instance in the stack
  101. :returns: a SQRESULT
  102. pushes the class of the 'class instance' at stored position idx in the stack.
  103. .. _sq_getdelegate:
  104. .. c:function:: SQRESULT sq_getdelegate(HSQUIRRELVM v, SQInteger idx)
  105. :param HSQUIRRELVM v: the target VM
  106. :param SQInteger idx: index of the target object in the stack
  107. :returns: a SQRESULT
  108. pushes the current delegate of the object at the position idx in the stack.
  109. .. _sq_getfreevariable:
  110. .. c:function:: const SQChar * sq_getfreevariable(HSQUIRRELVM v, SQInteger idx, SQInteger nval)
  111. :param HSQUIRRELVM v: the target VM
  112. :param SQInteger idx: index of the target object in the stack(closure)
  113. :param SQInteger nval: 0 based index of the free variable(relative to the closure).
  114. :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".
  115. :remarks: The function works for both squirrel closure and native closure.
  116. gets the value of the free variable of the closure at the position idx in the stack.
  117. .. _sq_getweakrefval:
  118. .. c:function:: SQRESULT sq_getweakrefval(HSQUIRRELVM v, SQInteger idx)
  119. :param HSQUIRRELVM v: the target VM
  120. :param SQInteger idx: index of the target weak reference
  121. :returns: a SQRESULT
  122. :remarks: if the function fails, nothing is pushed in the stack.
  123. pushes the object pointed by the weak reference at position idx in the stack.
  124. .. _sq_instanceof:
  125. .. c:function:: SQBool sq_instanceof(HSQUIRRELVM v)
  126. :param HSQUIRRELVM v: the target VM
  127. :returns: SQTrue if the instance at position -2 in the stack is an instance of the class object at position -1 in the stack.
  128. :remarks: The function doesn't pop any object from the stack.
  129. Determines if an object is an instance of a certain class. Expects an instance and a class in the stack.
  130. .. _sq_newmember:
  131. .. c:function:: SQRESULT sq_newmember(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
  132. :param HSQUIRRELVM v: the target VM
  133. :param SQInteger idx: index of the target table in the stack
  134. :param SQBool bstatic: if SQTrue creates a static member.
  135. :returns: a SQRESULT
  136. :remarks: Invokes the _newmember metamethod in the class. it only works on classes.
  137. pops a key, a value and an object (which 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.
  138. .. _sq_newslot:
  139. .. c:function:: SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
  140. :param HSQUIRRELVM v: the target VM
  141. :param SQInteger idx: index of the target table in the stack
  142. :param SQBool bstatic: if SQTrue creates a static member. This parameter is only used if the target object is a class.
  143. :returns: a SQRESULT
  144. :remarks: Invokes the _newslot metamethod in the table delegate. it only works on tables and classes.
  145. 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.
  146. .. _sq_next:
  147. .. c:function:: SQRESULT sq_next(HSQUIRRELVM v, SQInteger idx)
  148. :param HSQUIRRELVM v: the target VM
  149. :param SQInteger idx: index of the target object in the stack
  150. :returns: a SQRESULT
  151. 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).
  152. .. _sq_rawdeleteslot:
  153. .. c:function:: SQRESULT sq_rawdeleteslot(HSQUIRRELVM v, SQInteger idx, SQBool pushval)
  154. :param HSQUIRRELVM v: the target VM
  155. :param SQInteger idx: index of the target table in the stack
  156. :param SQBool pushval: if this param is true the function will push the value of the deleted slot.
  157. :returns: a SQRESULT
  158. 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.
  159. .. _sq_rawget:
  160. .. c:function:: SQRESULT sq_rawget(HSQUIRRELVM v, SQInteger idx)
  161. :param HSQUIRRELVM v: the target VM
  162. :param SQInteger idx: index of the target object in the stack
  163. :returns: a SQRESULT
  164. :remarks: Only works on tables and arrays.
  165. 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.
  166. .. _sq_rawnewmember:
  167. .. c:function:: SQRESULT sq_rawnewmember(HSQUIRRELVM v, SQInteger idx, SQBool bstatic)
  168. :param HSQUIRRELVM v: the target VM
  169. :param SQInteger idx: index of the target table in the stack
  170. :param SQBool bstatic: if SQTrue creates a static member.
  171. :returns: a SQRESULT
  172. :remarks: it only works on classes.
  173. 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.
  174. .. _sq_rawset:
  175. .. c:function:: SQRESULT sq_rawset(HSQUIRRELVM v, SQInteger idx)
  176. :param HSQUIRRELVM v: the target VM
  177. :param SQInteger idx: index of the target object in the stack
  178. :returns: a SQRESULT
  179. :remarks: it only works on tables and arrays. if the function fails nothing will be pushed in the stack.
  180. 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.
  181. .. _sq_set:
  182. .. c:function:: SQRESULT sq_set(HSQUIRRELVM v, SQInteger idx)
  183. :param HSQUIRRELVM v: the target VM
  184. :param SQInteger idx: index of the target object in the stack
  185. :returns: a SQRESULT
  186. :remarks: this call will invoke the delegation system like a normal assignment, it only works on tables, arrays and userdata.
  187. pops a key and a value from the stack and performs a set operation on the object at position idx in the stack.
  188. .. _sq_setattributes:
  189. .. c:function:: SQRESULT sq_setattributes(HSQUIRRELVM v, SQInteger idx)
  190. :param HSQUIRRELVM v: the target VM
  191. :param SQInteger idx: index of the target class in the stack.
  192. :returns: a SQRESULT
  193. Sets the attribute of a class member. The function pops a key and a value from the stack and sets the attribute (indexed by the 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.
  194. .. _sq_setdelegate:
  195. .. c:function:: SQRESULT sq_setdelegate(HSQUIRRELVM v, SQInteger idx)
  196. :param HSQUIRRELVM v: the target VM
  197. :param SQInteger idx: index of the target object in the stack
  198. :returns: a SQRESULT
  199. :remarks: to remove the delegate from an object, set a null value.
  200. pops a table from the stack and sets it as the delegate of the object at the position idx in the stack.
  201. .. _sq_setfreevariable:
  202. .. c:function:: SQRESULT sq_setfreevariable(HSQUIRRELVM v, SQInteger idx, SQInteger nval)
  203. :param HSQUIRRELVM v: the target VM
  204. :param SQInteger idx: index of the target object in the stack
  205. :param SQInteger nval: 0 based index of the free variable(relative to the closure).
  206. :returns: a SQRESULT
  207. pops a value from the stack and sets it as a free variable of the closure at the position idx in the stack.
  208. .. _sq_weakref:
  209. .. c:function:: void sq_weakref(HSQUIRRELVM v, SQInteger idx)
  210. :param HSQUIRRELVM v: the target VM
  211. :param SQInteger idx: index to the target object in the stack
  212. :returns: a SQRESULT
  213. :remarks: if the object at idx position is an integer,float,bool or null the object itself is pushed instead of a weak ref.
  214. pushes a weak reference to the object at position idx in the stack.