From e8e5ddc890fffbe4e5df9d929092b1bb951341b6 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 4 Mar 2018 05:40:57 -0500 Subject: [PATCH] fix overpop from stack_check_get tracking --- examples/require.cpp | 19 ++++++++++++------- single/sol/sol.hpp | 6 +++--- single/sol/sol_forward.hpp | 4 ++-- sol/stack_check_get.hpp | 2 +- sol2.natvis | 24 ++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 sol2.natvis diff --git a/examples/require.cpp b/examples/require.cpp index db4a85c7..96c164eb 100644 --- a/examples/require.cpp +++ b/examples/require.cpp @@ -12,31 +12,36 @@ sol::table open_mylib(sol::this_state s) { sol::state_view lua(s); sol::table module = lua.create_table(); - module["func"] = []() { /* super cool function here */ }; + module["func"] = []() { + /* super cool function here */ + return 2; + }; // register a class too module.new_usertype("some_class", "bark", &some_class::bark - ); + ); - return module; + return module; } int main() { std::cout << "=== require example ===" << std::endl; sol::state lua; - lua.open_libraries(sol::lib::package); + lua.open_libraries(sol::lib::package, sol::lib::base); // sol::c_call takes functions at the template level // and turns it into a lua_CFunction // alternatively, one can use sol::c_call> to make the call // if it's a constexpr struct lua.require("my_lib", sol::c_call); - // do ALL THE THINGS YOU LIKE - lua.script(R"( + // run some code against your require'd library + lua.safe_script(R"( s = my_lib.some_class.new() -s.bark = 20; +assert(my_lib.func() == 2) +s.bark = 20 )"); + some_class& s = lua["s"]; c_assert(s.bark == 20); std::cout << "s.bark = " << s.bark << std::endl; diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index cc64cdd5..28c1780e 100644 --- a/single/sol/sol.hpp +++ b/single/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 2018-03-03 20:38:52.222840 UTC -// This header was generated with sol v2.19.5 (revision 2e1fcd3) +// Generated 2018-03-04 10:40:19.748536 UTC +// This header was generated with sol v2.19.5 (revision ab5b417) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -9472,12 +9472,12 @@ namespace stack { struct check_getter::value>> { template static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); // actually check if it's none here, otherwise // we'll have a nil object inside an optional! bool success = !lua_isnoneornil(L, index); if (!success) { // expected type, actual type + tracking.use(static_cast(!lua_isnone(L, index))); handler(L, index, type::poly, type_of(L, index), ""); return nullopt; } diff --git a/single/sol/sol_forward.hpp b/single/sol/sol_forward.hpp index 0ee88ba6..5c1952d0 100644 --- a/single/sol/sol_forward.hpp +++ b/single/sol/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 2018-03-03 20:38:52.449565 UTC -// This header was generated with sol v2.19.5 (revision 2e1fcd3) +// Generated 2018-03-04 10:40:19.971825 UTC +// This header was generated with sol v2.19.5 (revision ab5b417) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/sol/stack_check_get.hpp b/sol/stack_check_get.hpp index 5dc5e008..74de3b0c 100644 --- a/sol/stack_check_get.hpp +++ b/sol/stack_check_get.hpp @@ -51,12 +51,12 @@ namespace stack { struct check_getter::value>> { template static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - tracking.use(1); // actually check if it's none here, otherwise // we'll have a nil object inside an optional! bool success = !lua_isnoneornil(L, index); if (!success) { // expected type, actual type + tracking.use(static_cast(!lua_isnone(L, index))); handler(L, index, type::poly, type_of(L, index), ""); return nullopt; } diff --git a/sol2.natvis b/sol2.natvis new file mode 100644 index 00000000..9bbe3be9 --- /dev/null +++ b/sol2.natvis @@ -0,0 +1,24 @@ + + + + empty + {*((value_type*)(&storage_[0]))} + + *((value_type*)(&storage_[0])) + + + + ref={ref} state={luastate} + + ref + luastate + + + + index={index} state={luastate} + + index + luastate + + + \ No newline at end of file