mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Heavily improve usage of Preprocessor checks
- Weed out bugs in the numeric checking implementation - Solve the problem with load_result/protected_function_result/unsafe_function_result being copyable and thus amenable to explosions. Fixes #995. - Resolve the warning in sol::readonly. Fixes #1000. - Looke into #1014. Not sure I can help there, honestly; looks like a mix up of multiply-loaded libraries and mixing the two.
This commit is contained in:
parent
0e1aafe4df
commit
000fa31809
|
@ -14,7 +14,7 @@ bool sol_lua_check(sol::types<two_things>, lua_State* L, int index, Handler&& ha
|
|||
// indices can be negative to count backwards from the top of the stack,
|
||||
// rather than the bottom up
|
||||
// to deal with this, we adjust the index to
|
||||
// its absolute position using the lua_absindex function
|
||||
// its absolute position using the lua_absindex function
|
||||
int absolute_index = lua_absindex(L, index);
|
||||
// Check first and second second index for being the proper types
|
||||
bool success = sol::stack::check<int>(L, absolute_index, handler) && sol::stack::check<bool>(L, absolute_index + 1, handler);
|
||||
|
@ -26,15 +26,15 @@ two_things sol_lua_get(sol::types<two_things>, lua_State* L, int index, sol::sta
|
|||
int absolute_index = lua_absindex(L, index);
|
||||
// Get the first element
|
||||
int a = sol::stack::get<int>(L, absolute_index);
|
||||
// Get the second element,
|
||||
// Get the second element,
|
||||
// in the +1 position from the first
|
||||
bool b = sol::stack::get<bool>(L, absolute_index + 1);
|
||||
// we use 2 slots, each of the previous takes 1
|
||||
tracking.use(2);
|
||||
return two_things{ a, b };
|
||||
return two_things { a, b };
|
||||
}
|
||||
|
||||
int sol_lua_push(sol::types<two_things>, lua_State* L, const two_things& things) {
|
||||
int sol_lua_push(lua_State* L, const two_things& things) {
|
||||
int amount = sol::stack::push(L, things.a);
|
||||
// amount will be 1: int pushes 1 item
|
||||
amount += sol::stack::push(L, things.b);
|
||||
|
@ -46,7 +46,7 @@ int sol_lua_push(sol::types<two_things>, lua_State* L, const two_things& things)
|
|||
int main() {
|
||||
std::cout << "=== customization ===" << std::endl;
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
|
||||
|
@ -56,7 +56,7 @@ int main() {
|
|||
// get the function out of Lua
|
||||
sol::function f = lua["f"];
|
||||
|
||||
two_things things = f(two_things{ 24, false });
|
||||
two_things things = f(two_things { 24, false });
|
||||
c_assert(things.a == 24);
|
||||
c_assert(things.b == false);
|
||||
// things.a == 24
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <sol/version.hpp>
|
||||
#include <sol/compatibility/lua_version.hpp>
|
||||
|
||||
#if !defined(SOL_NO_COMPAT) || !(SOL_NO_COMPAT)
|
||||
#if SOL_IS_ON(SOL_USE_COMPATIBILITY_LAYER_I_)
|
||||
|
||||
#if SOL_IS_ON(SOL_USE_CXX_LUA_I_) || SOL_IS_ON(SOL_USE_CXX_LUAJIT_I_)
|
||||
#ifndef COMPAT53_LUA_CPP
|
||||
|
@ -46,6 +46,6 @@
|
|||
#include <sol/compatibility/compat-5.3.h>
|
||||
#include <sol/compatibility/compat-5.4.h>
|
||||
|
||||
#endif // SOL_NO_COMPAT
|
||||
#endif
|
||||
|
||||
#endif // SOL_COMPATIBILITY_HPP
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#elif defined(LUAJIT_VERSION)
|
||||
#define SOL_USE_LUAJIT_I_ SOL_OFF
|
||||
#else
|
||||
#define SOL_USE_LUAJIT_I_ SOL_OFF
|
||||
#define SOL_USE_LUAJIT_I_ SOL_DEFAULT_OFF
|
||||
#endif // luajit
|
||||
|
||||
#if SOL_IS_ON(SOL_USE_CXX_LUAJIT_I_)
|
||||
|
@ -71,9 +71,9 @@
|
|||
#endif
|
||||
|
||||
#if defined(MOONJIT_VERSION)
|
||||
#define SOL_MOONJIT_I_ SOL_ON
|
||||
#define SOL_USE_MOONJIT_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_MOONJIT_I_ SOL_OFF
|
||||
#define SOL_USE_MOONJIT_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if !defined(SOL_LUA_VERSION)
|
||||
|
@ -98,10 +98,18 @@
|
|||
|
||||
// Exception safety / propagation, according to Lua information
|
||||
// and user defines. Note this can sometimes change based on version information...
|
||||
#if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) && (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0)
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
|
||||
#elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0)
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON
|
||||
#if defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE)
|
||||
#if (SOL_EXCEPTIONS_ALWAYS_UNSAFE != 0)
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
|
||||
#else
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON
|
||||
#endif
|
||||
#elif defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
|
||||
#if (SOL_EXCEPTIONS_SAFE_PROPAGATION != 0)
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
|
||||
#endif
|
||||
#elif SOL_LUAJIT_VERSION_I_ >= 20100
|
||||
// LuaJIT 2.1.0-beta3 and better have exception support locked in for all platforms (mostly)
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_ON
|
||||
|
@ -116,9 +124,37 @@
|
|||
// otherwise, there is no exception safety for
|
||||
// shoving exceptions through Lua and errors should
|
||||
// always be serialized
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_OFF
|
||||
#define SOL_PROPAGATE_EXCEPTIONS_I_ SOL_DEFAULT_OFF
|
||||
#endif // LuaJIT beta 02.01.00 have better exception handling on all platforms since beta3
|
||||
|
||||
#if defined(SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE)
|
||||
#if (SOL_LUAJIT_USE_EXCEPTION_TRAMPOLINE != 0)
|
||||
#define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#if SOL_IS_OFF(SOL_PROPAGATE_EXCEPTIONS_I_) && SOL_IS_ON(SOL_USE_LUAJIT_I_)
|
||||
#define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION)
|
||||
#if (SOL_LUAL_STREAM_HAS_CLOSE_FUNCTION != 0)
|
||||
#define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#if SOL_IS_OFF(SOL_USE_LUAJIT_I_) && (SOL_LUA_VERSION > 501)
|
||||
#define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif // SOL_COMPATIBILITY_VERSION_HPP
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace sol {
|
|||
call_status stats = call_status::yielded;
|
||||
|
||||
void luacall(std::ptrdiff_t argcount, std::ptrdiff_t) {
|
||||
#if SOL_LUA_VERSION >= 504
|
||||
#if SOL_LUA_VESION_I_ >= 504
|
||||
int nresults;
|
||||
stats = static_cast<call_status>(lua_resume(lua_state(), nullptr, static_cast<int>(argcount), &nresults));
|
||||
#else
|
||||
|
@ -91,13 +91,16 @@ namespace sol {
|
|||
using base_t::lua_state;
|
||||
|
||||
basic_coroutine() = default;
|
||||
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_coroutine>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
template <typename T,
|
||||
meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_coroutine>>,
|
||||
meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>,
|
||||
meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_coroutine(T&& r) noexcept
|
||||
: base_t(std::forward<T>(r)), error_handler(detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
if (!is_function<meta::unqualified_t<T>>::value) {
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_coroutine>(lua_state(), -1, handler);
|
||||
}
|
||||
#endif // Safety
|
||||
|
@ -112,11 +115,9 @@ namespace sol {
|
|||
basic_coroutine(basic_function<base_t>&& b)
|
||||
: basic_coroutine(std::move(b), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(b.lua_state())) {
|
||||
}
|
||||
basic_coroutine(const basic_function<base_t>& b, handler_t eh)
|
||||
: base_t(b), error_handler(std::move(eh)) {
|
||||
basic_coroutine(const basic_function<base_t>& b, handler_t eh) : base_t(b), error_handler(std::move(eh)) {
|
||||
}
|
||||
basic_coroutine(basic_function<base_t>&& b, handler_t eh)
|
||||
: base_t(std::move(b)), error_handler(std::move(eh)) {
|
||||
basic_coroutine(basic_function<base_t>&& b, handler_t eh) : base_t(std::move(b)), error_handler(std::move(eh)) {
|
||||
}
|
||||
basic_coroutine(const stack_reference& r)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
|
@ -124,11 +125,9 @@ namespace sol {
|
|||
basic_coroutine(stack_reference&& r)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
|
||||
}
|
||||
basic_coroutine(const stack_reference& r, handler_t eh)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
basic_coroutine(const stack_reference& r, handler_t eh) : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
}
|
||||
basic_coroutine(stack_reference&& r, handler_t eh)
|
||||
: basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
basic_coroutine(stack_reference&& r, handler_t eh) : basic_coroutine(r.lua_state(), r.stack_index(), std::move(eh)) {
|
||||
}
|
||||
|
||||
template <typename Super>
|
||||
|
@ -139,9 +138,9 @@ namespace sol {
|
|||
basic_coroutine(proxy_base<Super>&& p)
|
||||
: basic_coroutine(std::move(p), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(p.lua_state())) {
|
||||
}
|
||||
template <typename Proxy, typename Handler, meta::enable<std::is_base_of<proxy_base_tag, meta::unqualified_t<Proxy>>, meta::neg<is_lua_index<meta::unqualified_t<Handler>>>> = meta::enabler>
|
||||
basic_coroutine(Proxy&& p, Handler&& eh)
|
||||
: basic_coroutine(detail::force_cast<base_t>(p), std::forward<Handler>(eh)) {
|
||||
template <typename Proxy, typename Handler,
|
||||
meta::enable<std::is_base_of<proxy_base_tag, meta::unqualified_t<Proxy>>, meta::neg<is_lua_index<meta::unqualified_t<Handler>>>> = meta::enabler>
|
||||
basic_coroutine(Proxy&& p, Handler&& eh) : basic_coroutine(detail::force_cast<base_t>(p), std::forward<Handler>(eh)) {
|
||||
}
|
||||
|
||||
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
|
@ -149,57 +148,51 @@ namespace sol {
|
|||
: basic_coroutine(L, std::forward<T>(r), detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_coroutine(lua_State* L, T&& r, handler_t eh)
|
||||
: base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
|
||||
basic_coroutine(lua_State* L, T&& r, handler_t eh) : base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_coroutine>(lua_state(), -1, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
|
||||
basic_coroutine(lua_nil_t n)
|
||||
: base_t(n), error_handler(n) {
|
||||
basic_coroutine(lua_nil_t n) : base_t(n), error_handler(n) {
|
||||
}
|
||||
|
||||
basic_coroutine(lua_State* L, int index = -1)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, int index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
basic_coroutine(lua_State* L, int index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) {
|
||||
#ifdef SOL_SAFE_REFERENCES
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_coroutine>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_coroutine(lua_State* L, absolute_index index)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, absolute_index index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
basic_coroutine(lua_State* L, absolute_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_coroutine>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_coroutine(lua_State* L, raw_index index)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, raw_index index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
basic_coroutine(lua_State* L, raw_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_coroutine>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_coroutine(lua_State* L, ref_index index)
|
||||
: basic_coroutine(L, index, detail::get_default_handler<reference, is_main_threaded<base_t>::value>(L)) {
|
||||
}
|
||||
basic_coroutine(lua_State* L, ref_index index, handler_t eh)
|
||||
: base_t(L, index), error_handler(std::move(eh)) {
|
||||
basic_coroutine(lua_State* L, ref_index index, handler_t eh) : base_t(L, index), error_handler(std::move(eh)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_coroutine>(lua_state(), -1, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
|
@ -214,8 +207,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
bool runnable() const noexcept {
|
||||
return base_t::valid()
|
||||
&& (status() == call_status::yielded);
|
||||
return base_t::valid() && (status() == call_status::yielded);
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept {
|
||||
|
|
|
@ -28,16 +28,15 @@
|
|||
#include <string>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#if defined(__GNUC__) && defined(__MINGW32__) && (__GNUC__ < 6)
|
||||
#if SOL_IS_ON(SOL_MINGW_CCTYPE_IS_POISONED_I_)
|
||||
extern "C" {
|
||||
#include <ctype.h>
|
||||
}
|
||||
#endif // MinGW is on some stuff
|
||||
#include <locale>
|
||||
|
||||
namespace sol {
|
||||
namespace detail {
|
||||
inline constexpr std::array<string_view, 9> removals{ { "{anonymous}",
|
||||
namespace sol { namespace detail {
|
||||
inline constexpr std::array<string_view, 9> removals { { "{anonymous}",
|
||||
"(anonymous namespace)",
|
||||
"public:",
|
||||
"private:",
|
||||
|
@ -48,7 +47,7 @@ namespace detail {
|
|||
"`anonymous namespace'" } };
|
||||
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if SOL_IS_ON(SOL_COMPILER_GCC_I_) || SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
inline std::string ctti_get_type_name_from_sig(std::string name) {
|
||||
// cardinal sins from MINGW
|
||||
using namespace std;
|
||||
|
@ -86,7 +85,7 @@ namespace detail {
|
|||
inline std::string ctti_get_type_name() {
|
||||
return ctti_get_type_name_from_sig(__PRETTY_FUNCTION__);
|
||||
}
|
||||
#elif defined(_MSC_VER)
|
||||
#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
inline std::string ctti_get_type_name_from_sig(std::string name) {
|
||||
std::size_t start = name.find("get_type_name");
|
||||
if (start == std::string::npos)
|
||||
|
@ -135,7 +134,9 @@ namespace detail {
|
|||
|
||||
inline std::string short_demangle_from_type_name(std::string realname) {
|
||||
// This isn't the most complete but it'll do for now...?
|
||||
static const std::array<std::string, 10> ops = {{"operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*"}};
|
||||
static const std::array<std::string, 10> ops = {
|
||||
{ "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" }
|
||||
};
|
||||
int level = 0;
|
||||
std::ptrdiff_t idx = 0;
|
||||
for (idx = static_cast<std::ptrdiff_t>(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) {
|
||||
|
@ -186,7 +187,6 @@ namespace detail {
|
|||
static const std::string d = short_demangle_once<T>();
|
||||
return d;
|
||||
}
|
||||
}
|
||||
} // namespace sol::detail
|
||||
}} // namespace sol::detail
|
||||
|
||||
#endif // SOL_DEMANGLE_HPP
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// sol3
|
||||
// sol3
|
||||
|
||||
// The MIT License (MIT)
|
||||
|
||||
|
@ -41,19 +41,15 @@ namespace sol {
|
|||
basic_environment(basic_environment&&) = default;
|
||||
basic_environment& operator=(const basic_environment&) = default;
|
||||
basic_environment& operator=(basic_environment&&) = default;
|
||||
basic_environment(const stack_reference& r)
|
||||
: basic_environment(r.lua_state(), r.stack_index()) {
|
||||
basic_environment(const stack_reference& r) : basic_environment(r.lua_state(), r.stack_index()) {
|
||||
}
|
||||
basic_environment(stack_reference&& r)
|
||||
: basic_environment(r.lua_state(), r.stack_index()) {
|
||||
basic_environment(stack_reference&& r) : basic_environment(r.lua_state(), r.stack_index()) {
|
||||
}
|
||||
|
||||
basic_environment(lua_State* L, new_table nt)
|
||||
: base_t(L, std::move(nt)) {
|
||||
basic_environment(lua_State* L, new_table nt) : base_t(L, std::move(nt)) {
|
||||
}
|
||||
template <bool b>
|
||||
basic_environment(lua_State* L, new_table t, const basic_reference<b>& fallback)
|
||||
: basic_environment(L, std::move(t)) {
|
||||
basic_environment(lua_State* L, new_table t, const basic_reference<b>& fallback) : basic_environment(L, std::move(t)) {
|
||||
stack_table mt(L, new_table(0, 1));
|
||||
mt.set(meta_function::index, fallback);
|
||||
this->set(metatable_key, mt);
|
||||
|
@ -63,7 +59,7 @@ namespace sol {
|
|||
basic_environment(env_key_t, const stack_reference& extraction_target)
|
||||
: base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<env_key_t>(this->lua_state(), -1, handler);
|
||||
#endif // Safety
|
||||
lua_pop(this->lua_state(), 2);
|
||||
|
@ -72,48 +68,45 @@ namespace sol {
|
|||
basic_environment(env_key_t, const basic_reference<b>& extraction_target)
|
||||
: base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<env_key_t>(this->lua_state(), -1, handler);
|
||||
#endif // Safety
|
||||
lua_pop(this->lua_state(), 2);
|
||||
}
|
||||
basic_environment(lua_State* L, int index = -1)
|
||||
: base_t(detail::no_safety, L, index) {
|
||||
basic_environment(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_environment>(L, index, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
basic_environment(lua_State* L, ref_index index)
|
||||
: base_t(detail::no_safety, L, index) {
|
||||
basic_environment(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_environment>(L, -1, handler);
|
||||
#endif // Safety
|
||||
}
|
||||
template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_environment>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_environment(T&& r) noexcept
|
||||
: base_t(detail::no_safety, std::forward<T>(r)) {
|
||||
template <typename T,
|
||||
meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_environment>>, meta::neg<std::is_same<base_type, stack_reference>>,
|
||||
meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_environment(T&& r) noexcept : base_t(detail::no_safety, std::forward<T>(r)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
if (!is_environment<meta::unqualified_t<T>>::value) {
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_environment>(lua_state(), -1, handler);
|
||||
}
|
||||
#endif // Safety
|
||||
}
|
||||
basic_environment(lua_nil_t r) noexcept
|
||||
: base_t(detail::no_safety, r) {
|
||||
basic_environment(lua_nil_t r) noexcept : base_t(detail::no_safety, r) {
|
||||
}
|
||||
|
||||
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
|
||||
basic_environment(lua_State* L, T&& r) noexcept
|
||||
: base_t(detail::no_safety, L, std::forward<T>(r)) {
|
||||
basic_environment(lua_State* L, T&& r) noexcept : base_t(detail::no_safety, L, std::forward<T>(r)) {
|
||||
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
|
||||
if (!is_environment<meta::unqualified_t<T>>::value) {
|
||||
auto pp = stack::push_pop(*this);
|
||||
constructor_handler handler{};
|
||||
constructor_handler handler {};
|
||||
stack::check<basic_environment>(lua_state(), -1, handler);
|
||||
}
|
||||
#endif // Safety
|
||||
|
@ -123,7 +116,7 @@ namespace sol {
|
|||
void set_on(const T& target) const {
|
||||
lua_State* L = target.lua_state();
|
||||
auto pp = stack::push_pop(target);
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
// Use lua_setfenv
|
||||
this->push();
|
||||
lua_setfenv(L, -2);
|
||||
|
@ -153,11 +146,9 @@ namespace sol {
|
|||
struct this_environment {
|
||||
optional<environment> env;
|
||||
|
||||
this_environment()
|
||||
: env(nullopt) {
|
||||
this_environment() : env(nullopt) {
|
||||
}
|
||||
this_environment(environment e)
|
||||
: env(std::move(e)) {
|
||||
this_environment(environment e) : env(std::move(e)) {
|
||||
}
|
||||
this_environment(const this_environment&) = default;
|
||||
this_environment(this_environment&&) = default;
|
||||
|
@ -168,11 +159,11 @@ namespace sol {
|
|||
return static_cast<bool>(env);
|
||||
}
|
||||
|
||||
operator optional<environment>&() {
|
||||
operator optional<environment> &() {
|
||||
return env;
|
||||
}
|
||||
|
||||
operator const optional<environment>&() const {
|
||||
operator const optional<environment> &() const {
|
||||
return env;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,18 @@ namespace sol {
|
|||
load_status err;
|
||||
|
||||
public:
|
||||
load_result() = default;
|
||||
load_result() noexcept = default;
|
||||
load_result(lua_State* Ls, int stackindex = -1, int retnum = 0, int popnum = 0, load_status lerr = load_status::ok) noexcept
|
||||
: L(Ls), index(stackindex), returncount(retnum), popcount(popnum), err(lerr) {
|
||||
}
|
||||
load_result(const load_result&) = default;
|
||||
load_result& operator=(const load_result&) = default;
|
||||
|
||||
// We do not want anyone to copy these around willy-nilly
|
||||
// Will likely break people, but also will probably get rid of quiet bugs that have
|
||||
// been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops:
|
||||
// LuaJIT and other Lua engines will implode and segfault at random later times.)
|
||||
load_result(const load_result&) = delete;
|
||||
load_result& operator=(const load_result&) = delete;
|
||||
|
||||
load_result(load_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) {
|
||||
// Must be manual, otherwise destructor will screw us
|
||||
// return count being 0 is enough to keep things clean
|
||||
|
|
|
@ -54,12 +54,18 @@ namespace sol {
|
|||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
protected_function_result() = default;
|
||||
protected_function_result() noexcept = default;
|
||||
protected_function_result(lua_State* Ls, int idx = -1, int retnum = 0, int popped = 0, call_status pferr = call_status::ok) noexcept
|
||||
: L(Ls), index(idx), returncount(retnum), popcount(popped), err(pferr) {
|
||||
}
|
||||
protected_function_result(const protected_function_result&) = default;
|
||||
protected_function_result& operator=(const protected_function_result&) = default;
|
||||
|
||||
// We do not want anyone to copy these around willy-nilly
|
||||
// Will likely break people, but also will probably get rid of quiet bugs that have
|
||||
// been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops:
|
||||
// LuaJIT and other Lua engines will implode and segfault at random later times.)
|
||||
protected_function_result(const protected_function_result&) = delete;
|
||||
protected_function_result& operator=(const protected_function_result&) = delete;
|
||||
|
||||
protected_function_result(protected_function_result&& o) noexcept
|
||||
: L(o.L), index(o.index), returncount(o.returncount), popcount(o.popcount), err(o.err) {
|
||||
// Must be manual, otherwise destructor will screw us
|
||||
|
|
|
@ -68,8 +68,7 @@ namespace sol {
|
|||
lua_State* L;
|
||||
int index;
|
||||
int count;
|
||||
push_popper_at(lua_State* luastate, int index = -1, int count = 1)
|
||||
: L(luastate), index(index), count(count) {
|
||||
push_popper_at(lua_State* luastate, int index = -1, int count = 1) : L(luastate), index(index), count(count) {
|
||||
}
|
||||
~push_popper_at() {
|
||||
remove(L, index, count);
|
||||
|
@ -80,8 +79,7 @@ namespace sol {
|
|||
struct push_popper_n {
|
||||
lua_State* L;
|
||||
int t;
|
||||
push_popper_n(lua_State* luastate, int x)
|
||||
: L(luastate), t(x) {
|
||||
push_popper_n(lua_State* luastate, int x) : L(luastate), t(x) {
|
||||
}
|
||||
push_popper_n(const push_popper_n&) = delete;
|
||||
push_popper_n(push_popper_n&&) = default;
|
||||
|
@ -91,7 +89,7 @@ namespace sol {
|
|||
lua_pop(L, t);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct push_popper_n<true> {
|
||||
push_popper_n(lua_State*, int) {
|
||||
|
@ -104,9 +102,7 @@ namespace sol {
|
|||
T t;
|
||||
int idx;
|
||||
|
||||
push_popper(T x)
|
||||
: t(x), idx(lua_absindex(t.lua_state(), -t.push())) {
|
||||
|
||||
push_popper(T x) : t(x), idx(lua_absindex(t.lua_state(), -t.push())) {
|
||||
}
|
||||
|
||||
int index_of(const Tu&) {
|
||||
|
@ -132,11 +128,11 @@ namespace sol {
|
|||
~push_popper() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct push_popper<false, T, std::enable_if_t<is_stack_based_v<meta::unqualified_t<T>>>> {
|
||||
using Tu = meta::unqualified_t<T>;
|
||||
|
||||
|
||||
push_popper(T) {
|
||||
}
|
||||
|
||||
|
@ -159,7 +155,7 @@ namespace sol {
|
|||
lua_State* L = x.lua_state();
|
||||
return push_popper_at(L, lua_absindex(L, -c), c);
|
||||
}
|
||||
|
||||
|
||||
template <bool top_level = false>
|
||||
push_popper_n<top_level> pop_n(lua_State* L, int x) {
|
||||
return push_popper_n<top_level>(L, x);
|
||||
|
@ -167,7 +163,7 @@ namespace sol {
|
|||
} // namespace stack
|
||||
|
||||
inline lua_State* main_thread(lua_State* L, lua_State* backup_if_unsupported = nullptr) {
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
if (L == nullptr)
|
||||
return backup_if_unsupported;
|
||||
lua_getglobal(L, detail::default_main_thread_name());
|
||||
|
@ -235,7 +231,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
protected:
|
||||
int stack_index () const noexcept {
|
||||
int stack_index() const noexcept {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -319,8 +315,7 @@ namespace sol {
|
|||
stateless_reference(const stateless_reference& o) noexcept = delete;
|
||||
stateless_reference& operator=(const stateless_reference& r) noexcept = delete;
|
||||
|
||||
stateless_reference(stateless_reference&& o) noexcept
|
||||
: ref(o.ref) {
|
||||
stateless_reference(stateless_reference&& o) noexcept : ref(o.ref) {
|
||||
o.ref = LUA_NOREF;
|
||||
}
|
||||
|
||||
|
@ -437,8 +432,7 @@ namespace sol {
|
|||
: basic_reference(detail::pick_main_thread<main_only>(L, L), detail::global_, detail::global_) {
|
||||
}
|
||||
|
||||
basic_reference(lua_State* L, detail::global_tag, detail::global_tag) noexcept
|
||||
: stateless_reference(L, detail::global_), luastate(L) {
|
||||
basic_reference(lua_State* L, detail::global_tag, detail::global_tag) noexcept : stateless_reference(L, detail::global_), luastate(L) {
|
||||
}
|
||||
|
||||
basic_reference(lua_State* oL, const basic_reference<!main_only>& o) noexcept : stateless_reference(oL, o), luastate(oL) {
|
||||
|
@ -458,18 +452,14 @@ namespace sol {
|
|||
|
||||
public:
|
||||
basic_reference() noexcept = default;
|
||||
basic_reference(lua_nil_t) noexcept
|
||||
: basic_reference() {
|
||||
basic_reference(lua_nil_t) noexcept : basic_reference() {
|
||||
}
|
||||
basic_reference(const stack_reference& r) noexcept
|
||||
: basic_reference(r.lua_state(), r.stack_index()) {
|
||||
basic_reference(const stack_reference& r) noexcept : basic_reference(r.lua_state(), r.stack_index()) {
|
||||
}
|
||||
basic_reference(stack_reference&& r) noexcept
|
||||
: basic_reference(r.lua_state(), r.stack_index()) {
|
||||
basic_reference(stack_reference&& r) noexcept : basic_reference(r.lua_state(), r.stack_index()) {
|
||||
}
|
||||
template <bool r_main_only>
|
||||
basic_reference(lua_State* L, const basic_reference<r_main_only>& r) noexcept
|
||||
: luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
basic_reference(lua_State* L, const basic_reference<r_main_only>& r) noexcept : luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
if (r.ref == LUA_REFNIL) {
|
||||
ref = LUA_REFNIL;
|
||||
return;
|
||||
|
@ -487,8 +477,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
template <bool r_main_only>
|
||||
basic_reference(lua_State* L, basic_reference<r_main_only>&& r) noexcept
|
||||
: luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
basic_reference(lua_State* L, basic_reference<r_main_only>&& r) noexcept : luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
if (r.ref == LUA_REFNIL) {
|
||||
ref = LUA_REFNIL;
|
||||
return;
|
||||
|
@ -507,8 +496,7 @@ namespace sol {
|
|||
r.luastate = nullptr;
|
||||
}
|
||||
|
||||
basic_reference(lua_State* L, const stack_reference& r) noexcept
|
||||
: luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
basic_reference(lua_State* L, const stack_reference& r) noexcept : luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
if (lua_state() == nullptr || r.lua_state() == nullptr || r.get_type() == type::none) {
|
||||
ref = LUA_NOREF;
|
||||
return;
|
||||
|
@ -523,8 +511,7 @@ namespace sol {
|
|||
r.push(lua_state());
|
||||
ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
|
||||
}
|
||||
basic_reference(lua_State* L, int index = -1) noexcept
|
||||
: luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
basic_reference(lua_State* L, int index = -1) noexcept : luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
// use L to stick with that state's execution stack
|
||||
#if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_)
|
||||
luaL_checkstack(L, 1, "not enough Lua stack space to push this reference value");
|
||||
|
@ -532,13 +519,11 @@ namespace sol {
|
|||
lua_pushvalue(L, index);
|
||||
ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
basic_reference(lua_State* L, ref_index index) noexcept
|
||||
: luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
basic_reference(lua_State* L, ref_index index) noexcept : luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
lua_rawgeti(lua_state(), LUA_REGISTRYINDEX, index.index);
|
||||
ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX);
|
||||
}
|
||||
basic_reference(lua_State* L, lua_nil_t) noexcept
|
||||
: luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
basic_reference(lua_State* L, lua_nil_t) noexcept : luastate(detail::pick_main_thread<main_only>(L, L)) {
|
||||
}
|
||||
|
||||
~basic_reference() noexcept {
|
||||
|
@ -547,12 +532,10 @@ namespace sol {
|
|||
deref();
|
||||
}
|
||||
|
||||
basic_reference(const basic_reference& o) noexcept
|
||||
: stateless_reference(o.copy()), luastate(o.lua_state()) {
|
||||
basic_reference(const basic_reference& o) noexcept : stateless_reference(o.copy()), luastate(o.lua_state()) {
|
||||
}
|
||||
|
||||
basic_reference(basic_reference&& o) noexcept
|
||||
: stateless_reference(std::move(o)), luastate(o.lua_state()) {
|
||||
basic_reference(basic_reference&& o) noexcept : stateless_reference(std::move(o)), luastate(o.lua_state()) {
|
||||
o.luastate = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,27 +22,28 @@
|
|||
#ifndef SOL_HPP
|
||||
#define SOL_HPP
|
||||
|
||||
#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER)
|
||||
#define SOL_INSIDE_UNREAL
|
||||
#include <sol/version.hpp>
|
||||
|
||||
#if SOL_IS_ON(SOL_INSIDE_UNREAL_ENGINE_I_)
|
||||
#ifdef check
|
||||
#pragma push_macro("check")
|
||||
#undef check
|
||||
#endif
|
||||
#endif // Unreal Engine 4 Bullshit
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if SOL_IS_ON(SOL_COMPILER_GCC_I_)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#if __GNUC__ > 6
|
||||
#pragma GCC diagnostic ignored "-Wnoexcept-type"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#elif SOL_IS_ON(SOL_COMPILER_CLANG_I_)
|
||||
// we'll just let this alone for now
|
||||
#elif defined _MSC_VER
|
||||
#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4505) // unreferenced local function has been removed GEE THANKS
|
||||
#endif // clang++ vs. g++ vs. VC++
|
||||
#endif // clang++ vs. g++ vs. VC++
|
||||
|
||||
#include <sol/forward.hpp>
|
||||
#include <sol/forward_detail.hpp>
|
||||
|
@ -63,13 +64,13 @@
|
|||
#include <sol/variadic_results.hpp>
|
||||
#include <sol/lua_value.hpp>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if SOL_IS_ON(SOL_COMPILER_GCC_I_)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined _MSC_VER
|
||||
#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_)
|
||||
#pragma warning(pop)
|
||||
#endif // g++
|
||||
|
||||
#if defined(SOL_INSIDE_UNREAL)
|
||||
#if SOL_IS_ON(SOL_INSIDE_UNREAL_ENGINE_I_)
|
||||
#undef check
|
||||
#pragma pop_macro("check")
|
||||
#endif // Unreal Engine 4 Bullshit
|
||||
|
|
|
@ -272,7 +272,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
inline void luajit_exception_handler(lua_State* L, int (*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) {
|
||||
#if defined(SOL_LUAJIT) && (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION))
|
||||
#if SOL_IS_ON(SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_)
|
||||
if (L == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
inline void luajit_exception_off(lua_State* L) {
|
||||
#if defined(SOL_LUAJIT)
|
||||
#if SOL_IS_ON(SOL_USE_LUAJIT_EXCEPTION_TRAMPOLINE_I_)
|
||||
if (L == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace sol { namespace stack {
|
|||
return stack_detail::unchecked_get<T>(L, index, tracking);
|
||||
}
|
||||
else if constexpr ((std::is_integral_v<T> || std::is_same_v<T, lua_Integer>)&&!std::is_same_v<T, bool>) {
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
if (lua_isinteger(L, index) != 0) {
|
||||
tracking.use(1);
|
||||
return static_cast<T>(lua_tointeger(L, index));
|
||||
|
@ -67,7 +67,7 @@ namespace sol { namespace stack {
|
|||
int isnum = 0;
|
||||
const lua_Number value = lua_tonumberx(L, index, &isnum);
|
||||
if (isnum != 0) {
|
||||
#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
|
||||
#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_)
|
||||
const auto integer_value = llround(value);
|
||||
if (static_cast<lua_Number>(integer_value) == value) {
|
||||
tracking.use(1);
|
||||
|
|
|
@ -105,8 +105,10 @@ namespace sol { namespace stack {
|
|||
}
|
||||
else if constexpr (std::is_integral_v<T> || std::is_same_v<T, lua_Integer>) {
|
||||
tracking.use(1);
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
// Lua 5.3 and greater checks for numeric precision
|
||||
#if SOL_IS_ON(SOL_STRINGS_ARE_NUMBERS_I_)
|
||||
// imprecise, sloppy conversions
|
||||
int isnum = 0;
|
||||
lua_tointegerx(L, index, &isnum);
|
||||
const bool success = isnum != 0;
|
||||
|
@ -114,8 +116,8 @@ namespace sol { namespace stack {
|
|||
// expected type, actual type
|
||||
handler(L, index, type::number, type_of(L, index), detail::not_a_number_or_number_string_integral);
|
||||
}
|
||||
#elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
|
||||
// this check is precise, does not convert
|
||||
#elif SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_)
|
||||
// this check is precise, do not convert
|
||||
if (lua_isinteger(L, index) == 1) {
|
||||
return true;
|
||||
}
|
||||
|
@ -125,16 +127,18 @@ namespace sol { namespace stack {
|
|||
handler(L, index, type::number, type_of(L, index), detail::not_a_number_integral);
|
||||
}
|
||||
#else
|
||||
// Numerics are neither safe nor string-convertible
|
||||
type t = type_of(L, index);
|
||||
const bool success = t == type::number;
|
||||
#endif // If numbers are enabled, use the imprecise check
|
||||
#endif
|
||||
if (!success) {
|
||||
// expected type, actual type
|
||||
handler(L, index, type::number, type_of(L, index), detail::not_a_number);
|
||||
}
|
||||
return success;
|
||||
#else
|
||||
#if !defined(SOL_STRINGS_ARE_NUMBERS) || !SOL_STRINGS_ARE_NUMBERS
|
||||
// Lua 5.2 and below checks
|
||||
#if SOL_IS_OFF(SOL_STRINGS_ARE_NUMBERS_I_)
|
||||
// must pre-check, because it will convert
|
||||
type t = type_of(L, index);
|
||||
if (t != type::number) {
|
||||
|
@ -143,7 +147,8 @@ namespace sol { namespace stack {
|
|||
return false;
|
||||
}
|
||||
#endif // Do not allow strings to be numbers
|
||||
#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
|
||||
|
||||
#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_)
|
||||
int isnum = 0;
|
||||
const lua_Number v = lua_tonumberx(L, index, &isnum);
|
||||
const bool success = isnum != 0 && static_cast<lua_Number>(llround(v)) == v;
|
||||
|
@ -151,17 +156,17 @@ namespace sol { namespace stack {
|
|||
const bool success = true;
|
||||
#endif // Safe numerics and number precision checking
|
||||
if (!success) {
|
||||
// expected type, actual type
|
||||
// Use defines to provide a better error message!
|
||||
#if SOL_IS_ON(SOL_STRINGS_ARE_NUMBERS_I_)
|
||||
handler(L, index, type::number, type_of(L, index), detail::not_a_number_or_number_string);
|
||||
#elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS)
|
||||
#elif SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_)
|
||||
handler(L, index, type::number, t, detail::not_a_number_or_number_string);
|
||||
#else
|
||||
handler(L, index, type::number, t, detail::not_a_number);
|
||||
#endif
|
||||
}
|
||||
return success;
|
||||
#endif // Lua Version 5.3 versus others
|
||||
#endif
|
||||
}
|
||||
else if constexpr (std::is_floating_point_v<T> || std::is_same_v<T, lua_Number>) {
|
||||
tracking.use(1);
|
||||
|
@ -461,7 +466,7 @@ namespace sol { namespace stack {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct unqualified_checker<non_null<T>, type::userdata> : unqualified_checker<T, lua_type_of_v<T>> {};
|
||||
struct unqualified_checker<non_null<T>, type::userdata> : unqualified_checker<T, lua_type_of_v<T>> { };
|
||||
|
||||
template <typename T>
|
||||
struct unqualified_checker<detail::as_value_tag<T>, type::userdata> {
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace sol { namespace stack {
|
|||
template <typename T, bool global, bool raw, typename>
|
||||
struct field_getter {
|
||||
static constexpr int default_table_index = meta::conditional_t < meta::is_c_str_v<T>
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
|| (std::is_integral_v<T> && !std::is_same_v<T, bool>)
|
||||
#endif // integer global keys 5.3 or better
|
||||
|| (raw && std::is_void_v<std::remove_pointer_t<T>>),
|
||||
std::integral_constant<int, -1>, std::integral_constant<int, -2>> ::value;
|
||||
std::integral_constant<int, -1>, std::integral_constant<int, -2> > ::value;
|
||||
|
||||
template <typename Key>
|
||||
void get(lua_State* L, Key&& key, int tableindex = default_table_index) {
|
||||
|
@ -48,7 +48,7 @@ namespace sol { namespace stack {
|
|||
}
|
||||
else if constexpr (std::is_same_v<T, env_key_t>) {
|
||||
(void)key;
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
// Use lua_setfenv
|
||||
lua_getfenv(L, tableindex);
|
||||
#else
|
||||
|
@ -67,7 +67,7 @@ namespace sol { namespace stack {
|
|||
if constexpr (std::is_integral_v<T> && !std::is_same_v<bool, T>) {
|
||||
lua_rawgeti(L, tableindex, static_cast<lua_Integer>(key));
|
||||
}
|
||||
#if SOL_LUA_VERSION >= 502
|
||||
#if SOL_LUA_VESION_I_ >= 502
|
||||
else if constexpr (std::is_void_v<std::remove_pointer_t<T>>) {
|
||||
lua_rawgetp(L, tableindex, key);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ namespace sol { namespace stack {
|
|||
lua_getfield(L, tableindex, &key[0]);
|
||||
}
|
||||
}
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
else if constexpr (std::is_integral_v<T> && !std::is_same_v<bool, T>) {
|
||||
lua_geti(L, tableindex, static_cast<lua_Integer>(key));
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ namespace sol { namespace stack {
|
|||
template <std::size_t... I, typename Keys>
|
||||
void apply(std::index_sequence<0, I...>, lua_State* L, Keys&& keys, int tableindex) {
|
||||
get_field<b, raw>(L, std::get<0>(std::forward<Keys>(keys)), tableindex);
|
||||
void(detail::swallow{ (get_field<false, raw>(L, std::get<I>(std::forward<Keys>(keys))), 0)... });
|
||||
void(detail::swallow { (get_field<false, raw>(L, std::get<I>(std::forward<Keys>(keys))), 0)... });
|
||||
reference saved(L, -1);
|
||||
lua_pop(L, static_cast<int>(sizeof...(I)));
|
||||
saved.push();
|
||||
|
@ -148,7 +148,7 @@ namespace sol { namespace stack {
|
|||
static constexpr int default_table_index
|
||||
= meta::conditional_t < (meta::is_c_str_v<T> || meta::is_string_of_v<T, char>) || (std::is_integral_v<T> && !std::is_same_v<T, bool>)
|
||||
|| (std::is_integral_v<T> && !std::is_same_v<T, bool>) || (raw && std::is_void_v<std::remove_pointer_t<T>>),
|
||||
std::integral_constant<int, -2>, std::integral_constant<int, -3>> ::value;
|
||||
std::integral_constant<int, -2>, std::integral_constant<int, -3> > ::value;
|
||||
|
||||
template <typename Key, typename Value>
|
||||
void set(lua_State* L, Key&& key, Value&& value, int tableindex = default_table_index) {
|
||||
|
@ -168,7 +168,7 @@ namespace sol { namespace stack {
|
|||
push(L, std::forward<Value>(value));
|
||||
lua_rawseti(L, tableindex, static_cast<lua_Integer>(key));
|
||||
}
|
||||
#if SOL_LUA_VERSION >= 502
|
||||
#if SOL_LUA_VESION_I_ >= 502
|
||||
else if constexpr (std::is_void_v<std::remove_pointer_t<T>>) {
|
||||
push(L, std::forward<Value>(value));
|
||||
lua_rawsetp(L, tableindex, std::forward<Key>(key));
|
||||
|
@ -192,7 +192,7 @@ namespace sol { namespace stack {
|
|||
lua_setfield(L, tableindex, &key[0]);
|
||||
}
|
||||
}
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
else if constexpr (std::is_integral_v<T> && !std::is_same_v<bool, T>) {
|
||||
push(L, std::forward<Value>(value));
|
||||
lua_seti(L, tableindex, static_cast<lua_Integer>(key));
|
||||
|
|
|
@ -127,7 +127,7 @@ namespace sol { namespace stack {
|
|||
}
|
||||
else if constexpr (std::is_integral_v<T> || std::is_same_v<T, lua_Integer>) {
|
||||
tracking.use(1);
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
if (lua_isinteger(L, index) != 0) {
|
||||
return static_cast<T>(lua_tointeger(L, index));
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ namespace sol { namespace stack {
|
|||
int index = lua_absindex(L, relindex);
|
||||
T cont;
|
||||
std::size_t idx = 0;
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
// This method is HIGHLY performant over regular table iteration
|
||||
// thanks to the Lua API changes in 5.3
|
||||
// Questionable in 5.4
|
||||
|
@ -337,7 +337,7 @@ namespace sol { namespace stack {
|
|||
}
|
||||
bool isnil = false;
|
||||
for (int vi = 0; vi < lua_size<V>::value; ++vi) {
|
||||
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600
|
||||
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600
|
||||
#if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_)
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
#endif // make sure stack doesn't overflow
|
||||
|
@ -358,7 +358,7 @@ namespace sol { namespace stack {
|
|||
if (i == 0) {
|
||||
break;
|
||||
}
|
||||
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600
|
||||
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600
|
||||
lua_pop(L, vi);
|
||||
#else
|
||||
lua_pop(L, (vi + 1));
|
||||
|
@ -368,7 +368,7 @@ namespace sol { namespace stack {
|
|||
}
|
||||
}
|
||||
if (isnil) {
|
||||
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VERSION >= 600
|
||||
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600
|
||||
#else
|
||||
lua_pop(L, lua_size<V>::value);
|
||||
#endif
|
||||
|
@ -476,7 +476,7 @@ namespace sol { namespace stack {
|
|||
C cont;
|
||||
auto at = cont.cbefore_begin();
|
||||
std::size_t idx = 0;
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
// This method is HIGHLY performant over regular table iteration thanks to the Lua API changes in 5.3
|
||||
for (lua_Integer i = 0;; i += lua_size<V>::value, lua_pop(L, lua_size<V>::value)) {
|
||||
if (idx >= cont.max_size()) {
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace sol { namespace stack {
|
|||
#if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_)
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_environment);
|
||||
#endif // make sure stack doesn't overflow
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
// Use lua_getfenv
|
||||
lua_getfenv(L, index);
|
||||
#else
|
||||
|
@ -265,13 +265,13 @@ namespace sol { namespace stack {
|
|||
#if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_)
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_integral);
|
||||
#endif // make sure stack doesn't overflow
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
if (stack_detail::integer_value_fits<Tu>(value)) {
|
||||
lua_pushinteger(L, static_cast<lua_Integer>(value));
|
||||
return 1;
|
||||
}
|
||||
#endif // Lua 5.3 and above
|
||||
#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
|
||||
#if SOL_IS_ON(SOL_NUMBER_PRECISION_CHECKS_I_)
|
||||
if (static_cast<T>(llround(static_cast<lua_Number>(value))) != value) {
|
||||
#if SOL_IS_OFF(SOL_EXCEPTIONS_I_)
|
||||
// Is this really worth it?
|
||||
|
@ -297,7 +297,7 @@ namespace sol { namespace stack {
|
|||
luaL_Stream* source { std::forward<Args>(args)... };
|
||||
luaL_Stream* stream = static_cast<luaL_Stream*>(lua_newuserdata(L, sizeof(luaL_Stream)));
|
||||
stream->f = source->f;
|
||||
#if !defined(SOL_LUAJIT) && (SOL_LUA_VERSION > 501)
|
||||
#if SOL_IS_ON(SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_)
|
||||
stream->closef = source->closef;
|
||||
#endif // LuaJIT and Lua 5.1 and below do not have
|
||||
return 1;
|
||||
|
@ -306,7 +306,7 @@ namespace sol { namespace stack {
|
|||
luaL_Stream& source(std::forward<Args>(args)...);
|
||||
luaL_Stream* stream = static_cast<luaL_Stream*>(lua_newuserdata(L, sizeof(luaL_Stream)));
|
||||
stream->f = source.f;
|
||||
#if !defined(SOL_LUAJIT) && (SOL_LUA_VERSION > 501)
|
||||
#if SOL_IS_ON(SOL_LUAL_STREAM_USE_CLOSE_FUNCTION_I_)
|
||||
stream->closef = source.closef;
|
||||
#endif // LuaJIT and Lua 5.1 and below do not have
|
||||
return 1;
|
||||
|
@ -376,7 +376,7 @@ namespace sol { namespace stack {
|
|||
int tableindex = lua_gettop(L);
|
||||
std::size_t index = 1;
|
||||
for (const auto& i : cont) {
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
#if SOL_LUA_VESION_I_ >= 503
|
||||
int p = is_nested ? stack::push(L, as_nested_ref(i)) : stack::push(L, i);
|
||||
for (int pi = 0; pi < p; ++pi) {
|
||||
lua_seti(L, tableindex, static_cast<lua_Integer>(index++));
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
namespace sol {
|
||||
inline void register_main_thread(lua_State* L) {
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
if (L == nullptr) {
|
||||
lua_pushnil(L);
|
||||
lua_setglobal(L, detail::default_main_thread_name());
|
||||
|
@ -120,7 +120,7 @@ namespace sol {
|
|||
std::string err = "sol: ";
|
||||
err += to_string(result.status());
|
||||
err += " error";
|
||||
#if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
|
||||
#if SOL_IS_ON(SOL_EXCEPTIONS_I_)
|
||||
std::exception_ptr eptr = std::current_exception();
|
||||
if (eptr) {
|
||||
err += " with a ";
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace sol {
|
|||
bool is53mod = loaded && !(loaded->is<bool>() && !loaded->as<bool>());
|
||||
if (is53mod)
|
||||
return loaded;
|
||||
#if SOL_LUA_VERSION <= 501
|
||||
#if SOL_LUA_VESION_I_ <= 501
|
||||
auto loaded51 = global.traverse_get<optional<object>>("package", "loaded", key);
|
||||
bool is51mod = loaded51 && !(loaded51->is<bool>() && !loaded51->as<bool>());
|
||||
if (is51mod)
|
||||
|
@ -57,7 +57,7 @@ namespace sol {
|
|||
|
||||
template <typename T>
|
||||
void ensure_package(const std::string& key, T&& sr) {
|
||||
#if SOL_LUA_VERSION <= 501
|
||||
#if SOL_LUA_VESION_I_ <= 501
|
||||
auto pkg = global["package"];
|
||||
if (!pkg.valid()) {
|
||||
pkg = create_table_with("loaded", create_table_with(key, sr));
|
||||
|
@ -120,7 +120,7 @@ namespace sol {
|
|||
|
||||
for (auto&& library : libraries) {
|
||||
switch (library) {
|
||||
#if SOL_LUA_VERSION <= 501 && defined(SOL_LUAJIT)
|
||||
#if SOL_LUA_VESION_I_ <= 501 && defined(SOL_LUAJIT)
|
||||
case lib::coroutine:
|
||||
#endif // luajit opens coroutine base stuff
|
||||
case lib::base:
|
||||
|
@ -133,7 +133,7 @@ namespace sol {
|
|||
break;
|
||||
#if !defined(SOL_LUAJIT)
|
||||
case lib::coroutine:
|
||||
#if SOL_LUA_VERSION > 501
|
||||
#if SOL_LUA_VESION_I_ > 501
|
||||
luaL_requiref(L, "coroutine", luaopen_coroutine, 1);
|
||||
lua_pop(L, 1);
|
||||
#endif // Lua 5.2+ only
|
||||
|
@ -155,7 +155,7 @@ namespace sol {
|
|||
#ifdef SOL_LUAJIT
|
||||
luaL_requiref(L, "bit32", luaopen_bit, 1);
|
||||
lua_pop(L, 1);
|
||||
#elif (SOL_LUA_VERSION == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2)
|
||||
#elif (SOL_LUA_VESION_I_ == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2)
|
||||
luaL_requiref(L, "bit32", luaopen_bit32, 1);
|
||||
lua_pop(L, 1);
|
||||
#else
|
||||
|
@ -174,7 +174,7 @@ namespace sol {
|
|||
lua_pop(L, 1);
|
||||
break;
|
||||
case lib::utf8:
|
||||
#if SOL_LUA_VERSION > 502 && !defined(SOL_LUAJIT)
|
||||
#if SOL_LUA_VESION_I_ > 502 && !defined(SOL_LUAJIT)
|
||||
luaL_requiref(L, "utf8", luaopen_utf8, 1);
|
||||
lua_pop(L, 1);
|
||||
#endif // Lua 5.3+ only
|
||||
|
@ -227,7 +227,7 @@ namespace sol {
|
|||
// one day Lua 5.1 will die a peaceful death
|
||||
// and its old bones will find blissful rest
|
||||
auto loaders_proxy = package
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
["loaders"]
|
||||
#else
|
||||
["searchers"]
|
||||
|
@ -255,7 +255,7 @@ namespace sol {
|
|||
// one day Lua 5.1 will die a peaceful death
|
||||
// and its old bones will find blissful rest
|
||||
auto loaders_proxy = package
|
||||
#if SOL_LUA_VERSION < 502
|
||||
#if SOL_LUA_VESION_I_ < 502
|
||||
["loaders"]
|
||||
#else
|
||||
["searchers"]
|
||||
|
@ -638,7 +638,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
bool supports_gc_mode(gc_mode mode) const noexcept {
|
||||
#if SOL_LUA_VERSION >= 504
|
||||
#if SOL_LUA_VESION_I_ >= 504
|
||||
// supports all modes
|
||||
(void)mode;
|
||||
return true;
|
||||
|
@ -647,7 +647,12 @@ namespace sol {
|
|||
}
|
||||
|
||||
bool is_gc_on() const {
|
||||
#if SOL_LUA_VESION_I_ >= 502
|
||||
return lua_gc(lua_state(), LUA_GCISRUNNING, 0) == 1;
|
||||
#else
|
||||
// You cannot turn it off in Lua 5.1
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void collect_garbage() {
|
||||
|
@ -662,7 +667,7 @@ namespace sol {
|
|||
// THOUGHT: std::chrono-alikes to map "kilobyte size" here...?
|
||||
// Make it harder to give MB or KB to a B parameter...?
|
||||
// Probably overkill for now.
|
||||
#if SOL_LUA_VERSION >= 504
|
||||
#if SOL_LUA_VESION_I_ >= 504
|
||||
// The manual implies that this function is almost always successful...
|
||||
// is it?? It could depend on the GC mode...
|
||||
return lua_gc(lua_state(), LUA_GCSTEP, step_size_kilobytes) != 0;
|
||||
|
@ -687,7 +692,7 @@ namespace sol {
|
|||
// THOUGHT: std::chrono-alikes to map "byte size" here...?
|
||||
// Make it harder to give MB or KB to a B parameter...?
|
||||
// Probably overkill for now.
|
||||
#if SOL_LUA_VERSION >= 504
|
||||
#if SOL_LUA_VESION_I_ >= 504
|
||||
int old_mode = lua_gc(lua_state(), LUA_GCINC, pause, step_multiplier, step_byte_size);
|
||||
if (old_mode == LUA_GCGEN) {
|
||||
return gc_mode::generational;
|
||||
|
@ -705,7 +710,7 @@ namespace sol {
|
|||
|
||||
// Returns the old GC mode. Check support using the supports_gc_mode function.
|
||||
gc_mode change_gc_mode_generational(int minor_multiplier, int major_multiplier) {
|
||||
#if SOL_LUA_VERSION >= 504
|
||||
#if SOL_LUA_VESION_I_ >= 504
|
||||
// "What does this shit mean?"
|
||||
// http://www.lua.org/manual/5.4/manual.html#2.5.2
|
||||
int old_mode = lua_gc(lua_state(), LUA_GCGEN, minor_multiplier, major_multiplier);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// sol3
|
||||
// sol3
|
||||
|
||||
// The MIT License (MIT)
|
||||
|
||||
|
@ -37,10 +37,10 @@ namespace sol {
|
|||
// must push a single object to be the error object
|
||||
// NOTE: the VAST MAJORITY of all Lua libraries -- C or otherwise -- expect a string for the type of error
|
||||
// break this convention at your own risk
|
||||
using exception_handler_function = int(*)(lua_State*, optional<const std::exception&>, string_view);
|
||||
using exception_handler_function = int (*)(lua_State*, optional<const std::exception&>, string_view);
|
||||
|
||||
namespace detail {
|
||||
inline const char(&default_exception_handler_name())[11]{
|
||||
inline const char (&default_exception_handler_name())[11] {
|
||||
static const char name[11] = "sol.\xE2\x98\xA2\xE2\x98\xA2";
|
||||
return name;
|
||||
}
|
||||
|
@ -72,13 +72,13 @@ namespace sol {
|
|||
return exfunc(L, std::move(maybe_ex), std::move(what));
|
||||
}
|
||||
|
||||
#ifdef SOL_NO_EXCEPTIONS
|
||||
#if SOL_IS_OFF(SOL_EXCEPTIONS_I_)
|
||||
template <lua_CFunction f>
|
||||
int static_trampoline(lua_State* L) noexcept {
|
||||
return f(L);
|
||||
}
|
||||
|
||||
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
|
||||
#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_)
|
||||
template <lua_CFunction_noexcept f>
|
||||
int static_trampoline_noexcept(lua_State* L) noexcept {
|
||||
return f(L);
|
||||
|
@ -100,8 +100,8 @@ namespace sol {
|
|||
}
|
||||
#else
|
||||
|
||||
inline int impl_static_trampoline(lua_State* L, lua_CFunction f) {
|
||||
#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT)
|
||||
inline int lua_cfunction_trampoline(lua_State* L, lua_CFunction f) {
|
||||
#if SOL_IS_ON(SOL_PROPAGATE_EXCEPTIONS_I_)
|
||||
return f(L);
|
||||
|
||||
#else
|
||||
|
@ -117,7 +117,7 @@ namespace sol {
|
|||
catch (const std::exception& e) {
|
||||
call_exception_handler(L, optional<const std::exception&>(e), e.what());
|
||||
}
|
||||
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
|
||||
#if SOL_IS_OFF(SOL_USE_LUAJIT_I_)
|
||||
// LuaJIT cannot have the catchall when the safe propagation is on
|
||||
// but LuaJIT will swallow all C++ errors
|
||||
// if we don't at least catch std::exception ones
|
||||
|
@ -131,61 +131,53 @@ namespace sol {
|
|||
|
||||
template <lua_CFunction f>
|
||||
int static_trampoline(lua_State* L) {
|
||||
return impl_static_trampoline(L, f);
|
||||
return lua_cfunction_trampoline(L, f);
|
||||
}
|
||||
|
||||
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
|
||||
#if 0
|
||||
// impossible: g++/clang++ choke as they think this function is ambiguous:
|
||||
// to fix, wait for template <auto X> and then switch on no-exceptness of the function
|
||||
template <lua_CFunction_noexcept f>
|
||||
int static_trampoline(lua_State* L) noexcept {
|
||||
return f(L);
|
||||
}
|
||||
#else
|
||||
#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_)
|
||||
template <lua_CFunction_noexcept f>
|
||||
int static_trampoline_noexcept(lua_State* L) noexcept {
|
||||
return f(L);
|
||||
}
|
||||
#endif // impossible
|
||||
|
||||
#else
|
||||
template <lua_CFunction f>
|
||||
int static_trampoline_noexcept(lua_State* L) noexcept {
|
||||
return f(L);
|
||||
}
|
||||
#endif // noexcept lua_CFunction type
|
||||
#endif
|
||||
|
||||
template <typename Fx, typename... Args>
|
||||
int trampoline(lua_State* L, Fx&& f, Args&&... args) {
|
||||
if (meta::bind_traits<meta::unqualified_t<Fx>>::is_noexcept) {
|
||||
if constexpr (meta::bind_traits<meta::unqualified_t<Fx>>::is_noexcept) {
|
||||
return f(L, std::forward<Args>(args)...);
|
||||
}
|
||||
#if defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_LUAJIT)
|
||||
return f(L, std::forward<Args>(args)...);
|
||||
else {
|
||||
#if SOL_IS_ON(SOL_PROPAGATE_EXCEPTIONS_I_)
|
||||
return f(L, std::forward<Args>(args)...);
|
||||
#else
|
||||
try {
|
||||
return f(L, std::forward<Args>(args)...);
|
||||
}
|
||||
catch (const char* cs) {
|
||||
call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(cs));
|
||||
}
|
||||
catch (const std::string& s) {
|
||||
call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(s.c_str(), s.size()));
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
call_exception_handler(L, optional<const std::exception&>(e), e.what());
|
||||
}
|
||||
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
|
||||
// LuaJIT cannot have the catchall when the safe propagation is on
|
||||
// but LuaJIT will swallow all C++ errors
|
||||
// if we don't at least catch std::exception ones
|
||||
catch (...) {
|
||||
call_exception_handler(L, optional<const std::exception&>(nullopt), "caught (...) exception");
|
||||
}
|
||||
try {
|
||||
return f(L, std::forward<Args>(args)...);
|
||||
}
|
||||
catch (const char* cs) {
|
||||
call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(cs));
|
||||
}
|
||||
catch (const std::string& s) {
|
||||
call_exception_handler(L, optional<const std::exception&>(nullopt), string_view(s.c_str(), s.size()));
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
call_exception_handler(L, optional<const std::exception&>(e), e.what());
|
||||
}
|
||||
#if SOL_IS_OFF(SOL_USE_LUAJIT_I_)
|
||||
// LuaJIT cannot have the catchall when the safe propagation is on
|
||||
// but LuaJIT will swallow all C++ errors
|
||||
// if we don't at least catch std::exception ones
|
||||
catch (...) {
|
||||
call_exception_handler(L, optional<const std::exception&>(nullopt), "caught (...) exception");
|
||||
}
|
||||
#endif
|
||||
return lua_error(L);
|
||||
return lua_error(L);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline int c_trampoline(lua_State* L, lua_CFunction f) {
|
||||
|
@ -193,29 +185,25 @@ namespace sol {
|
|||
}
|
||||
#endif // Exceptions vs. No Exceptions
|
||||
|
||||
template <typename F, F fx>
|
||||
inline int typed_static_trampoline_raw(std::true_type, lua_State* L) {
|
||||
return static_trampoline_noexcept<fx>(L);
|
||||
}
|
||||
|
||||
template <typename F, F fx>
|
||||
inline int typed_static_trampoline_raw(std::false_type, lua_State* L) {
|
||||
return static_trampoline<fx>(L);
|
||||
}
|
||||
|
||||
template <typename F, F fx>
|
||||
inline int typed_static_trampoline(lua_State* L) {
|
||||
return typed_static_trampoline_raw<F, fx>(std::integral_constant<bool, meta::bind_traits<F>::is_noexcept>(), L);
|
||||
if constexpr (meta::bind_traits<F>::is_noexcept) {
|
||||
return static_trampoline_noexcept<fx>(L);
|
||||
}
|
||||
else {
|
||||
return static_trampoline<fx>(L);
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
inline void set_default_exception_handler(lua_State* L, exception_handler_function exf = &detail::default_exception_handler) {
|
||||
static_assert(sizeof(void*) >= sizeof(exception_handler_function), "void* storage is too small to transport the exception handler: please file a bug on the issue tracker");
|
||||
static_assert(sizeof(void*) >= sizeof(exception_handler_function),
|
||||
"void* storage is too small to transport the exception handler: please file a bug on the sol2 issue tracker to get this looked at!");
|
||||
void* storage;
|
||||
std::memcpy(&storage, &exf, sizeof(exception_handler_function));
|
||||
lua_pushlightuserdata(L, storage);
|
||||
lua_setglobal(L, detail::default_exception_handler_name());
|
||||
}
|
||||
} // sol
|
||||
} // namespace sol
|
||||
|
||||
#endif // SOL_TRAMPOLINE_HPP
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// sol3
|
||||
// sol3
|
||||
|
||||
// The MIT License (MIT)
|
||||
|
||||
|
@ -50,20 +50,25 @@ namespace sol {
|
|||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
unsafe_function_result() = default;
|
||||
unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0)
|
||||
: L(Ls), index(idx), returncount(retnum) {
|
||||
unsafe_function_result() noexcept = default;
|
||||
unsafe_function_result(lua_State* Ls, int idx = -1, int retnum = 0) noexcept : L(Ls), index(idx), returncount(retnum) {
|
||||
}
|
||||
unsafe_function_result(const unsafe_function_result&) = default;
|
||||
unsafe_function_result& operator=(const unsafe_function_result&) = default;
|
||||
unsafe_function_result(unsafe_function_result&& o)
|
||||
: L(o.L), index(o.index), returncount(o.returncount) {
|
||||
|
||||
|
||||
// We do not want anyone to copy these around willy-nilly
|
||||
// Will likely break people, but also will probably get rid of quiet bugs that have
|
||||
// been lurking. (E.g., Vanilla Lua will just quietly discard over-pops and under-pops:
|
||||
// LuaJIT and other Lua engines will implode and segfault at random later times.)
|
||||
unsafe_function_result(const unsafe_function_result&) = delete;
|
||||
unsafe_function_result& operator=(const unsafe_function_result&) = delete;
|
||||
|
||||
unsafe_function_result(unsafe_function_result&& o) noexcept : L(o.L), index(o.index), returncount(o.returncount) {
|
||||
// Must be manual, otherwise destructor will screw us
|
||||
// return count being 0 is enough to keep things clean
|
||||
// but will be thorough
|
||||
o.abandon();
|
||||
}
|
||||
unsafe_function_result& operator=(unsafe_function_result&& o) {
|
||||
unsafe_function_result& operator=(unsafe_function_result&& o) noexcept {
|
||||
L = o.L;
|
||||
index = o.index;
|
||||
returncount = o.returncount;
|
||||
|
@ -148,7 +153,7 @@ namespace sol {
|
|||
return returncount;
|
||||
};
|
||||
void abandon() noexcept {
|
||||
//L = nullptr;
|
||||
// L = nullptr;
|
||||
index = 0;
|
||||
returncount = 0;
|
||||
}
|
||||
|
|
|
@ -68,6 +68,12 @@
|
|||
#define SOL_COMPILER_VCXX_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
#define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if SIZE_MAX <= 0xFFFFULL
|
||||
#define SOL_PLATFORM_X16_I_ SOL_ON
|
||||
#define SOL_PLATFORM_X86_I_ SOL_OFF
|
||||
|
@ -125,7 +131,7 @@
|
|||
#define SOL_DEBUG_BUILD_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#define SOL_DEBUG_BUILD_I_ SOL_OFF
|
||||
#define SOL_DEBUG_BUILD_I_ SOL_DEFAULT_OFF
|
||||
#endif // We are in a debug mode of some sort
|
||||
|
||||
#if defined(SOL_NO_EXCEPTIONS)
|
||||
|
@ -147,7 +153,7 @@
|
|||
#define SOL_EXCEPTIONS_I_ SOL_ON
|
||||
#endif
|
||||
#else
|
||||
#define SOL_EXCEPTIONS_I_ SOL_ON
|
||||
#define SOL_EXCEPTIONS_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -170,7 +176,7 @@
|
|||
#define SOL_RTTI_I_ SOL_ON
|
||||
#endif
|
||||
#else
|
||||
#define SOL_EXCEPTIONS_I_ SOL_ON
|
||||
#define SOL_RTTI_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_THREAD_LOCAL) && (SOL_NO_THREAD_LOCAL != 0)
|
||||
|
@ -182,7 +188,7 @@
|
|||
#if defined(SOL_ALL_SAFETIES_ON) && (SOL_ALL_SAFETIES_ON != 0)
|
||||
#define SOL_ALL_SAFETIES_ON_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_ALL_SAFETIES_ON_I_ SOL_OFF
|
||||
#define SOL_ALL_SAFETIES_ON_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_SAFE_GETTER) && (SOL_SAFE_GETTER != 0)
|
||||
|
@ -193,7 +199,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_GETTER_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_GETTER_I_ SOL_OFF
|
||||
#define SOL_SAFE_GETTER_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -205,7 +211,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_USERTYPE_I_ SOL_OFF
|
||||
#define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -217,7 +223,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_REFERENCES_I_ SOL_OFF
|
||||
#define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -230,7 +236,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_OFF
|
||||
#define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -242,7 +248,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_FUNCTION_CALLS_I_ SOL_OFF
|
||||
#define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -254,7 +260,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_PROXIES_I_ SOL_OFF
|
||||
#define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -266,7 +272,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_NUMERICS_I_ SOL_OFF
|
||||
#define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -278,7 +284,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_STACK_CHECK_I_ SOL_OFF
|
||||
#define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -288,10 +294,12 @@
|
|||
#else
|
||||
#if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_)
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON
|
||||
#elif SOL_IS_ON(SOL_SAFE_NUMERICS_I_)
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON
|
||||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_OFF
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -302,14 +310,14 @@
|
|||
#define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF
|
||||
#define SOL_STRINGS_ARE_NUMBERS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_ENABLE_INTEROP) && (SOL_ENABLE_INTEROP != 0) \
|
||||
|| defined(SOL_USE_INTEROP) && (SOL_USE_INTEROP != 0)
|
||||
#define SOL_USE_INTEROP_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_USE_INTEROP_I_ SOL_OFF
|
||||
#define SOL_USE_INTEROP_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_NIL)
|
||||
|
@ -319,7 +327,7 @@
|
|||
#define SOL_NIL_I_ SOL_ON
|
||||
#endif
|
||||
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
|
||||
#define SOL_NIL_I_ SOL_OFF
|
||||
#define SOL_NIL_I_ SOL_DEFAULT_OFF
|
||||
#else
|
||||
#define SOL_NIL_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
@ -413,8 +421,12 @@
|
|||
#define SOL_FILE_ID_SIZE_I_ 2048
|
||||
#endif
|
||||
|
||||
#if defined(SOL_PRINT_ERRORS) && (SOL_PRINT_ERRORS != 0)
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_ON
|
||||
#if defined(SOL_PRINT_ERRORS)
|
||||
#if (SOL_PRINT_ERRORS != 0)
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_)
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_ON
|
||||
|
@ -526,6 +538,37 @@
|
|||
#else
|
||||
#define SOL_USE_UNSAFE_BASE_LOOKUP_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_INSIDE_UNREAL)
|
||||
#if (SOL_INSIDE_UNREAL != 0)
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER)
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_COMPAT)
|
||||
#if (SOL_NO_COMPAT != 0)
|
||||
#define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_OFF
|
||||
#else
|
||||
#define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_ON
|
||||
#endif
|
||||
#else
|
||||
#define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if SOL_IS_ON(SOL_COMPILER_FRONTEND_MINGW_I_) && defined(__GNUC__) && (__GNUC__ < 6)
|
||||
// MinGW is off its rocker in some places...
|
||||
#define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#endif // SOL_VERSION_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-09-09 00:46:22.609996 UTC
|
||||
// This header was generated with sol v3.2.1 (revision e4f588d)
|
||||
// Generated 2020-09-26 10:44:02.641191 UTC
|
||||
// This header was generated with sol v3.2.1 (revision e89b6ac)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_CONFIG_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-09-09 00:46:22.606997 UTC
|
||||
// This header was generated with sol v3.2.1 (revision e4f588d)
|
||||
// Generated 2020-09-26 10:44:02.626193 UTC
|
||||
// This header was generated with sol v3.2.1 (revision e89b6ac)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
@ -76,6 +76,12 @@
|
|||
#define SOL_COMPILER_VCXX_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
#define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_COMPILER_FRONTEND_MINGW_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if SIZE_MAX <= 0xFFFFULL
|
||||
#define SOL_PLATFORM_X16_I_ SOL_ON
|
||||
#define SOL_PLATFORM_X86_I_ SOL_OFF
|
||||
|
@ -132,7 +138,7 @@
|
|||
#define SOL_DEBUG_BUILD_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#define SOL_DEBUG_BUILD_I_ SOL_OFF
|
||||
#define SOL_DEBUG_BUILD_I_ SOL_DEFAULT_OFF
|
||||
#endif // We are in a debug mode of some sort
|
||||
|
||||
#if defined(SOL_NO_EXCEPTIONS)
|
||||
|
@ -154,7 +160,7 @@
|
|||
#define SOL_EXCEPTIONS_I_ SOL_ON
|
||||
#endif
|
||||
#else
|
||||
#define SOL_EXCEPTIONS_I_ SOL_ON
|
||||
#define SOL_EXCEPTIONS_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_RTTI)
|
||||
|
@ -176,7 +182,7 @@
|
|||
#define SOL_RTTI_I_ SOL_ON
|
||||
#endif
|
||||
#else
|
||||
#define SOL_EXCEPTIONS_I_ SOL_ON
|
||||
#define SOL_RTTI_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_THREAD_LOCAL) && (SOL_NO_THREAD_LOCAL != 0)
|
||||
|
@ -188,7 +194,7 @@
|
|||
#if defined(SOL_ALL_SAFETIES_ON) && (SOL_ALL_SAFETIES_ON != 0)
|
||||
#define SOL_ALL_SAFETIES_ON_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_ALL_SAFETIES_ON_I_ SOL_OFF
|
||||
#define SOL_ALL_SAFETIES_ON_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_SAFE_GETTER) && (SOL_SAFE_GETTER != 0)
|
||||
|
@ -199,7 +205,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_GETTER_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_GETTER_I_ SOL_OFF
|
||||
#define SOL_SAFE_GETTER_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -211,7 +217,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_USERTYPE_I_ SOL_OFF
|
||||
#define SOL_SAFE_USERTYPE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -223,7 +229,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_REFERENCES_I_ SOL_OFF
|
||||
#define SOL_SAFE_REFERENCES_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -236,7 +242,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_OFF
|
||||
#define SOL_SAFE_FUNCTION_OBJECTS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -248,7 +254,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_FUNCTION_CALLS_I_ SOL_OFF
|
||||
#define SOL_SAFE_FUNCTION_CALLS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -260,7 +266,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_PROXIES_I_ SOL_OFF
|
||||
#define SOL_SAFE_PROXIES_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -272,7 +278,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_NUMERICS_I_ SOL_OFF
|
||||
#define SOL_SAFE_NUMERICS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -284,7 +290,7 @@
|
|||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_SAFE_STACK_CHECK_I_ SOL_OFF
|
||||
#define SOL_SAFE_STACK_CHECK_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -294,10 +300,12 @@
|
|||
#else
|
||||
#if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_)
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON
|
||||
#elif SOL_IS_ON(SOL_SAFE_NUMERICS_I_)
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_ON
|
||||
#elif SOL_IS_ON(SOL_DEBUG_BUILD_I_)
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_ON
|
||||
#else
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_OFF
|
||||
#define SOL_NUMBER_PRECISION_CHECKS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -308,14 +316,14 @@
|
|||
#define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#define SOL_STRINGS_ARE_NUMBERS_I_ SOL_OFF
|
||||
#define SOL_STRINGS_ARE_NUMBERS_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_ENABLE_INTEROP) && (SOL_ENABLE_INTEROP != 0) \
|
||||
|| defined(SOL_USE_INTEROP) && (SOL_USE_INTEROP != 0)
|
||||
#define SOL_USE_INTEROP_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_USE_INTEROP_I_ SOL_OFF
|
||||
#define SOL_USE_INTEROP_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_NIL)
|
||||
|
@ -325,7 +333,7 @@
|
|||
#define SOL_NIL_I_ SOL_ON
|
||||
#endif
|
||||
#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
|
||||
#define SOL_NIL_I_ SOL_OFF
|
||||
#define SOL_NIL_I_ SOL_DEFAULT_OFF
|
||||
#else
|
||||
#define SOL_NIL_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
@ -419,8 +427,12 @@
|
|||
#define SOL_FILE_ID_SIZE_I_ 2048
|
||||
#endif
|
||||
|
||||
#if defined(SOL_PRINT_ERRORS) && (SOL_PRINT_ERRORS != 0)
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_ON
|
||||
#if defined(SOL_PRINT_ERRORS)
|
||||
#if (SOL_PRINT_ERRORS != 0)
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#if SOL_IS_ON(SOL_ALL_SAFETIES_ON_I_)
|
||||
#define SOL_PRINT_ERRORS_I_ SOL_ON
|
||||
|
@ -533,6 +545,37 @@
|
|||
#define SOL_USE_UNSAFE_BASE_LOOKUP_I_ SOL_OFF
|
||||
#endif
|
||||
|
||||
#if defined(SOL_INSIDE_UNREAL)
|
||||
#if (SOL_INSIDE_UNREAL != 0)
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_OFF
|
||||
#endif
|
||||
#else
|
||||
#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER)
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_INSIDE_UNREAL_ENGINE_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SOL_NO_COMPAT)
|
||||
#if (SOL_NO_COMPAT != 0)
|
||||
#define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_OFF
|
||||
#else
|
||||
#define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_ON
|
||||
#endif
|
||||
#else
|
||||
#define SOL_USE_COMPATIBILITY_LAYER_I_ SOL_DEFAULT_ON
|
||||
#endif
|
||||
|
||||
#if SOL_IS_ON(SOL_COMPILER_FRONTEND_MINGW_I_) && defined(__GNUC__) && (__GNUC__ < 6)
|
||||
// MinGW is off its rocker in some places...
|
||||
#define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_ON
|
||||
#else
|
||||
#define SOL_MINGW_CCTYPE_IS_POISONED_I_ SOL_DEFAULT_OFF
|
||||
#endif
|
||||
|
||||
// end of sol/version.hpp
|
||||
|
||||
#include <utility>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,20 @@
|
|||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
struct foo1000 {
|
||||
static void register_into(sol::table& table) {
|
||||
table.new_usertype<foo1000>("foo1000", "id", sol::readonly(&foo1000::foo));
|
||||
}
|
||||
int foo;
|
||||
};
|
||||
|
||||
int regression_1000() {
|
||||
sol::state lua;
|
||||
lua.create_named_table("t");
|
||||
|
||||
sol::table t = lua["t"];
|
||||
foo1000::register_into(t);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
#include <cstddef>
|
||||
|
||||
extern int regression_1008();
|
||||
extern int regression_1000();
|
||||
|
||||
int main(int, char*[]) {
|
||||
using f_ptr = int (*)();
|
||||
const f_ptr regressions[] = { ®ression_1008 };
|
||||
const f_ptr regressions[] = { ®ression_1008, ®ression_1000 };
|
||||
const int sizeof_regressions = sizeof(regressions) / sizeof(regressions[0]);
|
||||
int r = 0;
|
||||
for (std::size_t i = 0; i < sizeof_regressions; ++i) {
|
||||
|
|
|
@ -30,13 +30,12 @@
|
|||
|
||||
template <typename T>
|
||||
T va_func(sol::variadic_args va, T first) {
|
||||
(void)first;
|
||||
T s = 0;
|
||||
for (auto arg : va) {
|
||||
T v = arg;
|
||||
s += v;
|
||||
}
|
||||
std::cout << first << std::endl;
|
||||
std::cout << s << std::endl;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -231,7 +230,7 @@ end )",
|
|||
REQUIRE((bool)testv);
|
||||
REQUIRE_FALSE((bool)testn);
|
||||
REQUIRE(testv.value() == 29);
|
||||
sol::optional<thing> v = lua_bark(sol::optional<thing>(thing{ 29 }));
|
||||
sol::optional<thing> v = lua_bark(sol::optional<thing>(thing { 29 }));
|
||||
REQUIRE_NOTHROW([&] {
|
||||
sol::lua_nil_t n = lua_bark(sol::nullopt);
|
||||
return n;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <numeric>
|
||||
#include <iostream>
|
||||
|
||||
struct T {};
|
||||
struct T { };
|
||||
|
||||
TEST_CASE("operators/default", "test that generic equality operators and all sorts of equality tests can be used") {
|
||||
struct U {
|
||||
|
@ -56,10 +56,10 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor
|
|||
T& t2 = t1;
|
||||
T t3;
|
||||
U u1;
|
||||
U u2{ 30 };
|
||||
U u2 { 30 };
|
||||
U u3;
|
||||
V v1;
|
||||
V v2{ 30 };
|
||||
V v2 { 30 };
|
||||
V v3;
|
||||
lua["t1"] = &t1;
|
||||
lua["t2"] = &t2;
|
||||
|
@ -74,55 +74,55 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor
|
|||
SECTION("plain") {
|
||||
// Can only compare identity here
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(t1 == t1)"
|
||||
"assert(t2 == t2)"
|
||||
"assert(t3 == t3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
sol::optional<sol::error> result1 = lua.safe_script(
|
||||
"assert(t1 == t1)"
|
||||
"assert(t2 == t2)"
|
||||
"assert(t3 == t3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE_FALSE(result1.has_value());
|
||||
}
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(t1 == t2)"
|
||||
"assert(not (t1 == t3))"
|
||||
"assert(not (t2 == t3))",
|
||||
sol::script_pass_on_error);
|
||||
"assert(t1 == t2)"
|
||||
"assert(not (t1 == t3))"
|
||||
"assert(not (t2 == t3))",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
// Object should compare equal to themselves
|
||||
// (and not invoke operator==; pointer test should be sufficient)
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(u1 == u1)"
|
||||
"assert(u2 == u2)"
|
||||
"assert(u3 == u3)",
|
||||
sol::script_pass_on_error);
|
||||
"assert(u1 == u1)"
|
||||
"assert(u2 == u2)"
|
||||
"assert(u3 == u3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(not (u1 == u2))"
|
||||
"assert(u1 == u3)"
|
||||
"assert(not (u2 == u3))",
|
||||
sol::script_pass_on_error);
|
||||
"assert(not (u1 == u2))"
|
||||
"assert(u1 == u3)"
|
||||
"assert(not (u2 == u3))",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
// Object should compare equal to themselves
|
||||
// (and not invoke operator==; pointer test should be sufficient)
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(v1 == v1)"
|
||||
"assert(v2 == v2)"
|
||||
"assert(v3 == v3)",
|
||||
sol::script_pass_on_error);
|
||||
"assert(v1 == v1)"
|
||||
"assert(v2 == v2)"
|
||||
"assert(v3 == v3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(not (v1 == v2))"
|
||||
"assert(v1 == v3)"
|
||||
"assert(not (v2 == v3))",
|
||||
sol::script_pass_on_error);
|
||||
"assert(not (v1 == v2))"
|
||||
"assert(v1 == v3)"
|
||||
"assert(not (v2 == v3))",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
}
|
||||
|
@ -134,54 +134,54 @@ TEST_CASE("operators/default", "test that generic equality operators and all sor
|
|||
// Can only compare identity here
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(t1 == t1)"
|
||||
"assert(t2 == t2)"
|
||||
"assert(t3 == t3)",
|
||||
sol::script_pass_on_error);
|
||||
"assert(t1 == t1)"
|
||||
"assert(t2 == t2)"
|
||||
"assert(t3 == t3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(t1 == t2)"
|
||||
"assert(not (t1 == t3))"
|
||||
"assert(not (t2 == t3))",
|
||||
sol::script_pass_on_error);
|
||||
"assert(t1 == t2)"
|
||||
"assert(not (t1 == t3))"
|
||||
"assert(not (t2 == t3))",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
// Object should compare equal to themselves
|
||||
// (and not invoke operator==; pointer test should be sufficient)
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(u1 == u1)"
|
||||
"assert(u2 == u2)"
|
||||
"assert(u3 == u3)",
|
||||
sol::script_pass_on_error);
|
||||
"assert(u1 == u1)"
|
||||
"assert(u2 == u2)"
|
||||
"assert(u3 == u3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(not (u1 == u2))"
|
||||
"assert(u1 == u3)"
|
||||
"assert(not (u2 == u3))",
|
||||
sol::script_pass_on_error);
|
||||
"assert(not (u1 == u2))"
|
||||
"assert(u1 == u3)"
|
||||
"assert(not (u2 == u3))",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
// Object should compare equal to themselves
|
||||
// (and not invoke operator==; pointer test should be sufficient)
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(v1 == v1)"
|
||||
"assert(v2 == v2)"
|
||||
"assert(v3 == v3)",
|
||||
sol::script_pass_on_error);
|
||||
"assert(v1 == v1)"
|
||||
"assert(v2 == v2)"
|
||||
"assert(v3 == v3)",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"assert(not (v1 == v2))"
|
||||
"assert(v1 == v3)"
|
||||
"assert(not (v2 == v3))",
|
||||
sol::script_pass_on_error);
|
||||
"assert(not (v1 == v2))"
|
||||
"assert(v1 == v3)"
|
||||
"assert(not (v2 == v3))",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
}
|
||||
}
|
||||
|
@ -240,9 +240,9 @@ TEST_CASE("operators/call", "test call operator generation") {
|
|||
lua.new_usertype<callable>("callable");
|
||||
{
|
||||
auto result1 = lua.safe_script(
|
||||
"obj = callable.new()\n"
|
||||
"v = obj(2, 'bark woof')",
|
||||
sol::script_pass_on_error);
|
||||
"obj = callable.new()\n"
|
||||
"v = obj(2, 'bark woof')",
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
int v = lua["v"];
|
||||
REQUIRE(v == 11);
|
||||
|
@ -310,7 +310,7 @@ TEST_CASE("operators/stringable", "test std::ostream stringability") {
|
|||
{
|
||||
auto result1 = lua.safe_script(R"(obj = stringable.new()
|
||||
print(obj) )",
|
||||
sol::script_pass_on_error);
|
||||
sol::script_pass_on_error);
|
||||
REQUIRE(result1.valid());
|
||||
stringable& obj = lua["obj"];
|
||||
REQUIRE(stringable::last_print_ptr == &obj);
|
||||
|
|
Loading…
Reference in New Issue
Block a user