references_from_c.rst 877 B

123456789101112131415161718192021
  1. .. embedding_references_from_c:
  2. ========================================================
  3. Mantaining references to Squirrel values from the C API
  4. ========================================================
  5. Squirrel allows to reference values through the C API; the function sq_getstackobj() gets
  6. a handle to a squirrel object(any type). The object handle can be used to control the lifetime
  7. of an object by adding or removing references to it( see sq_addref() and sq_release()).
  8. The object can be also re-pushed in the VM stack using sq_pushobject().::
  9. HSQOBJECT obj;
  10. sq_resetobject(v,&obj) //initialize the handle
  11. sq_getstackobj(v,-2,&obj); //retrieve an object handle from the pos -2
  12. sq_addref(v,&obj); //adds a reference to the object
  13. ... //do stuff
  14. sq_pushobject(v,&obj); //push the object in the stack
  15. sq_release(v,&obj); //relese the object