Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document creating structs #167

Merged
merged 3 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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