Usertype documentation

This commit is contained in:
ThePhD 2016-07-07 18:11:03 -04:00
parent dbaa8f58f0
commit f7108d5e37
6 changed files with 31 additions and 4 deletions

View File

@ -35,6 +35,7 @@ Browse the various function and classes :doc:`Sol<../index>` utilizes to make yo
types types
user user
usertype usertype
simple_usertype
userdata userdata
usertype_memory usertype_memory
unique_usertype_traits unique_usertype_traits

View File

@ -0,0 +1,14 @@
simple_usertype
==================
structures and classes from C++ made available to Lua code (simpler)
--------------------------------------------------------------------
This type is no different from :doc:`regular usertype<usertype>`, but with the following caveats:
* Dot (".") syntax is not natively supported for simple usertypes (e.g., typical member variable / property bindings)
- All member variables become functions of that name and are get/set in Lua with the syntax ``local v = obj:value()`` to get, and ``obj:value(24)`` to set
- :doc:`properties<property>` also become functions, similar to how member variables are treated above
* Automatic "__index" and "__newindex" handling is not done
- Overriding either of these properties leaves it entirely up to you to handle how you find variables
- If you override "__index" or "__newindex", you must perform a raw get on the original table and return a valid function / value if you want it to find the members you already set on the ``simple_usertype``

View File

@ -145,6 +145,9 @@ The constructor of usertype takes a variable number of arguments. It takes an ev
.. _constructor: .. _constructor:
* ``sol::simple``
- Only allowed as the first argument to the usertype constructor
- This tag triggers the :doc:`simple usertype<simple_usertype>` changes / optimizations
* ``"{name}", constructors<Type-List-0, Type-List-1, ...>`` * ``"{name}", constructors<Type-List-0, Type-List-1, ...>``
- ``Type-List-N`` must be a ``sol::types<Args...>``, where ``Args...`` is a list of types that a constructor takes. Supports overloading by default - ``Type-List-N`` must be a ``sol::types<Args...>``, where ``Args...`` is a list of types that a constructor takes. Supports overloading by default
- If you pass the ``constructors<...>`` argument first when constructing the usertype, then it will automatically be given a ``"{name}"`` of ``"new"`` - If you pass the ``constructors<...>`` argument first when constructing the usertype, then it will automatically be given a ``"{name}"`` of ``"new"``
@ -250,6 +253,15 @@ traits
This trait is used to provide names for the various metatables and global tables used to perform cleanup and lookup. They are automatically generated at runtime. In the case of RTTI being present, Sol will attempt to demangle the name from ``std::type_info`` to produce a valid name. If RTTI is disabled, Sol attempts to parse the output of ``__PRETTY_FUCNTION__`` (``g++``/``clang++``) or ``_FUNCDSIG`` (``vc++``) to get the proper type name. If you have a special need you can override the names for your specific type. This trait is used to provide names for the various metatables and global tables used to perform cleanup and lookup. They are automatically generated at runtime. In the case of RTTI being present, Sol will attempt to demangle the name from ``std::type_info`` to produce a valid name. If RTTI is disabled, Sol attempts to parse the output of ``__PRETTY_FUCNTION__`` (``g++``/``clang++``) or ``_FUNCDSIG`` (``vc++``) to get the proper type name. If you have a special need you can override the names for your specific type.
compilation speed
-----------------
.. note::
If you find that compilation times are too long and you're only binding member functions, consider perhaps using :doc:`simple usertypes<simple_usertype>`. This can reduce compile times (but may cost memory size and speed). See the simple usertypes documentation for more details.
performance note performance note
---------------- ----------------

View File

@ -59,9 +59,9 @@ author = 'ThePhD'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '2.8' version = '2.9'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '2.8.6' release = '2.9.0'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@ -7,7 +7,7 @@
:target: https://github.com/ThePhD/sol2 :target: https://github.com/ThePhD/sol2
:alt: sol2 repository :alt: sol2 repository
Sol 2.8 Sol 2.9
======= =======
a fast, simple C++ and Lua Binding a fast, simple C++ and Lua Binding
---------------------------------- ----------------------------------

View File

@ -60,7 +60,7 @@ namespace sol {
simple_usertype_metatable(usertype_detail::verified_tag, std::index_sequence<I...>, lua_State* L, Tuple&& args) simple_usertype_metatable(usertype_detail::verified_tag, std::index_sequence<I...>, lua_State* L, Tuple&& args)
: callconstructfunc(nil) { : callconstructfunc(nil) {
registrations.reserve(std::tuple_size<meta::unqualified_t<Tuple>>::value); registrations.reserve(std::tuple_size<meta::unqualified_t<Tuple>>::value);
detail::swallow{ 0, (void)detail::swallow{ 0,
(add(L, detail::forward_get<I * 2>(args), detail::forward_get<I * 2 + 1>(args)),0)... (add(L, detail::forward_get<I * 2>(args), detail::forward_get<I * 2 + 1>(args)),0)...
}; };
} }