From b9707e11caea64ab534e1449e18fcd3d511d2a02 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 13 Jan 2025 04:20:48 +0300 Subject: [PATCH] fix lua::create_lambda and lua::create_lambda_nothrow --- src/logic/scripting/lua/lua_util.cpp | 4 ++-- src/logic/scripting/lua/lua_wrapper.hpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/logic/scripting/lua/lua_util.cpp b/src/logic/scripting/lua/lua_util.cpp index 8c3adaea..842c7859 100644 --- a/src/logic/scripting/lua/lua_util.cpp +++ b/src/logic/scripting/lua/lua_util.cpp @@ -268,9 +268,9 @@ KeyCallback lua::create_simple_handler(State* L) { scripting::common_func lua::create_lambda(State* L) { auto funcptr = create_lambda_handler(L); return [=](const std::vector& args) -> dv::value { - int top = gettop(L) + 1; if (!get_from(L, LAMBDAS_TABLE, *funcptr, false)) return nullptr; + int top = gettop(L) + 1; for (const auto& arg : args) { pushvalue(L, arg); } @@ -290,9 +290,9 @@ scripting::common_func lua::create_lambda(State* L) { scripting::common_func lua::create_lambda_nothrow(State* L) { auto funcptr = create_lambda_handler(L); return [=](const std::vector& args) -> dv::value { - int top = gettop(L) - 1; if (!get_from(L, LAMBDAS_TABLE, *funcptr, false)) return nullptr; + int top = gettop(L) - 1; for (const auto& arg : args) { pushvalue(L, arg); } diff --git a/src/logic/scripting/lua/lua_wrapper.hpp b/src/logic/scripting/lua/lua_wrapper.hpp index ee184cb1..8637babc 100644 --- a/src/logic/scripting/lua/lua_wrapper.hpp +++ b/src/logic/scripting/lua/lua_wrapper.hpp @@ -21,6 +21,11 @@ namespace lua { } inline void pop(lua::State* L, int n = 1) { +#ifndef NDEBUG + if (lua_gettop(L) < n) { + abort(); + } +#endif lua_pop(L, n); } inline void insert(lua::State* L, int idx) {