tables_and_arrays_manipulation.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. .. _embedding_tables_and_arrays_manipulation:
  2. ==============================
  3. Tables and arrays manipulation
  4. ==============================
  5. A new table is created calling sq_newtable, this function pushes a new table in the stack.::
  6. void sq_newtable(HSQUIRRELVM v);
  7. To create a new slot::
  8. SQRESULT sq_newslot(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
  9. To set or get the table delegate::
  10. SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
  11. SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
  12. A new array is created calling sq_newarray, the function pushes a new array in the
  13. stack; if the parameters size is bigger than 0 the elements are initialized to null.::
  14. void sq_newarray (HSQUIRRELVM v,SQInteger size);
  15. To append a value to the back of the array::
  16. SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
  17. To remove a value from the back of the array::
  18. SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQInteger pushval);
  19. To resize the array::
  20. SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
  21. To retrieve the size of a table or an array you must use sq_getsize()::
  22. SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
  23. To set a value in an array or table::
  24. SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
  25. To get a value from an array or table::
  26. SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
  27. To get or set a value from a table without employ delegation::
  28. SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
  29. SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
  30. To iterate a table or an array::
  31. SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
  32. Here an example of how to perform an iteration: ::
  33. //push your table/array here
  34. sq_pushnull(v) //null iterator
  35. while(SQ_SUCCEEDED(sq_next(v,-2)))
  36. {
  37. //here -1 is the value and -2 is the key
  38. sq_pop(v,2); //pops key and val before the nex iteration
  39. }
  40. sq_pop(v,1); //pops the null iterator