From 903f4db02b2e8a75ccd8486a2b455ef6ff9d2782 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 27 Jan 2020 14:13:22 -0500 Subject: [PATCH] Fix up the tutorial. --- docs/source/tutorial/ownership.rst | 2 +- examples/source/tutorials/pointer_lifetime.cpp | 4 ++-- include/sol/stack_push.hpp | 6 +++--- single/include/sol/forward.hpp | 4 ++-- single/include/sol/sol.hpp | 15 +++++++++------ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/source/tutorial/ownership.rst b/docs/source/tutorial/ownership.rst index 78027ae2..94c22732 100644 --- a/docs/source/tutorial/ownership.rst +++ b/docs/source/tutorial/ownership.rst @@ -34,7 +34,7 @@ Use/return a ``unique_ptr`` or ``shared_ptr`` instead or just return a value: :linenos: :caption: (smart pointers) pointer_lifetime.cpp :name: pointer-lifetime-smart-ptr - :lines: 1-11,14-22, 74- + :lines: 1-11,25-44, 74- If you have something you know is going to last and you just want to give it to Lua as a reference, then it's fine too: diff --git a/examples/source/tutorials/pointer_lifetime.cpp b/examples/source/tutorials/pointer_lifetime.cpp index 84bc5365..31fafa75 100644 --- a/examples/source/tutorials/pointer_lifetime.cpp +++ b/examples/source/tutorials/pointer_lifetime.cpp @@ -6,8 +6,8 @@ struct my_type { } }; -int main () { - +int main() { + sol::state lua; /* diff --git a/include/sol/stack_push.hpp b/include/sol/stack_push.hpp index a559a7b8..47a51e3d 100644 --- a/include/sol/stack_push.hpp +++ b/include/sol/stack_push.hpp @@ -296,14 +296,14 @@ namespace sol { namespace stack { lua_pushnumber(L, std::forward(args)...); return 1; } - else if constexpr (std::is_same) { - luaL_Stream* source(std::forward(args)...); + else if constexpr (std::is_same_v) { + luaL_Stream* source { std::forward(args)... }; luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source->f; stream->closef = source->closef; return 1; } - else if constexpr (std::is_same) { + else if constexpr (std::is_same_v) { luaL_Stream& source(std::forward(args)...); luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source.f; diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 8a9fce79..8908213d 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 2020-01-25 17:11:21.688498 UTC -// This header was generated with sol v3.2.0 (revision 2beb13b) +// Generated 2020-01-27 19:13:11.283155 UTC +// This header was generated with sol v3.2.0 (revision 0c38fd1) // 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 c08b4bd7..4c61cdf1 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 2020-01-25 17:11:19.283779 UTC -// This header was generated with sol v3.2.0 (revision 2beb13b) +// Generated 2020-01-27 19:13:10.728559 UTC +// This header was generated with sol v3.2.0 (revision 0c38fd1) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -11187,11 +11187,13 @@ namespace sol { namespace stack { } else if constexpr (std::is_same_v || std::is_same_v) { if (lua_getmetatable(L, index) == 0) { + type t = type_of(L, index); handler(L, index, expected, t, "value is not a valid luaL_Stream (has no metatable/is not a valid value)"); return false; } luaL_getmetatable(L, LUA_FILEHANDLE); if (type_of(L, index) != type::table) { + type t = type_of(L, index); lua_pop(L, 1); handler(L, index, @@ -11204,6 +11206,7 @@ namespace sol { namespace stack { int is_stream_table = lua_compare(L, -1, -2, LUA_OPEQ); lua_pop(L, 2); if (is_stream_table == 0) { + type t = type_of(L, index); handler(L, index, expected, t, "value is not a valid luaL_Stream (incorrect metatable)"); return false; } @@ -13416,15 +13419,15 @@ namespace sol { namespace stack { lua_pushnumber(L, std::forward(args)...); return 1; } - else if constexpr (std::is_same) { - luaL_Stream* source(std::forward(Args)...); + else if constexpr (std::is_same_v) { + luaL_Stream* source { std::forward(args)... }; luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source->f; stream->closef = source->closef; return 1; } - else if constexpr (std::is_same) { - luaL_Stream& source(std::forward(Args)...); + else if constexpr (std::is_same_v) { + luaL_Stream& source(std::forward(args)...); luaL_Stream* stream = static_cast(lua_newuserdata(L, sizeof(luaL_Stream))); stream->f = source.f; stream->closef = source.closef;