From ba7aff015d8c332067c6f92373c710c93a3a8b82 Mon Sep 17 00:00:00 2001 From: Tatjam Date: Tue, 31 Jan 2023 14:06:33 +0100 Subject: [PATCH] Add note for LuaJIT 5.2 style containers If you use the LUAJIT_ENABLE_LUA52COMPAT compilation flag with LuaJIT, C++ container can be used just fine with `ipairs` or `pairs` as these properly check the metatable keys `__ipairs` and `__pairs` used by sol to implement this behaviour. --- documentation/source/containers.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/source/containers.rst b/documentation/source/containers.rst index f5d6d6fa..dd5256a6 100644 --- a/documentation/source/containers.rst +++ b/documentation/source/containers.rst @@ -7,6 +7,7 @@ Containers are objects that are meant to be inspected and iterated and whose job * Containers from C++ are stored as ``userdata`` with special ``usertype`` metatables with :ref:`special operations` - In Lua 5.1, this means containers pushed without wrappers like :doc:`as_table` and :doc:`nested` will not work with ``pairs`` or other built-in iteration functions from Lua + Lua 5.2+ will behave just fine (does not include LuaJIT 2.0.x) + + If this behaviour is needed using LuaJIT, the compilation flag `LUAJIT_ENABLE_LUA52COMPAT` can be used. - You must push containers into C++ by returning them directly and getting/setting them directly, and they will have a type of ``sol::type::userdata`` and treated like a usertype * Containers can be manipulated from both C++ and Lua, and, like userdata, will `reflect changes if you use a reference`_ to the data. * This means containers **do not automatically serialize as Lua tables**