From a49fbc2f04543afdd9d55d3432a157e7e980c0fb Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 26 May 2019 13:32:28 -0400 Subject: [PATCH] Objective C will always haunt me. --- docs/source/api/object.rst | 2 +- docs/source/api/types.rst | 19 +++++++++++++------ docs/source/tutorial/functions.rst | 2 +- docs/source/tutorial/variables.rst | 2 +- examples/source/any_return.cpp | 2 +- examples/source/tutorials/erase_demo.cpp | 2 +- include/sol/table_core.hpp | 4 ++-- include/sol/types.hpp | 6 +++--- single/include/sol/forward.hpp | 4 ++-- single/include/sol/sol.hpp | 14 +++++++------- 10 files changed, 32 insertions(+), 25 deletions(-) diff --git a/docs/source/api/object.rst b/docs/source/api/object.rst index d00f8c1c..ddb8e5bb 100644 --- a/docs/source/api/object.rst +++ b/docs/source/api/object.rst @@ -60,7 +60,7 @@ These allow a person to compare an ``sol::object`` against :ref:`nil`, whic .. code-block:: cpp - if (myobj == sol::nil) { + if (myobj == sol::lua_nil) { // doesn't have anything... } diff --git a/docs/source/api/types.rst b/docs/source/api/types.rst index 47ac5b6f..31a359b9 100644 --- a/docs/source/api/types.rst +++ b/docs/source/api/types.rst @@ -70,7 +70,7 @@ This enumeration contains the status of a load operation from :ref:`state::load( enum class type : int { none = LUA_TNONE, - nil = LUA_TNIL, + lua_nil = LUA_TNIL, string = LUA_TSTRING, number = LUA_TNUMBER, thread = LUA_TTHREAD, @@ -80,7 +80,9 @@ This enumeration contains the status of a load operation from :ref:`state::load( lightuserdata = LUA_TLIGHTUSERDATA, table = LUA_TTABLE, poly = none | nil | string | number | thread | - table | boolean | function | userdata | lightuserdata + table | boolean | function | userdata | lightuserdata, + // if not in Objective C land... + nil = LUA_TNIL }; The base types that Lua natively communicates in and understands. Note that "poly" isn't really a true type, it's just a symbol used in sol for something whose type hasn't been checked (and you should almost never see it). @@ -118,10 +120,15 @@ special types :caption: nil :name: nil - strunil_t {}; - const nil_t nil {}; - bool operator==(nil_t, nil_t); - bool operator!=(nil_t, nil_t); + struct lua_nil_t {}; + constexpr lua_nil_t lua_nil {}; + bool operator==(lua_nil_t, lua_nil_t); + bool operator!=(lua_nil_t, lua_nil_t); + + // if not in Objective-C land + using nil_t = lua_nil_t; + constexpr nil_t nil {}; + ``nil`` is a constant used to signify Lua's ``nil``, which is a type and object that something does not exist. It is comparable to itself, :doc:`sol::object` and :doc:`proxy values`. diff --git a/docs/source/tutorial/functions.rst b/docs/source/tutorial/functions.rst index 90258001..7536ff8c 100644 --- a/docs/source/tutorial/functions.rst +++ b/docs/source/tutorial/functions.rst @@ -318,7 +318,7 @@ It can be used like so, inconjunction with ``sol::this_state``: bool do_triple = a.as(); return sol::make_object(lua, b.as() * ( do_triple ? 3 : 1 ) ); } - return sol::make_object(lua, sol::nil); + return sol::make_object(lua, sol::lua_nil); } int main () { diff --git a/docs/source/tutorial/variables.rst b/docs/source/tutorial/variables.rst index af2eaea0..d2b7d3b8 100644 --- a/docs/source/tutorial/variables.rst +++ b/docs/source/tutorial/variables.rst @@ -61,7 +61,7 @@ This example pretty much sums up what can be done. Note that the syntax ``lua["n :linenos: -Finally, it's possible to erase a reference/variable by setting it to ``nil``, using the constant ``sol::nil`` in C++: +Finally, it's possible to erase a reference/variable by setting it to ``nil``, using the constant ``sol::lua_nil`` in C++: .. literalinclude:: ../../../examples/source/tutorials/erase_demo.cpp :linenos: diff --git a/examples/source/any_return.cpp b/examples/source/any_return.cpp index 33ff7d8a..11c84717 100644 --- a/examples/source/any_return.cpp +++ b/examples/source/any_return.cpp @@ -17,7 +17,7 @@ sol::object fancy_func(sol::object a, sol::object b, sol::this_state s) { return sol::object(lua, sol::in_place_type, b.as() * (do_triple ? 3 : 1)); } // Can also use make_object - return sol::make_object(lua, sol::nil); + return sol::make_object(lua, sol::lua_nil); } int main() { diff --git a/examples/source/tutorials/erase_demo.cpp b/examples/source/tutorials/erase_demo.cpp index bf22f27d..868f2e88 100644 --- a/examples/source/tutorials/erase_demo.cpp +++ b/examples/source/tutorials/erase_demo.cpp @@ -8,7 +8,7 @@ int main() { sol::optional x = lua["bark"]; // x will have a value - lua["bark"] = sol::nil; + lua["bark"] = sol::lua_nil; sol::optional y = lua["bark"]; // y will not have a value diff --git a/include/sol/table_core.hpp b/include/sol/table_core.hpp index 294c25a8..1786fe9a 100644 --- a/include/sol/table_core.hpp +++ b/include/sol/table_core.hpp @@ -142,7 +142,7 @@ namespace sol { if constexpr (sizeof...(Keys) > 0) { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { type t = type_of(L, -1); - if (t == type::nil || t == type::none) { + if (t == type::lua_nil || t == type::none) { lua_pop(L, 1); stack::push(L, new_table(0, 0)); } @@ -152,7 +152,7 @@ namespace sol { else { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { type t = type_of(L, -1); - if ((t == type::nil || t == type::none) && (is_table_like_v)) { + if ((t == type::lua_nil || t == type::none) && (is_table_like_v)) { lua_pop(L, 1); stack::push(L, new_table(0, 0)); } diff --git a/include/sol/types.hpp b/include/sol/types.hpp index c32f9ad6..ac028bb9 100644 --- a/include/sol/types.hpp +++ b/include/sol/types.hpp @@ -97,16 +97,16 @@ namespace sol { } // namespace detail struct lua_nil_t {}; - const lua_nil_t lua_nil{}; + constexpr lua_nil_t lua_nil{}; inline bool operator==(lua_nil_t, lua_nil_t) { return true; } inline bool operator!=(lua_nil_t, lua_nil_t) { return false; } - typedef lua_nil_t nil_t; #if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0) - const nil_t nil{}; + using nil_t = lua_nil_t; + constexpr nil_t& nil = lua_nil; #endif namespace detail { diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 769a2e62..dea05b8e 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2019-05-23 08:33:03.489892 UTC -// This header was generated with sol v3.0.2 (revision cda8e02) +// Generated 2019-05-26 17:32:11.611420 UTC +// This header was generated with sol v3.0.2 (revision 4fd5d34) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index 9adbdbb1..d33b2a71 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2019-05-23 08:33:02.664806 UTC -// This header was generated with sol v3.0.2 (revision cda8e02) +// Generated 2019-05-26 17:32:11.338294 UTC +// This header was generated with sol v3.0.2 (revision 4fd5d34) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -6288,16 +6288,16 @@ namespace sol { } // namespace detail struct lua_nil_t {}; - const lua_nil_t lua_nil{}; + constexpr lua_nil_t lua_nil{}; inline bool operator==(lua_nil_t, lua_nil_t) { return true; } inline bool operator!=(lua_nil_t, lua_nil_t) { return false; } - typedef lua_nil_t nil_t; #if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0) - const nil_t nil{}; + using nil_t = lua_nil_t; + constexpr nil_t& nil = lua_nil; #endif namespace detail { @@ -22476,7 +22476,7 @@ namespace sol { if constexpr (sizeof...(Keys) > 0) { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { type t = type_of(L, -1); - if (t == type::nil || t == type::none) { + if (t == type::lua_nil || t == type::none) { lua_pop(L, 1); stack::push(L, new_table(0, 0)); } @@ -22486,7 +22486,7 @@ namespace sol { else { if constexpr ((mode & detail::insert_mode::create_if_nil) == detail::insert_mode::create_if_nil) { type t = type_of(L, -1); - if ((t == type::nil || t == type::none) && (is_table_like_v)) { + if ((t == type::lua_nil || t == type::none) && (is_table_like_v)) { lua_pop(L, 1); stack::push(L, new_table(0, 0)); }