Skip to content

Commit

Permalink
document creating structs (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
uniboi authored May 23, 2023
1 parent 9ffedd7 commit f0569c5
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/source/squirrel/cpp_api/objectmanipulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,50 @@ Tables
}
*/
Structs
~~~~~~~

.. note::

These functions aren't available for plugins yet.

.. _pushnewstructinstance:

.. cpp:function:: SQRESULT::SQRESULT_NULL pushnewstructinstance(HSquirrelVM* sqvm, int fieldCount)

:param HSquirrelVM* sqvm: The target vm
:param int fieldCount: total number of fields the struct contains

Creates and pushes a struct instance with ``fieldCount`` to the stack.

.. _sealstructslot:

.. cpp:function:: SQRESULT::SQRESULT_NULL sealstructslot(HSquirrelVM* sqvm, int fieldIndex)

:param HSquirrelVM* sqvm: The target vm
:param int fieldIndex: Index of the field to fill

Pops a value from the stack and fills the field at ``fieldIndex`` from the struct object that needs to be at the top of the stack.

.. code-block:: cpp
pushnewstructinstance(sqvm, 2); // create a struct instance with 2 slots
pushinteger(sqvm, 12);
sealstructslot(sqvm, 0);
pushstring(sqvm, "example", -1);
sealstructslot(sqvm, 1);
/*
Assuming the compiler expects this slot:
struct ExStruct { int i, string s }
, the struct on the stack looks like this
ExStruct {
i = 12,
s = "example"
}
*/
Userdata
~~~~~~~~

Expand Down

0 comments on commit f0569c5

Please sign in to comment.