Fix a lot of errors

- Add a new feature for SOL_FUNCTION_CALL_VALUE_SEMANTICS. Fixes #1059
- Detect deprecated/removed bit32 library. Fixes #1086
- Format the entire repository. Close #1073
- SOL_LUAJIT was not being properly defined. Close #1082
- Fix alignment issue. #1071
This commit is contained in:
ThePhD 2020-12-16 15:25:35 -05:00
parent 5b7cf9ade9
commit 561c90abf4
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
80 changed files with 1300 additions and 1206 deletions

View File

@ -63,6 +63,8 @@ functions and argument passing
All arguments are forwarded. Unlike :doc:`get/set/operator[] on sol::state<api/state>` or :doc:`sol::table<api/table>`, value semantics are not used here. It is forwarding reference semantics, which do not copy/move unless it is specifically done by the receiving functions / specifically done by the user.
You can change this behavior by defining ``SOL_FUNCTION_CALL_VALUE_SEMANTICS``, as defined in the :doc:`safety configuration page<safety>`.
.. note::
This also means that you should pass and receive arguments in certain ways to maximize efficiency. For example, ``sol::table``, ``sol::object``, ``sol::userdata`` and friends are cheap to copy, and should simply by taken as values. This includes primitive types like ``int`` and ``double``. However, C++ types -- if you do not want copies -- should be taken as ``const type&`` or ``type&``, to save on copies if it's important. Note that taking references from Lua also means you can modify the data inside of Lua directly, so be careful. Lua by default deals with things mostly by reference (save for primitive types).

View File

@ -62,6 +62,11 @@ Safety Config
* If ``SOL_SAFE_NUMERICS`` is defined, turns off number precision and integer precision fitting when pushing numbers into sol2
* **Not** turned on by default under any settings: *this MUST be turned on manually*
``SOL_FUNCTION_CALL_VALUE_SEMANTICS`` triggers the following changes:
* Function arguments and returns into Lua (``sol:function`` and similar) do not pass their arguments by reference: they get copied
* Individual types can be blessed by template specializing ``sol::is_value_semantic_for_function<T>``
* **Not** turned on by default under any settings: *this MUST be turned on manually*
``SOL_STRINGS_ARE_NUMBERS`` triggers the following changes:
* Allows automatic to-string conversions for numbers
- ``lua_tolstring`` conversions are not permitted on numbers through sol3 by default: only actual strings are allowed
@ -124,6 +129,10 @@ Feature Config
* If this is defined to a numeric value, it uses that numeric value for the number of bytes of input to be put into the error message blurb in standard tracebacks and ``chunkname`` descriptions for ``.script``/``.script_file`` usage.
* Defaults to the ``LUA_ID_SIZE`` macro if defined, or some basic internal value like 2048.
``SOL_LUAJIT`` triggers the following change:
* Has sol2 expect LuaJIT, and all of its quirks.
* Turns on by default if the macro ``LUAJIT_VERSION`` is detected from including Lua headers without any work on your part. Can also be manually defined.
.. _config-memory:
Memory Config

View File

@ -63,7 +63,6 @@ function (MAKE_EXAMPLE example_source_file example_suffix target_sol)
file(TO_CMAKE_PATH "${example_output_relative_dir}" example_output_relative_dir_name)
STRING(REGEX REPLACE "/" "." example_output_relative_dir_name "${example_output_relative_dir}")
set(example_name "${example_name}${example_suffix}")
if (example_output_relative_dir_name STREQUAL "")
set(example_output_name "${example_name}")
else()
@ -88,7 +87,7 @@ function (MAKE_EXAMPLE example_source_file example_suffix target_sol)
-ftemplate-backtrace-limit=0
-Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Wpedantic -Werror -pedantic -pedantic-errors
-Wno-noexcept-type)
-Wno-noexcept-type -Wshadow -Wconversion)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# For another day, when C++ is not so crap

View File

@ -17,11 +17,11 @@ int my_exception_handler(lua_State* L, sol::optional<const std::exception&> mayb
}
else {
std::cout << "(from the description parameter): ";
std::cout.write(description.data(), description.size());
std::cout.write(description.data(), static_cast<std::streamsize>(description.size()));
std::cout << std::endl;
}
// you must push 1 element onto the stack to be
// you must push 1 element onto the stack to be
// transported through as the error object in Lua
// note that Lua -- and 99.5% of all Lua users and libraries -- expects a string
// so we push a single string (in our case, the description of the error)
@ -44,7 +44,7 @@ int main() {
sol::protected_function_result pfr = lua.safe_script("will_throw()", &sol::script_pass_on_error);
c_assert(!pfr.valid());
sol::error err = pfr;
std::cout << err.what() << std::endl;

View File

@ -1,50 +0,0 @@
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
#include <string>
#include <iostream>
class MyClass {
public:
MyClass(double d) : data(d) {}
double data;
};
int main() {
std::cout << "=== coroutine ===" << std::endl;
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<MyClass>("MyClass",
sol::meta_function::construct, sol::factories(
// MyClass.new(...) -- dot syntax, no "self" value passed in
[](const double& d) {return std::make_shared<MyClass>(d);},
// MyClass:new(...) -- colon syntax, passes in the "self" value
// as first argument implicitly
[](sol::object, const double& d) {return std::make_shared<MyClass>(d);}
),
// MyClass(...) syntax, only
sol::call_constructor, sol::factories([](const double& d) {return std::make_shared<MyClass>(d);}),
"data", &MyClass::data
);
sol::optional<sol::error> maybe_error = lua.safe_script(R"(
d1 = MyClass(2.1)
d2 = MyClass:new(3.1)
d3 = MyClass(4.1)
assert(d1.data == 2.1)
assert(d2.data == 2.1)
assert(d3.data == 2.1)
)", sol::script_pass_on_error);
if (maybe_error) {
// something went wrong!
std::cerr << "Something has gone horribly unexpected and wrong:\n" << maybe_error->what() << std::endl;
return 1;
}
// everything is okay!
return 0;
}

View File

@ -16,7 +16,7 @@ public:
}
int test(int x) {
return static_cast<int>(name.length() + x);
return static_cast<int>(name.length()) + x;
}
};

View File

@ -0,0 +1,55 @@
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>
#include <string>
#include <iostream>
class MyClass {
public:
MyClass(double d) : data(d) {
}
double data;
};
int main() {
std::cout << "=== usertype constructors ===" << std::endl;
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<MyClass>("MyClass",
sol::meta_function::construct,
sol::factories(
// MyClass.new(...) -- dot syntax, no "self" value passed in
[](const double& d) { return std::make_shared<MyClass>(d); },
// MyClass:new(...) -- colon syntax, passes in the "self" value
// as first argument implicitly
[](sol::object, const double& d) { return std::make_shared<MyClass>(d); }),
// MyClass(...) syntax, only
sol::call_constructor,
sol::factories([](const double& d) { return std::make_shared<MyClass>(d); }),
"data",
&MyClass::data);
sol::optional<sol::error> maybe_error = lua.safe_script(R"(
d1 = MyClass(2.1)
d2 = MyClass:new(3.1)
d3 = MyClass(4.1)
assert(d1.data == 2.1)
assert(d2.data == 3.1)
assert(d3.data == 4.1)
)",
sol::script_pass_on_error);
if (maybe_error) {
// something went wrong!
std::cerr << "Something has gone horribly unexpected and wrong:\n" << maybe_error->what() << std::endl;
return 1;
}
// everything is okay!
std::cout << "Everything went okay and all the asserts passed!" << std::endl;
return 0;
}

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -35,7 +35,7 @@ namespace sol {
template <typename Source>
auto as_returns(Source&& source) {
return as_returns_t<std::decay_t<Source>>{ std::forward<Source>(source) };
return as_returns_t<std::decay_t<Source>> { std::forward<Source>(source) };
}
namespace stack {

View File

@ -28,8 +28,8 @@
namespace sol {
namespace detail {
struct unchecked_t {};
const unchecked_t unchecked = unchecked_t{};
struct unchecked_t { };
const unchecked_t unchecked = unchecked_t {};
} // namespace detail
namespace meta {
@ -47,13 +47,13 @@ namespace sol {
namespace meta_detail {
template <typename T>
struct unqualified_non_alias : unqualified<T> {};
struct unqualified_non_alias : unqualified<T> { };
template <template <class...> class Test, class, class... Args>
struct is_detected : std::false_type {};
struct is_detected : std::false_type { };
template <template <class...> class Test, class... Args>
struct is_detected<Test, void_t<Test<Args...>>, Args...> : std::true_type {};
struct is_detected<Test, void_t<Test<Args...>>, Args...> : std::true_type { };
} // namespace meta_detail
template <template <class...> class Trait, class... Args>
@ -82,9 +82,9 @@ namespace sol {
namespace meta_detail {
template <typename T, template <typename...> class Templ>
struct is_specialization_of : std::false_type {};
struct is_specialization_of : std::false_type { };
template <typename... T, template <typename...> class Templ>
struct is_specialization_of<Templ<T...>, Templ> : std::true_type {};
struct is_specialization_of<Templ<T...>, Templ> : std::true_type { };
} // namespace meta_detail
template <typename T, template <typename...> class Templ>

View File

@ -59,7 +59,7 @@ namespace sol {
luaL_ref(L, deps.stack_index());
};
(void)per_dep;
(void)detail::swallow{ int(), (per_dep(In), int())... };
(void)detail::swallow { int(), (per_dep(In), int())... };
lua_setuservalue(L, ai);
}
}
@ -112,7 +112,7 @@ namespace sol {
}
template <typename T, typename List>
struct void_call : void_call<T, meta::function_args_t<List>> {};
struct void_call : void_call<T, meta::function_args_t<List>> { };
template <typename T, typename... Args>
struct void_call<T, types<Args...>> {
@ -129,7 +129,7 @@ namespace sol {
template <typename Fx, std::size_t I, typename... R, typename... Args>
int operator()(types<Fx>, meta::index_value<I>, types<R...> r, types<Args...> a, lua_State* L, int, int start) const {
detail::default_construct func{};
detail::default_construct func {};
return stack::call_into_lua<checked, clean_stack>(r, a, L, start, func, obj_);
}
};
@ -171,7 +171,7 @@ namespace sol {
std::forward<Args>(args)...);
}
}
stack::record tracking{};
stack::record tracking {};
if (!stack::stack_detail::check_types(args_list(), L, start, no_panic, tracking)) {
return overload_match_arity(types<Fxs...>(),
std::index_sequence<In...>(),
@ -264,7 +264,7 @@ namespace sol {
std::forward<Args>(args)...);
}
}
stack::record tracking{};
stack::record tracking {};
if (!stack::stack_detail::check_types(args_list(), L, start, no_panic, tracking)) {
return overload_match_arity(types<Fx1, Fxs...>(),
std::index_sequence<I1, In...>(),
@ -349,11 +349,10 @@ namespace sol {
using wrap = wrapper<uFx>;
using traits_type = typename wrap::traits_type;
using fp_t = typename traits_type::function_pointer_type;
constexpr bool is_function_pointer_convertible
= std::is_class_v<uFx> && std::is_convertible_v<std::decay_t<Fx>, fp_t>;
constexpr bool is_function_pointer_convertible = std::is_class_v<uFx> && std::is_convertible_v<std::decay_t<Fx>, fp_t>;
if constexpr (is_function_pointer_convertible) {
fp_t fx = f;
return agnostic_lua_call_wrapper<fp_t, is_index, is_variable, checked, boost, clean_stack>{}.call(
return agnostic_lua_call_wrapper<fp_t, is_index, is_variable, checked, boost, clean_stack> {}.call(
L, fx, std::forward<Args>(args)...);
}
else {
@ -448,7 +447,7 @@ namespace sol {
template <typename T, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
struct agnostic_lua_call_wrapper<std::reference_wrapper<T>, is_index, is_variable, checked, boost, clean_stack, C> {
static int call(lua_State* L, std::reference_wrapper<T> f) {
agnostic_lua_call_wrapper<T, is_index, is_variable, checked, boost, clean_stack> alcw{};
agnostic_lua_call_wrapper<T, is_index, is_variable, checked, boost, clean_stack> alcw {};
return alcw.call(L, f.get());
}
};
@ -463,7 +462,10 @@ namespace sol {
using object_type = typename wrap::object_type;
if constexpr (sizeof...(Args) < 1) {
using Ta = meta::conditional_t<std::is_void_v<T>, object_type, T>;
static_assert(std::is_base_of_v<object_type, Ta>, "It seems like you might have accidentally bound a class type with a member function method that does not correspond to the class. For example, there could be a small type in your new_usertype<T>(...) binding, where you specify one class \"T\" but then bind member methods from a complete unrelated class. Check things over!");
static_assert(std::is_base_of_v<object_type, Ta>,
"It seems like you might have accidentally bound a class type with a member function method that does not correspond to the "
"class. For example, there could be a small type in your new_usertype<T>(...) binding, where you specify one class \"T\" "
"but then bind member methods from a complete unrelated class. Check things over!");
#if SOL_IS_ON(SOL_SAFE_USERTYPE_I_)
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
@ -493,7 +495,10 @@ namespace sol {
if constexpr (is_index) {
if constexpr (sizeof...(Args) < 1) {
using Ta = meta::conditional_t<std::is_void_v<T>, object_type, T>;
static_assert(std::is_base_of_v<object_type, Ta>, "It seems like you might have accidentally bound a class type with a member function method that does not correspond to the class. For example, there could be a small type in your new_usertype<T>(...) binding, where you specify one class \"T\" but then bind member methods from a complete unrelated class. Check things over!");
static_assert(std::is_base_of_v<object_type, Ta>,
"It seems like you might have accidentally bound a class type with a member function method that does not correspond "
"to the class. For example, there could be a small type in your new_usertype<T>(...) binding, where you specify one "
"class \"T\" but then bind member methods from a complete unrelated class. Check things over!");
#if SOL_IS_ON(SOL_SAFE_USERTYPE_I_)
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
@ -527,7 +532,7 @@ namespace sol {
constexpr bool ret_is_const = std::is_const_v<std::remove_reference_t<return_type>>;
if constexpr (ret_is_const) {
(void)fx;
(void)detail::swallow{ 0, (static_cast<void>(args), 0)... };
(void)detail::swallow { 0, (static_cast<void>(args), 0)... };
return luaL_error(L, "sol: cannot write to a readonly (const) variable");
}
else {
@ -535,7 +540,7 @@ namespace sol {
constexpr bool is_assignable = std::is_copy_assignable_v<u_return_type> || std::is_array_v<u_return_type>;
if constexpr (!is_assignable) {
(void)fx;
(void)detail::swallow{ 0, ((void)args, 0)... };
(void)detail::swallow { 0, ((void)args, 0)... };
return luaL_error(L, "sol: cannot write to this variable: copy assignment/constructor not available");
}
else {
@ -574,7 +579,7 @@ namespace sol {
}
}
else {
agnostic_lua_call_wrapper<F, is_index, is_variable, checked, boost, clean_stack> alcw{};
agnostic_lua_call_wrapper<F, is_index, is_variable, checked, boost, clean_stack> alcw {};
return alcw.call(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
}
}
@ -696,7 +701,7 @@ namespace sol {
}
else {
using uFx = meta::unqualified_t<Fx>;
lua_call_wrapper<T, uFx, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, uFx, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, std::forward<F>(f).fx);
}
}
@ -710,7 +715,7 @@ namespace sol {
template <typename Fx, std::size_t I, typename... R, typename... Args>
int operator()(types<Fx>, meta::index_value<I>, types<R...>, types<Args...>, lua_State* L, int, int, F& fx) {
auto& f = std::get<I>(fx.functions);
return lua_call_wrapper<T, Fx, is_index, is_variable, checked, boost>{}.call(L, f);
return lua_call_wrapper<T, Fx, is_index, is_variable, checked, boost> {}.call(L, f);
}
};
@ -727,7 +732,7 @@ namespace sol {
template <typename Fx, std::size_t I, typename... R, typename... Args>
int operator()(types<Fx>, meta::index_value<I>, types<R...>, types<Args...>, lua_State* L, int, int, F& fx) {
auto& f = std::get<I>(fx.functions);
return lua_call_wrapper<T, Fx, is_index, is_variable, checked, boost, clean_stack>{}.call(L, f);
return lua_call_wrapper<T, Fx, is_index, is_variable, checked, boost, clean_stack> {}.call(L, f);
}
};
@ -754,12 +759,12 @@ namespace sol {
if constexpr (is_specialized) {
if constexpr (is_index) {
decltype(auto) p = f.read();
lua_call_wrapper<T, meta::unqualified_t<decltype(p)>, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, meta::unqualified_t<decltype(p)>, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, p, std::forward<Args>(args)...);
}
else {
decltype(auto) p = f.write();
lua_call_wrapper<T, meta::unqualified_t<decltype(p)>, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, meta::unqualified_t<decltype(p)>, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, p, std::forward<Args>(args)...);
}
}
@ -821,7 +826,7 @@ namespace sol {
template <typename... Args>
static int call(lua_State* L, F& fx, Args&&... args) {
return lua_call_wrapper<T, V, is_index, is_variable, true, boost, clean_stack>{}.call(L, fx.value, std::forward<Args>(args)...);
return lua_call_wrapper<T, V, is_index, is_variable, true, boost, clean_stack> {}.call(L, fx.value, std::forward<Args>(args)...);
}
};
@ -831,8 +836,8 @@ namespace sol {
template <std::size_t... In>
static int call(std::index_sequence<In...>, lua_State* L, P& fx) {
int pushed = lua_call_wrapper<T, F, is_index, is_variable, checked, boost, false, C>{}.call(L, fx.value);
(void)detail::swallow{ int(), (policy_detail::handle_policy(std::get<In>(fx.policies), L, pushed), int())... };
int pushed = lua_call_wrapper<T, F, is_index, is_variable, checked, boost, false, C> {}.call(L, fx.value);
(void)detail::swallow { int(), (policy_detail::handle_policy(std::get<In>(fx.policies), L, pushed), int())... };
return pushed;
}
@ -846,19 +851,19 @@ namespace sol {
struct lua_call_wrapper<T, yielding_t<Y>, is_index, is_variable, checked, boost, clean_stack, C> {
template <typename F>
static int call(lua_State* L, F&& f) {
return lua_call_wrapper<T, meta::unqualified_t<Y>, is_index, is_variable, checked, boost, clean_stack>{}.call(L, f.func);
return lua_call_wrapper<T, meta::unqualified_t<Y>, is_index, is_variable, checked, boost, clean_stack> {}.call(L, f.func);
}
};
template <typename T, typename Sig, typename P, bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
struct lua_call_wrapper<T, function_arguments<Sig, P>, is_index, is_variable, checked, boost, clean_stack, C> {
static int call(lua_State* L, const function_arguments<Sig, P>& f) {
lua_call_wrapper<T, meta::unqualified_t<P>, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, meta::unqualified_t<P>, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, std::get<0>(f.arguments));
}
static int call(lua_State* L, function_arguments<Sig, P>&& f) {
lua_call_wrapper<T, meta::unqualified_t<P>, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, meta::unqualified_t<P>, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, std::get<0>(std::move(f.arguments)));
}
};
@ -869,11 +874,11 @@ namespace sol {
using uFx = meta::unqualified_t<Fx>;
if constexpr (meta::is_specialization_of_v<uFx, yielding_t>) {
using real_fx = meta::unqualified_t<decltype(std::forward<Fx>(fx).func)>;
lua_call_wrapper<T, real_fx, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, real_fx, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, std::forward<Fx>(fx).func, std::forward<Args>(args)...);
}
else {
lua_call_wrapper<T, uFx, is_index, is_variable, checked, boost, clean_stack> lcw{};
lua_call_wrapper<T, uFx, is_index, is_variable, checked, boost, clean_stack> lcw {};
return lcw.call(L, std::forward<Fx>(fx), std::forward<Args>(args)...);
}
}
@ -893,38 +898,38 @@ namespace sol {
}
template <typename T, typename = void>
struct is_var_bind : std::false_type {};
struct is_var_bind : std::false_type { };
template <typename T>
struct is_var_bind<T, std::enable_if_t<std::is_member_object_pointer<T>::value>> : std::true_type {};
struct is_var_bind<T, std::enable_if_t<std::is_member_object_pointer<T>::value>> : std::true_type { };
template <typename T>
struct is_var_bind<T, std::enable_if_t<is_lua_reference_or_proxy<T>::value>> : std::true_type {};
struct is_var_bind<T, std::enable_if_t<is_lua_reference_or_proxy<T>::value>> : std::true_type { };
template <>
struct is_var_bind<detail::no_prop> : std::true_type {};
struct is_var_bind<detail::no_prop> : std::true_type { };
template <typename R, typename W>
struct is_var_bind<property_wrapper<R, W>> : std::true_type {};
struct is_var_bind<property_wrapper<R, W>> : std::true_type { };
template <typename T>
struct is_var_bind<var_wrapper<T>> : std::true_type {};
struct is_var_bind<var_wrapper<T>> : std::true_type { };
template <typename T>
struct is_var_bind<readonly_wrapper<T>> : is_var_bind<meta::unqualified_t<T>> {};
struct is_var_bind<readonly_wrapper<T>> : is_var_bind<meta::unqualified_t<T>> { };
template <typename F, typename... Policies>
struct is_var_bind<policy_wrapper<F, Policies...>> : is_var_bind<meta::unqualified_t<F>> {};
struct is_var_bind<policy_wrapper<F, Policies...>> : is_var_bind<meta::unqualified_t<F>> { };
} // namespace call_detail
template <typename T>
struct is_variable_binding : call_detail::is_var_bind<meta::unqualified_t<T>> {};
struct is_variable_binding : call_detail::is_var_bind<meta::unqualified_t<T>> { };
template <typename T>
using is_var_wrapper = meta::is_specialization_of<T, var_wrapper>;
template <typename T>
struct is_function_binding : meta::neg<is_variable_binding<T>> {};
struct is_function_binding : meta::neg<is_variable_binding<T>> { };
} // namespace sol

View File

@ -49,7 +49,7 @@
#define SOL_USE_LUAJIT_I_ SOL_OFF
#endif
#elif defined(LUAJIT_VERSION)
#define SOL_USE_LUAJIT_I_ SOL_OFF
#define SOL_USE_LUAJIT_I_ SOL_ON
#else
#define SOL_USE_LUAJIT_I_ SOL_DEFAULT_OFF
#endif // luajit
@ -171,6 +171,36 @@
#endif
#endif
#if defined (SOL_LUA_BIT32_LIB)
#if SOL_LUA_BIT32_LIB != 0
#define SOL_LUA_BIT32_LIB_I_ SOL_ON
#else
#define SOL_LUA_BIT32_LIB_I_ SOL_OFF
#endif
#else
// Lua 5.2 only (deprecated in 5.3 (503)) (Can be turned on with Compat flags)
// Lua 5.2, or other versions of Lua with the compat flag, or Lua that is not 5.2 with the specific define (5.4.1 either removed it entirely or broke it)
#if (SOL_LUA_VESION_I_ == 502) || (defined(LUA_COMPAT_BITLIB) && (LUA_COMPAT_BITLIB != 0)) || (SOL_LUA_VESION_I_ < 504 && (defined(LUA_COMPAT_5_2) && (LUA_COMPAT_5_2 != 0)))
#define SOL_LUA_BIT32_LIB_I_ SOL_ON
#else
#define SOL_LUA_BIT32_LIB_I_ SOL_DEFAULT_OFF
#endif
#endif
#if defined (SOL_LUA_NIL_IN_TABLES)
#if SOL_LUA_NIL_IN_TABLES != 0
#define SOL_LUA_NIL_IN_TABLES_I_ SOL_ON
#else
#define SOL_LUA_NIL_IN_TABLES_I_ SOL_OFF
#endif
#else
#if defined(LUA_NILINTABLE) && (LUA_NILINTABLE != 0)
#define SOL_LUA_NIL_IN_TABLES_I_ SOL_DEFAULT_ON
#else
#define SOL_LUA_NIL_IN_TABLES_I_ SOL_DEFAULT_OFF
#endif
#endif
// clang-format on
#endif // SOL_COMPATIBILITY_VERSION_HPP

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -27,9 +27,7 @@
#include <sol/stack.hpp>
#include <iostream>
namespace sol {
namespace detail {
namespace debug {
namespace sol { namespace detail { namespace debug {
inline std::string dump_types(lua_State* L) {
std::string visual;
std::size_t size = lua_gettop(L) + 1;
@ -49,8 +47,6 @@ namespace debug {
inline void print_section(const std::string& message, lua_State* L) {
std::cout << "-- " << message << " -- [ " << dump_types(L) << " ]" << std::endl;
}
}
}
} // namespace sol::detail::debug
}}} // namespace sol::detail::debug
#endif // SOL_DEBUG_HPP

View File

@ -154,7 +154,7 @@ namespace sol { namespace detail {
continue;
std::size_t nisopidx = idx - op.size() + 1;
if (nisop == nisopidx) {
idx = static_cast<std::ptrdiff_t>(nisopidx);
idx = static_cast<std::size_t>(nisopidx);
earlybreak = true;
}
break;

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -34,13 +34,11 @@
#endif // compilers
#endif // SOL_DEPRECATED
namespace sol {
namespace detail {
namespace sol { namespace detail {
template <typename T>
struct SOL_DEPRECATED deprecate_type {
using type = T;
};
}
} // namespace sol::detail
}} // namespace sol::detail
#endif // SOL_DEPRECATE_HPP

View File

@ -32,8 +32,8 @@
namespace sol {
namespace detail {
struct direct_error_tag {};
const auto direct_error = direct_error_tag{};
struct direct_error_tag { };
const auto direct_error = direct_error_tag {};
struct error_result {
int results;

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -33,13 +33,13 @@ namespace sol {
namespace detail {
template <>
struct is_speshul<unsafe_function_result> : std::true_type {};
struct is_speshul<unsafe_function_result> : std::true_type { };
template <>
struct is_speshul<protected_function_result> : std::true_type {};
struct is_speshul<protected_function_result> : std::true_type { };
template <std::size_t I, typename... Args, typename T>
stack_proxy get(types<Args...>, meta::index_value<0>, meta::index_value<I>, const T& fr) {
return stack_proxy(fr.lua_state(), static_cast<int>(fr.stack_index() + I));
return stack_proxy(fr.lua_state(), fr.stack_index() + static_cast<int>(I));
}
template <std::size_t I, std::size_t N, typename Arg, typename... Args, typename T, meta::enable<meta::boolean<(N > 0)>> = meta::enabler>
@ -49,14 +49,14 @@ namespace sol {
} // namespace detail
template <>
struct tie_size<unsafe_function_result> : std::integral_constant<std::size_t, SIZE_MAX> {};
struct tie_size<unsafe_function_result> : std::integral_constant<std::size_t, SIZE_MAX> { };
template <>
struct tie_size<protected_function_result> : std::integral_constant<std::size_t, SIZE_MAX> {};
struct tie_size<protected_function_result> : std::integral_constant<std::size_t, SIZE_MAX> { };
template <std::size_t I>
stack_proxy get(const unsafe_function_result& fr) {
return stack_proxy(fr.lua_state(), static_cast<int>(fr.stack_index() + I));
return stack_proxy(fr.lua_state(), fr.stack_index() + static_cast<int>(I));
}
template <std::size_t I, typename... Args>
@ -66,7 +66,7 @@ namespace sol {
template <std::size_t I>
stack_proxy get(const protected_function_result& fr) {
return stack_proxy(fr.lua_state(), static_cast<int>(fr.stack_index() + I));
return stack_proxy(fr.lua_state(), fr.stack_index() + static_cast<int>(I));
}
template <std::size_t I, typename... Args>

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -29,8 +29,7 @@
#include <memory>
namespace sol {
namespace function_detail {
namespace sol { namespace function_detail {
template <typename Fx, int start = 1, bool is_yielding = false>
int call(lua_State* L) {
Fx& fx = stack::get<user<Fx>>(L, upvalue_index(start));
@ -42,7 +41,6 @@ namespace function_detail {
return nr;
}
}
}
} // namespace sol::function_detail
}} // namespace sol::function_detail
#endif // SOL_FUNCTION_TYPES_CORE_HPP

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -28,20 +28,17 @@
#include <sol/call.hpp>
#include <sol/function_types_core.hpp>
namespace sol {
namespace function_detail {
namespace sol { namespace function_detail {
template <int start_skew, typename... Functions>
struct overloaded_function {
typedef std::tuple<Functions...> overload_list;
typedef std::make_index_sequence<sizeof...(Functions)> indices;
overload_list overloads;
overloaded_function(overload_list set)
: overloads(std::move(set)) {
overloaded_function(overload_list set) : overloads(std::move(set)) {
}
overloaded_function(Functions... fxs)
: overloads(fxs...) {
overloaded_function(Functions... fxs) : overloads(fxs...) {
}
template <typename Fx, std::size_t I, typename... R, typename... Args>
@ -56,7 +53,6 @@ namespace function_detail {
return call_detail::overload_match<Functions...>(mfx, L, 1 + start_skew, overloads);
}
};
}
} // namespace sol::function_detail
}} // namespace sol::function_detail
#endif // SOL_FUNCTION_TYPES_OVERLOAD_HPP

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -27,16 +27,14 @@
#include <sol/function_types_core.hpp>
#include <sol/call.hpp>
namespace sol {
namespace function_detail {
namespace sol { namespace function_detail {
template <typename Func, bool is_yielding, bool no_trampoline>
struct functor_function {
typedef std::decay_t<meta::unwrap_unqualified_t<Func>> function_type;
function_type fx;
template <typename... Args>
functor_function(function_type f, Args&&... args)
: fx(std::move(f), std::forward<Args>(args)...) {
functor_function(function_type f, Args&&... args) : fx(std::move(f), std::forward<Args>(args)...) {
}
int call(lua_State* L) {
@ -69,8 +67,7 @@ namespace function_detail {
T member;
template <typename... Args>
member_function(function_type f, Args&&... args)
: invocation(std::move(f)), member(std::forward<Args>(args)...) {
member_function(function_type f, Args&&... args) : invocation(std::move(f)), member(std::forward<Args>(args)...) {
}
int call(lua_State* L) {
@ -99,8 +96,7 @@ namespace function_detail {
typedef std::add_lvalue_reference_t<meta::unwrapped_t<std::remove_reference_t<decltype(detail::deref(member))>>> M;
template <typename... Args>
member_variable(function_type v, Args&&... args)
: var(std::move(v)), member(std::forward<Args>(args)...) {
member_variable(function_type v, Args&&... args) : var(std::move(v)), member(std::forward<Args>(args)...) {
}
int call(lua_State* L) {
@ -132,7 +128,6 @@ namespace function_detail {
return detail::trampoline(L, f);
}
};
}
} // namespace sol::function_detail
}} // namespace sol::function_detail
#endif // SOL_FUNCTION_TYPES_STATEFUL_HPP

View File

@ -30,7 +30,7 @@
namespace sol {
template <typename... Args>
struct base_list {};
struct base_list { };
template <typename... Args>
using bases = base_list<Args...>;
@ -38,7 +38,7 @@ namespace sol {
const auto base_classes = base_classes_tag();
template <typename... Args>
struct is_to_stringable<base_list<Args...>> : std::false_type {};
struct is_to_stringable<base_list<Args...>> : std::false_type { };
namespace detail {
@ -79,7 +79,7 @@ namespace sol {
return ti == usertype_traits<T>::qualified_name() || type_check_bases(bases_t(), ti);
}
template <typename ...Bases>
template <typename... Bases>
static bool type_check_with(const string_view& ti) {
return ti == usertype_traits<T>::qualified_name() || type_check_bases(types<Bases...>(), ti);
}
@ -91,7 +91,8 @@ namespace sol {
template <typename Base, typename... Args>
static void* type_cast_bases(types<Base, Args...>, T* data, const string_view& ti) {
// Make sure to convert to T first, and then dynamic cast to the proper type
return ti != usertype_traits<Base>::qualified_name() ? type_cast_bases(types<Args...>(), data, ti) : static_cast<void*>(static_cast<Base*>(data));
return ti != usertype_traits<Base>::qualified_name() ? type_cast_bases(types<Args...>(), data, ti)
: static_cast<void*>(static_cast<Base*>(data));
}
static void* type_cast(void* voiddata, const string_view& ti) {

View File

@ -126,12 +126,7 @@ namespace sol {
template <typename... Ret, typename... Args>
decltype(auto) call(Args&&... args) {
#if !defined(__clang__) && defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 191200000
// MSVC is ass sometimes
return get<protected_function>().call<Ret...>(std::forward<Args>(args)...);
#else
return get<protected_function>().template call<Ret...>(std::forward<Args>(args)...);
#endif
}
template <typename... Args>

View File

@ -52,7 +52,7 @@ namespace sol {
basic_lua_table(lua_State* L, T&& r) : base_t(L, std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_lua_table>(lua_state(), -1, handler);
#endif // Safety
}
@ -63,14 +63,14 @@ namespace sol {
}
basic_lua_table(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_lua_table>(L, index, handler);
#endif // Safety
}
basic_lua_table(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_lua_table>(lua_state(), -1, handler);
#endif // Safety
}
@ -81,7 +81,7 @@ namespace sol {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
if (!is_table<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_lua_table>(lua_state(), -1, handler);
}
#endif // Safety
@ -90,6 +90,6 @@ namespace sol {
}
};
}
} // namespace sol
#endif // SOL_LUA_TABLE_HPP

View File

@ -67,20 +67,20 @@ namespace sol {
basic_metatable(lua_State* L, T&& r) : base_t(L, std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_metatable>(lua_state(), -1, handler);
#endif // Safety
}
basic_metatable(lua_State* L, int index = -1) : basic_metatable(detail::no_safety, L, index) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_metatable>(L, index, handler);
#endif // Safety
}
basic_metatable(lua_State* L, ref_index index) : basic_metatable(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_metatable>(lua_state(), -1, handler);
#endif // Safety
}
@ -91,7 +91,7 @@ namespace sol {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
if (!is_table<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_metatable>(base_t::lua_state(), -1, handler);
}
#endif // Safety
@ -146,7 +146,7 @@ namespace sol {
else {
// do not change the values in the registry: they need to be present
// no matter what, for safety's sake
//stack::set_field(L, gcmetakey, lua_nil, registry.stack_index());
// stack::set_field(L, gcmetakey, lua_nil, registry.stack_index());
}
}

View File

@ -37,8 +37,7 @@ namespace sol {
typedef basic_object_base<base_type> base_t;
template <bool invert_and_pop = false>
basic_object(std::integral_constant<bool, invert_and_pop>, lua_State* L, int index = -1) noexcept
: base_t(L, index) {
basic_object(std::integral_constant<bool, invert_and_pop>, lua_State* L, int index = -1) noexcept : base_t(L, index) {
if (invert_and_pop) {
lua_pop(L, -index);
}
@ -65,47 +64,37 @@ namespace sol {
public:
basic_object() noexcept = default;
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_object>>, meta::neg<std::is_same<base_type, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_object(T&& r)
: base_t(std::forward<T>(r)) {
template <typename T,
meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_object>>, meta::neg<std::is_same<base_type, stack_reference>>,
is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_object(T&& r) : base_t(std::forward<T>(r)) {
}
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_object(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) {
basic_object(lua_State* L, T&& r) : base_t(L, std::forward<T>(r)) {
}
basic_object(lua_nil_t r)
: base_t(r) {
basic_object(lua_nil_t r) : base_t(r) {
}
basic_object(const basic_object&) = default;
basic_object(basic_object&&) = default;
basic_object(const stack_reference& r) noexcept
: basic_object(r.lua_state(), r.stack_index()) {
basic_object(const stack_reference& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {
}
basic_object(stack_reference&& r) noexcept
: basic_object(r.lua_state(), r.stack_index()) {
basic_object(stack_reference&& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {
}
template <typename Super>
basic_object(const proxy_base<Super>& r) noexcept
: basic_object(r.operator basic_object()) {
basic_object(const proxy_base<Super>& r) noexcept : basic_object(r.operator basic_object()) {
}
template <typename Super>
basic_object(proxy_base<Super>&& r) noexcept
: basic_object(r.operator basic_object()) {
basic_object(proxy_base<Super>&& r) noexcept : basic_object(r.operator basic_object()) {
}
basic_object(lua_State* L, lua_nil_t r) noexcept
: base_t(L, r) {
basic_object(lua_State* L, lua_nil_t r) noexcept : base_t(L, r) {
}
basic_object(lua_State* L, int index = -1) noexcept
: base_t(L, index) {
basic_object(lua_State* L, int index = -1) noexcept : base_t(L, index) {
}
basic_object(lua_State* L, absolute_index index) noexcept
: base_t(L, index) {
basic_object(lua_State* L, absolute_index index) noexcept : base_t(L, index) {
}
basic_object(lua_State* L, raw_index index) noexcept
: base_t(L, index) {
basic_object(lua_State* L, raw_index index) noexcept : base_t(L, index) {
}
basic_object(lua_State* L, ref_index index) noexcept
: base_t(L, index) {
basic_object(lua_State* L, ref_index index) noexcept : base_t(L, index) {
}
template <typename T, typename... Args>
basic_object(lua_State* L, in_place_type_t<T>, Args&&... args) noexcept

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -33,7 +33,7 @@ namespace sol {
class basic_object_base : public ref_t {
private:
using base_t = ref_t;
template <typename T>
decltype(auto) as_stack(std::true_type) const {
return stack::get<T>(base_t::lua_state(), base_t::stack_index());
@ -68,8 +68,7 @@ namespace sol {
basic_object_base& operator=(const basic_object_base&) = default;
basic_object_base& operator=(basic_object_base&&) = default;
template <typename T, typename... Args, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_object_base>>> = meta::enabler>
basic_object_base(T&& arg, Args&&... args)
: base_t(std::forward<T>(arg), std::forward<Args>(args)...) {
basic_object_base(T&& arg, Args&&... args) : base_t(std::forward<T>(arg), std::forward<Args>(args)...) {
}
template <typename T>

View File

@ -87,10 +87,10 @@
#define SOL_TL_GCC_LESS_8_TRIVIALLY_COPY_CONSTRUCTIBLE_MUTEX
namespace sol { namespace detail {
template <class T>
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T> {};
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T> { };
#ifdef _GLIBCXX_VECTOR
template <class T, class A>
struct is_trivially_copy_constructible<std::vector<T, A>> : std::is_trivially_copy_constructible<T> {};
struct is_trivially_copy_constructible<std::vector<T, A>> : std::is_trivially_copy_constructible<T> { };
#endif
}} // namespace sol::detail
#endif
@ -121,7 +121,7 @@ namespace sol {
#ifndef SOL_TL_MONOSTATE_INPLACE_MUTEX
#define SOL_TL_MONOSTATE_INPLACE_MUTEX
/// \brief Used to represent an optional with no data; essentially a bool
class monostate {};
class monostate { };
#endif
template <class T>
@ -145,11 +145,11 @@ namespace sol {
// std::conjunction from C++17
template <class...>
struct conjunction : std::true_type {};
struct conjunction : std::true_type { };
template <class B>
struct conjunction<B> : B {};
struct conjunction<B> : B { };
template <class B, class... Bs>
struct conjunction<B, Bs...> : std::conditional<bool(B::value), conjunction<Bs...>, B>::type {};
struct conjunction<B, Bs...> : std::conditional<bool(B::value), conjunction<Bs...>, B>::type { };
#if defined(_LIBCPP_VERSION) && __cplusplus == 201103L
#define SOL_TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND
@ -160,26 +160,26 @@ namespace sol {
// in some cases. This is a check to workaround the common failing case.
#ifdef SOL_TL_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND
template <class T>
struct is_pointer_to_non_const_member_func : std::false_type {};
struct is_pointer_to_non_const_member_func : std::false_type { };
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)> : std::true_type { };
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...)&> : std::true_type { };
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) &&> : std::true_type { };
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile> : std::true_type { };
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile&> : std::true_type { };
template <class T, class Ret, class... Args>
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile&&> : std::true_type {};
struct is_pointer_to_non_const_member_func<Ret (T::*)(Args...) volatile&&> : std::true_type { };
template <class T>
struct is_const_or_const_ref : std::false_type {};
struct is_const_or_const_ref : std::false_type { };
template <class T>
struct is_const_or_const_ref<T const&> : std::true_type {};
struct is_const_or_const_ref<T const&> : std::true_type { };
template <class T>
struct is_const_or_const_ref<T const> : std::true_type {};
struct is_const_or_const_ref<T const> : std::true_type { };
#endif
// std::invoke from C++17
@ -226,9 +226,9 @@ namespace sol {
// Trait for checking if a type is a sol::optional
template <class T>
struct is_optional_impl : std::false_type {};
struct is_optional_impl : std::false_type { };
template <class T>
struct is_optional_impl<optional<T>> : std::true_type {};
struct is_optional_impl<optional<T>> : std::true_type { };
template <class T>
using is_optional = is_optional_impl<decay_t<T>>;
@ -243,7 +243,7 @@ namespace sol {
template <class F, class = void, class... U>
struct returns_void_impl;
template <class F, class... U>
struct returns_void_impl<F, void_t<invoke_result_t<F, U...>>, U...> : std::is_void<invoke_result_t<F, U...>> {};
struct returns_void_impl<F, void_t<invoke_result_t<F, U...>>, U...> : std::is_void<invoke_result_t<F, U...>> { };
template <class F, class... U>
using returns_void = returns_void_impl<F, void, U...>;
@ -281,16 +281,16 @@ namespace sol {
#ifdef _MSC_VER
// TODO make a version which works with MSVC
template <class T, class U = T>
struct is_swappable : std::true_type {};
struct is_swappable : std::true_type { };
template <class T, class U = T>
struct is_nothrow_swappable : std::true_type {};
struct is_nothrow_swappable : std::true_type { };
#else
// https://stackoverflow.com/questions/26744589/what-is-a-proper-way-to-implement-is-swappable-to-test-for-the-swappable-concept
namespace swap_adl_tests {
// if swap ADL finds this then it would call std::swap otherwise (same
// signature)
struct tag {};
struct tag { };
template <class T>
tag swap(T&, T&);
@ -311,32 +311,32 @@ namespace sol {
template <class T>
struct is_std_swap_noexcept
: std::integral_constant<bool, std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value> {};
: std::integral_constant<bool, std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value> { };
template <class T, std::size_t N>
struct is_std_swap_noexcept<T[N]> : is_std_swap_noexcept<T> {};
struct is_std_swap_noexcept<T[N]> : is_std_swap_noexcept<T> { };
template <class T, class U>
struct is_adl_swap_noexcept : std::integral_constant<bool, noexcept(can_swap<T, U>(0))> {};
struct is_adl_swap_noexcept : std::integral_constant<bool, noexcept(can_swap<T, U>(0))> { };
} // namespace swap_adl_tests
template <class T, class U = T>
struct is_swappable : std::integral_constant<bool,
decltype(detail::swap_adl_tests::can_swap<T, U>(0))::value
&& (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value
|| (std::is_move_assignable<T>::value && std::is_move_constructible<T>::value))> {};
|| (std::is_move_assignable<T>::value && std::is_move_constructible<T>::value))> { };
template <class T, std::size_t N>
struct is_swappable<T[N], T[N]> : std::integral_constant<bool,
decltype(detail::swap_adl_tests::can_swap<T[N], T[N]>(0))::value
&& (!decltype(detail::swap_adl_tests::uses_std<T[N], T[N]>(0))::value || is_swappable<T, T>::value)> {};
&& (!decltype(detail::swap_adl_tests::uses_std<T[N], T[N]>(0))::value || is_swappable<T, T>::value)> { };
template <class T, class U = T>
struct is_nothrow_swappable
: std::integral_constant<bool,
is_swappable<T, U>::value
&& ((decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value&& detail::swap_adl_tests::is_std_swap_noexcept<T>::value)
|| (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value&& detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> {};
|| (!decltype(detail::swap_adl_tests::uses_std<T, U>(0))::value&& detail::swap_adl_tests::is_adl_swap_noexcept<T, U>::value))> { };
#endif
// The storage base manages the actual storage, and correctly propagates
@ -358,7 +358,7 @@ namespace sol {
}
}
struct dummy {};
struct dummy { };
union {
dummy m_dummy;
T m_value;
@ -379,7 +379,7 @@ namespace sol {
// No destructor, so this class is trivially destructible
struct dummy {};
struct dummy { };
union {
dummy m_dummy;
T m_value;
@ -1608,7 +1608,7 @@ namespace sol {
}
namespace detail {
struct i_am_secret {};
struct i_am_secret { };
} // namespace detail
template <class T = detail::i_am_secret, class U, class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
@ -1627,7 +1627,7 @@ namespace sol {
#if __cplusplus >= 201703L
template <class T>
optional(T)->optional<T>;
optional(T) -> optional<T>;
#endif
/// \exclude

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -32,8 +32,7 @@ namespace sol {
struct overload_set {
std::tuple<Functions...> functions;
template <typename Arg, typename... Args, meta::disable<std::is_same<overload_set, meta::unqualified_t<Arg>>> = meta::enabler>
overload_set(Arg&& arg, Args&&... args)
: functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
overload_set(Arg&& arg, Args&&... args) : functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
}
overload_set(const overload_set&) = default;
overload_set(overload_set&&) = default;

View File

@ -38,10 +38,11 @@ namespace sol {
template <typename T>
using is_explicitly_dereferenceable_test = decltype(std::declval<T>().operator*());
}
} // namespace meta_detail
template <typename T>
using is_pointer_like = std::integral_constant<bool, !std::is_array_v<T> && (std::is_pointer_v<T> || is_detected_v<meta_detail::is_explicitly_dereferenceable_test, T>)>;
using is_pointer_like = std::integral_constant<bool,
!std::is_array_v<T> && (std::is_pointer_v<T> || is_detected_v<meta_detail::is_explicitly_dereferenceable_test, T>)>;
template <typename T>
constexpr inline bool is_pointer_like_v = is_pointer_like<T>::value;

View File

@ -30,14 +30,14 @@
namespace sol {
namespace detail {
struct policy_base_tag {};
struct policy_base_tag { };
} // namespace detail
template <int Target, int... In>
struct static_stack_dependencies : detail::policy_base_tag {};
struct static_stack_dependencies : detail::policy_base_tag { };
typedef static_stack_dependencies<-1, 1> self_dependency;
template <int... In>
struct returns_self_with : detail::policy_base_tag {};
struct returns_self_with : detail::policy_base_tag { };
typedef returns_self_with<> returns_self;
struct stack_dependencies : detail::policy_base_tag {
@ -48,7 +48,7 @@ namespace sol {
template <typename... Args>
stack_dependencies(int stack_target, Args&&... args) : target(stack_target), stack_indices(), len(sizeof...(Args)) {
std::size_t i = 0;
(void)detail::swallow{ int(), (stack_indices[i++] = static_cast<int>(std::forward<Args>(args)), int())... };
(void)detail::swallow { int(), (stack_indices[i++] = static_cast<int>(std::forward<Args>(args)), int())... };
}
int& operator[](std::size_t i) {

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -34,8 +34,7 @@ namespace sol {
T value;
template <typename Arg, typename... Args, meta::disable<std::is_same<protect_t, meta::unqualified_t<Arg>>> = meta::enabler>
protect_t(Arg&& arg, Args&&... args)
: value(std::forward<Arg>(arg), std::forward<Args>(args)...) {
protect_t(Arg&& arg, Args&&... args) : value(std::forward<Arg>(arg), std::forward<Args>(args)...) {
}
protect_t(const protect_t&) = default;

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -30,84 +30,79 @@
#include <sol/unsafe_function.hpp>
#include <cstdint>
namespace sol {
namespace detail {
inline const char(&default_handler_name())[9]{
static const char name[9] = "sol.\xF0\x9F\x94\xA9";
return name;
namespace sol { namespace detail {
inline const char (&default_handler_name())[9] {
static const char name[9] = "sol.\xF0\x9F\x94\xA9";
return name;
}
template <bool b, typename target_t = reference>
struct protected_handler {
typedef is_stack_based<target_t> is_stack;
const target_t& target;
int stackindex;
protected_handler(std::false_type, const target_t& target) : target(target), stackindex(0) {
if (b) {
stackindex = lua_gettop(target.lua_state()) + 1;
target.push();
}
}
template <bool b, typename target_t = reference>
struct protected_handler {
typedef is_stack_based<target_t> is_stack;
const target_t& target;
int stackindex;
protected_handler(std::false_type, const target_t& target)
: target(target), stackindex(0) {
if (b) {
stackindex = lua_gettop(target.lua_state()) + 1;
target.push();
}
protected_handler(std::true_type, const target_t& target) : target(target), stackindex(0) {
if (b) {
stackindex = target.stack_index();
}
protected_handler(std::true_type, const target_t& target)
: target(target), stackindex(0) {
if (b) {
stackindex = target.stack_index();
}
}
protected_handler(const target_t& target)
: protected_handler(is_stack(), target) {
}
bool valid() const noexcept {
return b;
}
~protected_handler() {
if constexpr (!is_stack::value) {
if (stackindex != 0) {
lua_remove(target.lua_state(), stackindex);
}
}
}
};
template <typename base_t, typename T>
basic_function<base_t> force_cast(T& p) {
return p;
}
template <typename Reference, bool is_main_ref = false>
static Reference get_default_handler(lua_State* L) {
if (is_stack_based<Reference>::value || L == nullptr)
return Reference(L, lua_nil);
L = is_main_ref ? main_thread(L, L) : L;
lua_getglobal(L, default_handler_name());
auto pp = stack::pop_n(L, 1);
return Reference(L, -1);
protected_handler(const target_t& target) : protected_handler(is_stack(), target) {
}
template <typename T>
static void set_default_handler(lua_State* L, const T& ref) {
if (L == nullptr) {
return;
bool valid() const noexcept {
return b;
}
~protected_handler() {
if constexpr (!is_stack::value) {
if (stackindex != 0) {
lua_remove(target.lua_state(), stackindex);
}
}
if (!ref.valid()) {
}
};
template <typename base_t, typename T>
basic_function<base_t> force_cast(T& p) {
return p;
}
template <typename Reference, bool is_main_ref = false>
static Reference get_default_handler(lua_State* L) {
if (is_stack_based<Reference>::value || L == nullptr)
return Reference(L, lua_nil);
L = is_main_ref ? main_thread(L, L) : L;
lua_getglobal(L, default_handler_name());
auto pp = stack::pop_n(L, 1);
return Reference(L, -1);
}
template <typename T>
static void set_default_handler(lua_State* L, const T& ref) {
if (L == nullptr) {
return;
}
if (!ref.valid()) {
#if SOL_IS_ON(SOL_SAFE_STACK_CHECK_I_)
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
#endif // make sure stack doesn't overflow
lua_pushnil(L);
lua_setglobal(L, default_handler_name());
}
else {
ref.push(L);
lua_setglobal(L, default_handler_name());
}
lua_pushnil(L);
lua_setglobal(L, default_handler_name());
}
} // namespace detail
} // namespace sol
else {
ref.push(L);
lua_setglobal(L, default_handler_name());
}
}
}} // namespace sol::detail
#endif // SOL_PROTECTED_HANDLER_HPP

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -35,7 +35,7 @@ namespace sol {
template <typename T, typename... Args>
static void construct(T&& obj, Args&&... args) {
typedef meta::unqualified_t<T> Tu;
std::allocator<Tu> alloc{};
std::allocator<Tu> alloc {};
std::allocator_traits<std::allocator<Tu>>::construct(alloc, std::forward<T>(obj), std::forward<Args>(args)...);
}
@ -48,7 +48,7 @@ namespace sol {
struct default_destruct {
template <typename T>
static void destroy(T&& obj) {
std::allocator<meta::unqualified_t<T>> alloc{};
std::allocator<meta::unqualified_t<T>> alloc {};
alloc.destroy(obj);
}
@ -80,11 +80,10 @@ namespace sol {
struct tagged {
private:
T value_;
public:
template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, tagged>> = meta::enabler>
tagged(Arg&& arg, Args&&... args)
: value_(std::forward<Arg>(arg), std::forward<Args>(args)...) {
tagged(Arg&& arg, Args&&... args) : value_(std::forward<Arg>(arg), std::forward<Args>(args)...) {
}
T& value() & {
@ -102,25 +101,24 @@ namespace sol {
} // namespace detail
template <typename... Args>
struct constructor_list {};
struct constructor_list { };
template <typename... Args>
using constructors = constructor_list<Args...>;
const auto default_constructor = constructors<types<>>{};
const auto default_constructor = constructors<types<>> {};
struct no_construction {};
const auto no_constructor = no_construction{};
struct no_construction { };
const auto no_constructor = no_construction {};
struct call_construction {};
const auto call_constructor = call_construction{};
struct call_construction { };
const auto call_constructor = call_construction {};
template <typename... Functions>
struct constructor_wrapper {
std::tuple<Functions...> functions;
template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, constructor_wrapper>> = meta::enabler>
constructor_wrapper(Arg&& arg, Args&&... args)
: functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
constructor_wrapper(Arg&& arg, Args&&... args) : functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
}
};
@ -133,8 +131,7 @@ namespace sol {
struct factory_wrapper {
std::tuple<Functions...> functions;
template <typename Arg, typename... Args, meta::disable<std::is_same<meta::unqualified_t<Arg>, factory_wrapper>> = meta::enabler>
factory_wrapper(Arg&& arg, Args&&... args)
: functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
factory_wrapper(Arg&& arg, Args&&... args) : functions(std::forward<Arg>(arg), std::forward<Args>(args)...) {
}
};
@ -146,15 +143,14 @@ namespace sol {
template <typename Function>
struct destructor_wrapper {
Function fx;
destructor_wrapper(Function f)
: fx(std::move(f)) {
destructor_wrapper(Function f) : fx(std::move(f)) {
}
};
template <>
struct destructor_wrapper<void> {};
struct destructor_wrapper<void> { };
const destructor_wrapper<void> default_destructor{};
const destructor_wrapper<void> default_destructor {};
template <typename Fx>
inline auto destructor(Fx&& fx) {

View File

@ -33,15 +33,11 @@
#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 SOL_IS_ON(SOL_COMPILER_CLANG_I_)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wconversion"
#elif SOL_IS_ON(SOL_COMPILER_VCXX_I_)
#pragma warning(push)
#pragma warning(disable : 4505) // unreferenced local function has been removed GEE THANKS

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -26,8 +26,7 @@
#include <sol/stack_check_unqualified.hpp>
namespace sol {
namespace stack {
namespace sol { namespace stack {
template <typename X, type expected, typename>
struct qualified_checker {
@ -85,7 +84,6 @@ namespace stack {
}
}
};
}
} // namespace sol::stack
}} // namespace sol::stack
#endif // SOL_STACK_CHECK_HPP

View File

@ -105,8 +105,9 @@ namespace sol {
// use temporary storage to prevent strict UB shenanigans
char alignment_shim[(std::max)({ sizeof(Args)... }) + (std::max)({ alignof(Args)... })] {};
char* start = alignment != nullptr ? static_cast<char*>(alignment) : alignment_shim;
alignment = start;
(void)detail::swallow { int {}, (align_one(std::alignment_of_v<Args>, sizeof(Args), alignment), int {})... };
return static_cast<char*>(alignment) - start;
return static_cast<std::size_t>(static_cast<char*>(alignment) - start);
}
inline void* align_usertype_pointer(void* ptr) {
@ -551,7 +552,7 @@ namespace sol {
}
bool operator()(meta_function mf) const {
bool p = properties[static_cast<int>(mf)];
bool p = properties[static_cast<std::size_t>(mf)];
if (times_through > 0) {
return p;
}
@ -959,10 +960,18 @@ namespace sol {
template <typename T, typename Arg, typename... Args>
int push_reference(lua_State* L, Arg&& arg, Args&&... args) {
using use_reference_tag = meta::all<std::is_lvalue_reference<T>,
meta::neg<std::is_const<std::remove_reference_t<T>>>,
meta::neg<is_lua_primitive<meta::unqualified_t<T>>>,
meta::neg<is_unique_usertype<meta::unqualified_t<T>>>>;
// clang-format off
using use_reference_tag =
meta::all<
meta::neg<is_value_semantic_for_function<T>>
#if SOL_IS_OFF(SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_)
, std::is_lvalue_reference<T>,
meta::neg<std::is_const<std::remove_reference_t<T>>>,
meta::neg<is_lua_primitive<meta::unqualified_t<T>>>,
meta::neg<is_unique_usertype<meta::unqualified_t<T>>>
#endif
>;
// clang-format on
using Tr = meta::conditional_t<use_reference_tag::value, detail::as_reference_tag, meta::unqualified_t<T>>;
return stack::push<Tr>(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
}
@ -998,7 +1007,7 @@ namespace sol {
template <typename T, typename... Args>
int multi_push_reference(lua_State* L, T&& t, Args&&... args) {
int pushcount = push_reference(L, std::forward<T>(t));
int pushcount = stack::push_reference(L, std::forward<T>(t));
void(detail::swallow { (pushcount += stack::push_reference(L, std::forward<Args>(args)), 0)... });
return pushcount;
}

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)

View File

@ -26,15 +26,12 @@
#include <sol/stack_get_unqualified.hpp>
namespace sol {
namespace stack {
namespace sol { namespace stack {
// There are no more enable_ifs that can be used here,
// so this is just for posterity, I guess?
// maybe I'll fill this file in later.
}
} // namespace sol::stack
}} // namespace sol::stack
#endif // SOL_STACK_QUALIFIED_GET_HPP

View File

@ -342,7 +342,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_VESION_I_ >= 600
#if SOL_IS_ON(SOL_LUA_NIL_IN_TABLES_I_) && 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
@ -363,7 +363,7 @@ namespace sol { namespace stack {
if (i == 0) {
break;
}
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600
#if SOL_IS_ON(SOL_LUA_NIL_IN_TABLES_I_) && SOL_LUA_VESION_I_ >= 600
lua_pop(L, vi);
#else
lua_pop(L, (vi + 1));
@ -373,7 +373,7 @@ namespace sol { namespace stack {
}
}
if (isnil) {
#if defined(LUA_NILINTABLE) && LUA_NILINTABLE && SOL_LUA_VESION_I_ >= 600
#if SOL_IS_ON(SOL_LUA_NIL_IN_TABLES_I_) && SOL_LUA_VESION_I_ >= 600
#else
lua_pop(L, lua_size<V>::value);
#endif

View File

@ -31,7 +31,7 @@
namespace sol {
namespace detail {
inline void stack_fail(int, int) {
#if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
#if SOL_IS_OFF(SOL_EXCEPTIONS_I_)
throw error(detail::direct_error, "imbalanced stack after operation finish");
#else
// Lol, what do you want, an error printout? :3c

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -41,14 +41,11 @@ namespace sol {
int stacktop;
proxy_t sp;
stack_iterator()
: L(nullptr), index((std::numeric_limits<int>::max)()), stacktop((std::numeric_limits<int>::max)()), sp() {
stack_iterator() : L(nullptr), index((std::numeric_limits<int>::max)()), stacktop((std::numeric_limits<int>::max)()), sp() {
}
stack_iterator(const stack_iterator<proxy_t, true>& r)
: L(r.L), index(r.index), stacktop(r.stacktop), sp(r.sp) {
stack_iterator(const stack_iterator<proxy_t, true>& r) : L(r.L), index(r.index), stacktop(r.stacktop), sp(r.sp) {
}
stack_iterator(lua_State* luastate, int idx, int topidx)
: L(luastate), index(idx), stacktop(topidx), sp(luastate, idx) {
stack_iterator(lua_State* luastate, int idx, int topidx) : L(luastate), index(idx), stacktop(topidx), sp(luastate, idx) {
}
reference operator*() {
@ -147,7 +144,8 @@ namespace sol {
};
template <typename proxy_t, bool is_const>
inline stack_iterator<proxy_t, is_const> operator+(typename stack_iterator<proxy_t, is_const>::difference_type n, const stack_iterator<proxy_t, is_const>& r) {
inline stack_iterator<proxy_t, is_const> operator+(
typename stack_iterator<proxy_t, is_const>::difference_type n, const stack_iterator<proxy_t, is_const>& r) {
return r + n;
}
} // namespace sol

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -29,8 +29,7 @@
#include <utility>
#include <tuple>
namespace sol {
namespace stack {
namespace sol { namespace stack {
template <typename T, typename>
struct popper {
inline static decltype(auto) pop(lua_State* L) {
@ -40,14 +39,13 @@ namespace stack {
"scope!");
}
else {
record tracking{};
record tracking {};
decltype(auto) r = get<T>(L, -lua_size<T>::value, tracking);
lua_pop(L, tracking.used);
return r;
}
}
};
}
} // namespace sol::stack
}} // namespace sol::stack
#endif // SOL_STACK_POP_HPP

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -28,13 +28,12 @@
#include <sol/stack_field.hpp>
#include <sol/stack_check.hpp>
namespace sol {
namespace stack {
namespace sol { namespace stack {
template <typename T, typename P, bool b, bool raw, typename>
struct probe_field_getter {
template <typename Key>
probe get(lua_State* L, Key&& key, int tableindex = -2) {
if constexpr(!b) {
if constexpr (!b) {
if (!maybe_indexable(L, tableindex)) {
return probe(false, 0);
}
@ -64,7 +63,7 @@ namespace stack {
struct probe_field_getter<std::tuple<Args...>, P, b, raw, C> {
template <std::size_t I, typename Keys>
probe apply(std::index_sequence<I>, int sofar, lua_State* L, Keys&& keys, int tableindex) {
get_field<(I<1) && b, raw>(L, std::get<I>(keys), tableindex);
get_field<(I < 1) && b, raw>(L, std::get<I>(keys), tableindex);
return probe(check<P>(L), sofar);
}
@ -90,7 +89,6 @@ namespace stack {
}
}
};
}
} // namespace sol::stack
}} // namespace sol::stack
#endif // SOL_STACK_PROBE_HPP

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -34,11 +34,9 @@ namespace sol {
int index;
public:
stack_proxy_base()
: L(nullptr), index(0) {
stack_proxy_base() : L(nullptr), index(0) {
}
stack_proxy_base(lua_State* L, int index)
: L(L), index(index) {
stack_proxy_base(lua_State* L, int index) : L(L), index(index) {
}
template <typename T>

View File

@ -688,7 +688,7 @@ namespace sol { namespace stack {
}
static int push(lua_State* L, const char* strb, const char* stre) {
return push_sized(L, strb, stre - strb);
return push_sized(L, strb, static_cast<std::size_t>(stre - strb));
}
static int push(lua_State* L, const char* str, std::size_t len) {
@ -746,7 +746,7 @@ namespace sol { namespace stack {
struct unqualified_pusher<char> {
static int push(lua_State* L, char c) {
const char str[2] = { c, '\0' };
return stack::push(L, static_cast<const char*>(str), 1);
return stack::push(L, static_cast<const char*>(str), 1u);
}
};
@ -915,7 +915,7 @@ namespace sol { namespace stack {
char sbo[SOL_OPTIMIZATION_STRING_CONVERSION_STACK_SIZE_I_];
// if our max string space is small enough, use SBO
// right off the bat
std::size_t max_possible_code_units = (stre - strb) * 4;
std::size_t max_possible_code_units = static_cast<std::size_t>(static_cast<std::size_t>(stre - strb) * static_cast<std::size_t>(4));
if (max_possible_code_units <= SOL_OPTIMIZATION_STRING_CONVERSION_STACK_SIZE_I_) {
return convert_into(L, sbo, max_possible_code_units, strb, stre);
}
@ -992,7 +992,7 @@ namespace sol { namespace stack {
char sbo[SOL_OPTIMIZATION_STRING_CONVERSION_STACK_SIZE_I_];
// if our max string space is small enough, use SBO
// right off the bat
std::size_t max_possible_code_units = (stre - strb) * 4;
std::size_t max_possible_code_units = static_cast<std::size_t>(static_cast<std::size_t>(stre - strb) * static_cast<std::size_t>(4));
if (max_possible_code_units <= SOL_OPTIMIZATION_STRING_CONVERSION_STACK_SIZE_I_) {
return convert_into(L, sbo, max_possible_code_units, strb, stre);
}
@ -1075,7 +1075,7 @@ namespace sol { namespace stack {
struct unqualified_pusher<wchar_t> {
static int push(lua_State* L, wchar_t c) {
const wchar_t str[2] = { c, '\0' };
return stack::push(L, static_cast<const wchar_t*>(str), 1);
return stack::push(L, static_cast<const wchar_t*>(str), 1u);
}
};
@ -1083,7 +1083,7 @@ namespace sol { namespace stack {
struct unqualified_pusher<char16_t> {
static int push(lua_State* L, char16_t c) {
const char16_t str[2] = { c, '\0' };
return stack::push(L, static_cast<const char16_t*>(str), 1);
return stack::push(L, static_cast<const char16_t*>(str), 1u);
}
};
@ -1091,7 +1091,7 @@ namespace sol { namespace stack {
struct unqualified_pusher<char32_t> {
static int push(lua_State* L, char32_t c) {
const char32_t str[2] = { c, '\0' };
return stack::push(L, static_cast<const char32_t*>(str), 1);
return stack::push(L, static_cast<const char32_t*>(str), 1u);
}
};

View File

@ -41,7 +41,7 @@ namespace sol {
class stateless_stack_reference {
private:
friend class stack_reference;
int index = 0;
int registry_index() const noexcept {
@ -50,7 +50,7 @@ namespace sol {
public:
stateless_stack_reference() noexcept = default;
stateless_stack_reference(lua_nil_t) noexcept : stateless_stack_reference(){};
stateless_stack_reference(lua_nil_t) noexcept : stateless_stack_reference() {};
stateless_stack_reference(lua_State* L, int i) noexcept : stateless_stack_reference(absolute_index(L, i)) {
}
stateless_stack_reference(lua_State*, absolute_index i) noexcept : stateless_stack_reference(i) {
@ -111,8 +111,7 @@ namespace sol {
public:
stack_reference() noexcept = default;
stack_reference(lua_nil_t) noexcept
: stack_reference() {};
stack_reference(lua_nil_t) noexcept : stack_reference() {};
stack_reference(lua_State* L, lua_nil_t) noexcept : stateless_stack_reference(L, 0), luastate(L) {
}
stack_reference(lua_State* L, int i) noexcept : stateless_stack_reference(L, i), luastate(L) {
@ -123,8 +122,7 @@ namespace sol {
}
stack_reference(lua_State* L, ref_index i) noexcept = delete;
stack_reference(lua_State* L, const reference& r) noexcept = delete;
stack_reference(lua_State* L, const stack_reference& r) noexcept
: luastate(L) {
stack_reference(lua_State* L, const stack_reference& r) noexcept : luastate(L) {
if (!r.valid()) {
index = 0;
return;
@ -177,7 +175,7 @@ namespace sol {
return stateless_stack_reference::valid(lua_state());
}
void abandon () {
void abandon() {
stateless_stack_reference::abandon(lua_state());
}
};

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -34,8 +34,7 @@ namespace sol {
typedef std::unique_ptr<lua_State, detail::state_deleter> unique_base;
public:
state(lua_CFunction panic = default_at_panic)
: unique_base(luaL_newstate()), state_view(unique_base::get()) {
state(lua_CFunction panic = default_at_panic) : unique_base(luaL_newstate()), state_view(unique_base::get()) {
set_default_state(unique_base::get(), panic);
}

View File

@ -105,9 +105,9 @@ namespace sol {
}
inline std::size_t total_memory_used(lua_State* L) {
std::size_t kb = lua_gc(L, LUA_GCCOUNT, 0);
std::size_t kb = static_cast<std::size_t>(lua_gc(L, LUA_GCCOUNT, 0));
kb *= 1024;
kb += lua_gc(L, LUA_GCCOUNTB, 0);
kb += static_cast<std::size_t>(lua_gc(L, LUA_GCCOUNTB, 0));
return kb;
}

View File

@ -120,7 +120,7 @@ namespace sol {
for (auto&& library : libraries) {
switch (library) {
#if SOL_LUA_VESION_I_ <= 501 && defined(SOL_LUAJIT)
#if SOL_LUA_VESION_I_ <= 501 && SOL_IS_ON(SOL_USE_LUAJIT_I_)
case lib::coroutine:
#endif // luajit opens coroutine base stuff
case lib::base:
@ -131,7 +131,7 @@ namespace sol {
luaL_requiref(L, "package", luaopen_package, 1);
lua_pop(L, 1);
break;
#if !defined(SOL_LUAJIT)
#if SOL_IS_OFF(SOL_USE_LUAJIT_I_)
case lib::coroutine:
#if SOL_LUA_VESION_I_ > 501
luaL_requiref(L, "coroutine", luaopen_coroutine, 1);
@ -152,14 +152,14 @@ namespace sol {
lua_pop(L, 1);
break;
case lib::bit32:
#ifdef SOL_LUAJIT
#if SOL_IS_ON(SOL_USE_LUAJIT_I_)
luaL_requiref(L, "bit32", luaopen_bit, 1);
lua_pop(L, 1);
#elif (SOL_LUA_VESION_I_ == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2)
#elif SOL_IS_ON(SOL_LUA_BIT32_LIB_I_)
luaL_requiref(L, "bit32", luaopen_bit32, 1);
lua_pop(L, 1);
#else
#endif // Lua 5.2 only (deprecated in 5.3 (503)) (Can be turned on with Compat flags)
#endif
break;
case lib::io:
luaL_requiref(L, "io", luaopen_io, 1);
@ -174,19 +174,19 @@ namespace sol {
lua_pop(L, 1);
break;
case lib::utf8:
#if SOL_LUA_VESION_I_ > 502 && !defined(SOL_LUAJIT)
#if SOL_LUA_VESION_I_ > 502 && SOL_IS_OFF(SOL_USE_LUAJIT_I_)
luaL_requiref(L, "utf8", luaopen_utf8, 1);
lua_pop(L, 1);
#endif // Lua 5.3+ only
break;
case lib::ffi:
#ifdef SOL_LUAJIT
#if SOL_IS_ON(SOL_USE_LUAJIT_I_)
luaL_requiref(L, "ffi", luaopen_ffi, 1);
lua_pop(L, 1);
#endif // LuaJIT only
break;
case lib::jit:
#ifdef SOL_LUAJIT
#if SOL_IS_ON(SOL_USE_LUAJIT_I_)
luaL_requiref(L, "jit", luaopen_jit, 0);
lua_pop(L, 1);
#endif // LuaJIT Only

View File

@ -55,8 +55,8 @@ namespace sol {
enrollments.default_constructor = !detail::any_is_constructor_v<Arg, Args...>;
enrollments.destructor = !detail::any_is_destructor_v<Arg, Args...>;
usertype<Class> ut = this->new_usertype<Class>(std::forward<Key>(key), std::move(enrollments));
static_assert(sizeof...(Args) % 2 == static_cast<std::size_t>(!detail::any_is_constructor_v<Arg>),
"you must pass an even number of arguments to new_usertype after first passing a constructor");
static_assert(sizeof...(Args) % 2 == static_cast<std::size_t>(!detail::any_is_constructor_v<Arg>),
"you must pass an even number of arguments to new_usertype after first passing a constructor");
if constexpr (detail::any_is_constructor_v<Arg>) {
ut.set(meta_function::construct, std::forward<Arg>(arg));
ut.tuple_set(std::make_index_sequence<(sizeof...(Args)) / 2>(), std::forward_as_tuple(std::forward<Args>(args)...));

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -33,8 +33,7 @@ namespace sol {
struct lua_thread_state {
lua_State* L;
lua_thread_state(lua_State* Ls)
: L(Ls) {
lua_thread_state(lua_State* Ls) : L(Ls) {
}
lua_State* lua_state() const noexcept {
@ -61,7 +60,7 @@ namespace sol {
struct unqualified_getter<lua_thread_state> {
lua_thread_state get(lua_State* L, int index, record& tracking) {
tracking.use(1);
lua_thread_state lts( lua_tothread(L, index) );
lua_thread_state lts(lua_tothread(L, index));
return lts;
}
};
@ -70,7 +69,7 @@ namespace sol {
struct unqualified_check_getter<lua_thread_state> {
template <typename Handler>
optional<lua_thread_state> get(lua_State* L, int index, Handler&& handler, record& tracking) {
lua_thread_state lts( lua_tothread(L, index) );
lua_thread_state lts(lua_tothread(L, index));
if (lts.lua_state() == nullptr) {
handler(L, index, type::thread, type_of(L, index), "value is not a valid thread type");
return nullopt;
@ -92,55 +91,47 @@ namespace sol {
basic_thread() noexcept = default;
basic_thread(const basic_thread&) = default;
basic_thread(basic_thread&&) = default;
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_thread>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_thread(T&& r)
: base_t(std::forward<T>(r)) {
template <typename T,
meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_thread>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_thread(T&& r) : base_t(std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_thread>(lua_state(), -1, handler);
#endif // Safety
}
basic_thread(const stack_reference& r)
: basic_thread(r.lua_state(), r.stack_index()){};
basic_thread(stack_reference&& r)
: basic_thread(r.lua_state(), r.stack_index()){};
basic_thread(const stack_reference& r) : basic_thread(r.lua_state(), r.stack_index()) {};
basic_thread(stack_reference&& r) : basic_thread(r.lua_state(), r.stack_index()) {};
basic_thread& operator=(const basic_thread&) = default;
basic_thread& operator=(basic_thread&&) = default;
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_thread(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) {
basic_thread(lua_State* L, T&& r) : base_t(L, std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_thread>(lua_state(), -1, handler);
#endif // Safety
}
basic_thread(lua_State* L, int index = -1)
: base_t(L, index) {
basic_thread(lua_State* L, int index = -1) : base_t(L, index) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_thread>(L, index, handler);
#endif // Safety
}
basic_thread(lua_State* L, ref_index index)
: base_t(L, index) {
basic_thread(lua_State* L, ref_index index) : base_t(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_thread>(lua_state(), -1, handler);
#endif // Safety
}
basic_thread(lua_State* L, lua_State* actualthread)
: basic_thread(L, lua_thread_state{ actualthread }) {
basic_thread(lua_State* L, lua_State* actualthread) : basic_thread(L, lua_thread_state { actualthread }) {
}
basic_thread(lua_State* L, this_state actualthread)
: basic_thread(L, lua_thread_state{ actualthread.L }) {
basic_thread(lua_State* L, this_state actualthread) : basic_thread(L, lua_thread_state { actualthread.L }) {
}
basic_thread(lua_State* L, lua_thread_state actualthread)
: base_t(L, -stack::push(L, actualthread)) {
basic_thread(lua_State* L, lua_thread_state actualthread) : base_t(L, -stack::push(L, actualthread)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_thread>(lua_state(), -1, handler);
#endif // Safety
if (!is_stack_based<base_t>::value) {

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -30,14 +30,14 @@ namespace sol {
namespace detail {
template <typename T>
struct is_speshul : std::false_type {};
struct is_speshul : std::false_type { };
} // namespace detail
template <typename T>
struct tie_size : std::tuple_size<T> {};
struct tie_size : std::tuple_size<T> { };
template <typename T>
struct is_tieable : std::integral_constant<bool, (::sol::tie_size<T>::value > 0)> {};
struct is_tieable : std::integral_constant<bool, (::sol::tie_size<T>::value > 0)> { };
template <typename... Tn>
struct tie_t : public std::tuple<std::add_lvalue_reference_t<Tn>...> {
@ -61,15 +61,13 @@ namespace sol {
template <std::size_t... I, typename T>
void set_extra(std::true_type, std::index_sequence<I...>, T&& target) {
using std::get;
(void)detail::swallow{0,
(get<I>(static_cast<base_t&>(*this)) = get<I>(types<Tn...>(), target), 0)..., 0};
(void)detail::swallow { 0, (get<I>(static_cast<base_t&>(*this)) = get<I>(types<Tn...>(), target), 0)..., 0 };
}
template <std::size_t... I, typename T>
void set_extra(std::false_type, std::index_sequence<I...>, T&& target) {
using std::get;
(void)detail::swallow{0,
(get<I>(static_cast<base_t&>(*this)) = get<I>(target), 0)..., 0};
(void)detail::swallow { 0, (get<I>(static_cast<base_t&>(*this)) = get<I>(target), 0)..., 0 };
}
public:
@ -84,7 +82,7 @@ namespace sol {
};
template <typename... Tn>
struct tie_size<tie_t<Tn...>> : std::tuple_size<std::tuple<Tn...>> {};
struct tie_size<tie_t<Tn...>> : std::tuple_size<std::tuple<Tn...>> { };
namespace adl_barrier_detail {
template <typename... Tn>

View File

@ -49,7 +49,7 @@ namespace sol {
inline int default_exception_handler(lua_State* L, optional<const std::exception&>, string_view what) {
#if SOL_IS_ON(SOL_PRINT_ERRORS_I_)
std::cerr << "[sol3] An exception occurred: ";
std::cerr.write(what.data(), what.size());
std::cerr.write(what.data(), static_cast<std::streamsize>(what.size()));
std::cerr << std::endl;
#endif
lua_pushlstring(L, what.data(), what.size());

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -44,10 +44,14 @@ namespace sol {
namespace detail {
template <typename... Args>
struct tuple_types_ { typedef types<Args...> type; };
struct tuple_types_ {
typedef types<Args...> type;
};
template <typename... Args>
struct tuple_types_<std::tuple<Args...>> { typedef types<Args...> type; };
struct tuple_types_<std::tuple<Args...>> {
typedef types<Args...> type;
};
} // namespace detail
template <typename... Args>

View File

@ -233,7 +233,7 @@ namespace sol {
operator std::add_lvalue_reference_t<U>() {
return value;
}
operator std::add_const_t<std::add_lvalue_reference_t<U>> &() const {
operator std::add_const_t<std::add_lvalue_reference_t<U>>&() const {
return value;
}
};
@ -578,7 +578,7 @@ namespace sol {
const new_table create = {};
enum class lib : char {
enum class lib : unsigned char {
// print, assert, and other base functions
base,
// require and other package functions
@ -752,7 +752,7 @@ namespace sol {
return names[static_cast<std::size_t>(c)];
}
enum class meta_function {
enum class meta_function : unsigned {
construct,
index,
new_index,
@ -841,7 +841,7 @@ namespace sol {
}
inline const std::string& to_string(meta_function mf) {
return meta_function_names()[static_cast<int>(mf)];
return meta_function_names()[static_cast<std::size_t>(mf)];
}
inline type type_of(lua_State* L, int index) {
@ -1169,6 +1169,19 @@ namespace sol {
template <typename T>
constexpr inline bool is_lua_primitive_v = is_lua_primitive<T>::value;
template <typename T>
struct is_value_semantic_for_function
#if SOL_IS_ON(SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_)
: std::true_type {
};
#else
: std::false_type {
};
#endif
template <typename T>
constexpr inline bool is_value_semantic_for_function_v = is_value_semantic_for_function<T>::value;
template <typename T>
struct is_main_threaded : std::is_base_of<main_reference, T> { };

View File

@ -19,15 +19,13 @@ namespace sol {
};
inline const string_view& to_string(error_code ec) {
static const string_view storage[7] = {
"ok",
static const string_view storage[7] = { "ok",
"invalid code points",
"invalid code unit",
"invalid leading surrogate",
"invalid trailing surrogate",
"sequence too short",
"overlong sequence"
};
"overlong sequence" };
return storage[static_cast<std::size_t>(ec)];
}
@ -95,19 +93,18 @@ namespace sol {
static constexpr int sequence_length(unsigned char b) {
return (b & start_2byte_mask) == 0 ? 1
: (b & start_3byte_mask) != start_3byte_mask ? 2
: (b & start_4byte_mask) != start_4byte_mask ? 3
: 4;
: (b & start_3byte_mask) != start_3byte_mask ? 2 : (b & start_4byte_mask) != start_4byte_mask ? 3 : 4;
}
static constexpr char32_t decode(unsigned char b0, unsigned char b1) {
return ((b0 & 0x1F) << 6) | (b1 & 0x3F);
return (static_cast<char32_t>((b0 & 0x1Fu) << 6u) | static_cast<char32_t>(b1 & 0x3Fu));
}
static constexpr char32_t decode(unsigned char b0, unsigned char b1, unsigned char b2) {
return ((b0 & 0x0F) << 12) | ((b1 & 0x3F) << 6) | (b2 & 0x3F);
return static_cast<char32_t>((b0 & 0x0Fu) << 12u) | static_cast<char32_t>((b1 & 0x3Fu) << 6u) | static_cast<char32_t>(b2 & 0x3Fu);
}
static constexpr char32_t decode(unsigned char b0, unsigned char b1, unsigned char b2, unsigned char b3) {
return ((b0 & 0x07) << 18) | ((b1 & 0x3F) << 12) | ((b2 & 0x3F) << 6) | (b3 & 0x3F);
return static_cast<char32_t>(static_cast<char32_t>((b0 & 0x07u) << 18u) | static_cast<char32_t>((b1 & 0x3F) << 12)
| static_cast<char32_t>((b2 & 0x3Fu) << 6u) | static_cast<char32_t>(b3 & 0x3Fu));
}
// utf16 related
@ -130,30 +127,30 @@ namespace sol {
er.error = error_code::ok;
if (codepoint <= unicode_detail::last_1byte_value) {
er.code_units_size = 1;
er.code_units = std::array<char, 4>{ { static_cast<char>(codepoint) } };
er.code_units = std::array<char, 4> { { static_cast<char>(codepoint) } };
}
else if (codepoint <= unicode_detail::last_2byte_value) {
er.code_units_size = 2;
er.code_units = std::array<char, 4>{{
er.code_units = std::array<char, 4> { {
static_cast<char>(0xC0 | ((codepoint & 0x7C0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
}};
} };
}
else if (codepoint <= unicode_detail::last_3byte_value) {
er.code_units_size = 3;
er.code_units = std::array<char, 4>{{
er.code_units = std::array<char, 4> { {
static_cast<char>(0xE0 | ((codepoint & 0xF000) >> 12)),
static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
}};
} };
}
else {
er.code_units_size = 4;
er.code_units = std::array<char, 4>{ {
er.code_units = std::array<char, 4> { {
static_cast<char>(0xF0 | ((codepoint & 0x1C0000) >> 18)),
static_cast<char>(0x80 | ((codepoint & 0x3F000) >> 12)),
static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
static_cast<char>(0x80 | ((codepoint & 0x3F000) >> 12)),
static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
} };
}
return er;
@ -164,17 +161,14 @@ namespace sol {
if (codepoint <= unicode_detail::last_bmp_value) {
er.code_units_size = 1;
er.code_units = std::array<char16_t, 4>{ { static_cast<char16_t>(codepoint) } };
er.code_units = std::array<char16_t, 4> { { static_cast<char16_t>(codepoint) } };
er.error = error_code::ok;
}
else {
auto normal = codepoint - unicode_detail::normalizing_value;
auto lead = unicode_detail::first_lead_surrogate + ((normal & unicode_detail::lead_surrogate_bitmask) >> unicode_detail::lead_shifted_bits);
auto trail = unicode_detail::first_trail_surrogate + (normal & unicode_detail::trail_surrogate_bitmask);
er.code_units = std::array<char16_t, 4>{ {
static_cast<char16_t>(lead),
static_cast<char16_t>(trail)
} };
er.code_units = std::array<char16_t, 4> { { static_cast<char16_t>(lead), static_cast<char16_t>(trail) } };
er.code_units_size = 2;
er.error = error_code::ok;
}
@ -198,8 +192,8 @@ namespace sol {
return dr;
}
unsigned char b0 = *it;
std::size_t length = unicode_detail::sequence_length(b0);
unsigned char b0 = static_cast<unsigned char>(*it);
std::size_t length = static_cast<std::size_t>(unicode_detail::sequence_length(b0));
if (length == 1) {
dr.codepoint = static_cast<char32_t>(b0);
@ -219,7 +213,7 @@ namespace sol {
std::array<unsigned char, 4> b;
b[0] = b0;
for (std::size_t i = 1; i < length; ++i) {
b[i] = *it;
b[i] = static_cast<unsigned char>(*it);
if (!unicode_detail::is_continuation(b[i])) {
dr.error = error_code::invalid_code_unit;
dr.next = it;
@ -249,7 +243,7 @@ namespace sol {
dr.error = error_code::invalid_code_point;
return dr;
}
// then everything is fine
dr.codepoint = decoded;
dr.error = error_code::ok;
@ -267,7 +261,7 @@ namespace sol {
}
char16_t lead = static_cast<char16_t>(*it);
if (!unicode_detail::is_surrogate(lead)) {
++it;
dr.codepoint = static_cast<char32_t>(lead);
@ -288,7 +282,7 @@ namespace sol {
dr.next = it;
return dr;
}
dr.codepoint = unicode_detail::combine_surrogates(lead, trail);
dr.next = ++it;
dr.error = error_code::ok;
@ -308,5 +302,5 @@ namespace sol {
dr.error = error_code::ok;
return dr;
}
}
}
} // namespace unicode
} // namespace sol

View File

@ -46,8 +46,8 @@ namespace sol {
}
template <typename U>
static auto get(U&& value) {
return std::addressof(detail::deref(value));
static auto get(U&& value_) {
return std::addressof(detail::deref(value_));
}
};
@ -89,7 +89,7 @@ namespace sol {
};
template <typename T>
struct is_unique_usertype : std::integral_constant<bool, unique_usertype_traits<T>::value> {};
struct is_unique_usertype : std::integral_constant<bool, unique_usertype_traits<T>::value> { };
template <typename T>
inline constexpr bool is_unique_usertype_v = is_unique_usertype<T>::value;
@ -107,11 +107,11 @@ namespace sol {
namespace detail {
template <typename T, typename = void>
struct is_base_rebindable_non_void_sfinae : std::false_type {};
struct is_base_rebindable_non_void_sfinae : std::false_type { };
template <typename T>
struct is_base_rebindable_non_void_sfinae<T, std::enable_if_t<is_base_rebindable_v<T>>>
: std::integral_constant<bool, !std::is_void_v<typename T::template rebind_base<void>>> {};
: std::integral_constant<bool, !std::is_void_v<typename T::template rebind_base<void>>> { };
} // namespace detail
template <typename T>

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -73,13 +73,14 @@ namespace sol {
using base_t::lua_state;
basic_function() = default;
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_function>>, 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_function(T&& r) noexcept
: base_t(std::forward<T>(r)) {
template <typename T,
meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_function>>, 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_function(T&& r) noexcept : base_t(std::forward<T>(r)) {
#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_function>(lua_state(), -1, handler);
}
#endif // Safety
@ -88,36 +89,30 @@ namespace sol {
basic_function& operator=(const basic_function&) = default;
basic_function(basic_function&&) = default;
basic_function& operator=(basic_function&&) = default;
basic_function(const stack_reference& r)
: basic_function(r.lua_state(), r.stack_index()) {
basic_function(const stack_reference& r) : basic_function(r.lua_state(), r.stack_index()) {
}
basic_function(stack_reference&& r)
: basic_function(r.lua_state(), r.stack_index()) {
basic_function(stack_reference&& r) : basic_function(r.lua_state(), r.stack_index()) {
}
basic_function(lua_nil_t n)
: base_t(n) {
basic_function(lua_nil_t n) : base_t(n) {
}
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_function(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) {
basic_function(lua_State* L, T&& r) : base_t(L, std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_function>(lua_state(), -1, handler);
#endif // Safety
}
basic_function(lua_State* L, int index = -1)
: base_t(L, index) {
basic_function(lua_State* L, int index = -1) : base_t(L, index) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_function>(L, index, handler);
#endif // Safety
}
basic_function(lua_State* L, ref_index index)
: base_t(L, index) {
basic_function(lua_State* L, ref_index index) : base_t(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_function>(lua_state(), -1, handler);
#endif // Safety
}

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -37,9 +37,10 @@ namespace sol {
using base_t::lua_state;
basic_userdata() noexcept = default;
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_userdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_userdata(T&& r) noexcept
: base_t(std::forward<T>(r)) {
template <typename T,
meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_userdata>>, meta::neg<std::is_same<base_t, stack_reference>>,
is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_userdata(T&& r) noexcept : base_t(std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
if (!is_userdata<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this);
@ -51,33 +52,28 @@ namespace sol {
basic_userdata(basic_userdata&&) = default;
basic_userdata& operator=(const basic_userdata&) = default;
basic_userdata& operator=(basic_userdata&&) = default;
basic_userdata(const stack_reference& r)
: basic_userdata(r.lua_state(), r.stack_index()) {
basic_userdata(const stack_reference& r) : basic_userdata(r.lua_state(), r.stack_index()) {
}
basic_userdata(stack_reference&& r)
: basic_userdata(r.lua_state(), r.stack_index()) {
basic_userdata(stack_reference&& r) : basic_userdata(r.lua_state(), r.stack_index()) {
}
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_userdata(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) {
basic_userdata(lua_State* L, T&& r) : base_t(L, std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_userdata>(L, -1, handler);
#endif // Safety
}
basic_userdata(lua_State* L, int index = -1)
: base_t(detail::no_safety, L, index) {
basic_userdata(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_userdata>(L, index, handler);
#endif // Safety
}
basic_userdata(lua_State* L, ref_index index)
: base_t(detail::no_safety, L, index) {
basic_userdata(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_userdata>(L, -1, handler);
#endif // Safety
}
@ -91,9 +87,10 @@ namespace sol {
using base_t::lua_state;
basic_lightuserdata() noexcept = default;
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_lightuserdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_lightuserdata(T&& r) noexcept
: base_t(std::forward<T>(r)) {
template <typename T,
meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_lightuserdata>>, meta::neg<std::is_same<base_t, stack_reference>>,
is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_lightuserdata(T&& r) noexcept : base_t(std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
if (!is_lightuserdata<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this);
@ -105,33 +102,28 @@ namespace sol {
basic_lightuserdata(basic_lightuserdata&&) = default;
basic_lightuserdata& operator=(const basic_lightuserdata&) = default;
basic_lightuserdata& operator=(basic_lightuserdata&&) = default;
basic_lightuserdata(const stack_reference& r)
: basic_lightuserdata(r.lua_state(), r.stack_index()) {
basic_lightuserdata(const stack_reference& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {
}
basic_lightuserdata(stack_reference&& r)
: basic_lightuserdata(r.lua_state(), r.stack_index()) {
basic_lightuserdata(stack_reference&& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {
}
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_lightuserdata(lua_State* L, T&& r)
: basic_lightuserdata(L, std::forward<T>(r)) {
basic_lightuserdata(lua_State* L, T&& r) : basic_lightuserdata(L, std::forward<T>(r)) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
auto pp = stack::push_pop(*this);
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_lightuserdata>(lua_state(), -1, handler);
#endif // Safety
}
basic_lightuserdata(lua_State* L, int index = -1)
: base_t(L, index) {
basic_lightuserdata(lua_State* L, int index = -1) : base_t(L, index) {
#if SOL_IS_ON(SOL_SAFE_REFERENCES_I_)
constructor_handler handler{};
constructor_handler handler {};
stack::check<basic_lightuserdata>(L, index, handler);
#endif // Safety
}
basic_lightuserdata(lua_State* L, ref_index index)
: base_t(L, index) {
basic_lightuserdata(lua_State* L, ref_index index) : base_t(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_lightuserdata>(lua_state(), index, handler);
#endif // Safety
}

View File

@ -47,20 +47,19 @@ namespace sol {
template <std::size_t... I, typename... Args>
void tuple_set(std::index_sequence<I...>, std::tuple<Args...>&& args) {
(void)args;
(void)detail::swallow{ 0,
(this->set(std::get<I * 2>(std::move(args)), std::get<I * 2 + 1>(std::move(args))), 0)... };
(void)detail::swallow { 0, (this->set(std::get<I * 2>(std::move(args)), std::get<I * 2 + 1>(std::move(args))), 0)... };
}
public:
using base_t::base_t;
using base_t::get;
using base_t::lua_state;
using base_t::pop;
using base_t::push;
using base_t::lua_state;
using base_t::get;
using base_t::set_function;
using base_t::traverse_set;
using base_t::traverse_get;
using base_t::traverse_set;
using base_t::unregister;
template <typename Key, typename Value>

View File

@ -355,10 +355,10 @@ namespace sol {
using has_traits_erase = meta::boolean<has_traits_erase_test<T>::value>;
template <typename T>
struct is_forced_container : is_container<T> {};
struct is_forced_container : is_container<T> { };
template <typename T>
struct is_forced_container<as_container_t<T>> : std::true_type {};
struct is_forced_container<as_container_t<T>> : std::true_type { };
template <typename T>
struct container_decay {
@ -587,7 +587,7 @@ namespace sol {
}
static detail::error_result get_category(std::input_iterator_tag, lua_State* L, T& self, K& key) {
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(key + deferred_uc::index_adjustment(L, self));
if (key < 0) {
return stack::push(L, lua_nil);
}
@ -608,7 +608,7 @@ namespace sol {
static detail::error_result get_category(std::random_access_iterator_tag, lua_State* L, T& self, K& key) {
std::ptrdiff_t len = static_cast<std::ptrdiff_t>(size_start(L, self));
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
if (key < 0 || key >= len) {
return stack::push(L, lua_nil);
}
@ -663,7 +663,7 @@ namespace sol {
static detail::error_result set_category(std::input_iterator_tag, lua_State* L, T& self, stack_object okey, stack_object value) {
decltype(auto) key = okey.as<K>();
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
auto e = deferred_uc::end(L, self);
auto it = deferred_uc::begin(L, self);
auto backit = it;
@ -681,7 +681,7 @@ namespace sol {
static detail::error_result set_category(std::random_access_iterator_tag, lua_State* L, T& self, stack_object okey, stack_object value) {
decltype(auto) key = okey.as<K>();
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
if (key < 0) {
return detail::error_result("sol: out of bounds (too small) for set on '%s'", detail::demangle<T>().c_str());
}
@ -828,7 +828,7 @@ namespace sol {
template <typename Iter>
static detail::error_result find_associative_lookup(std::false_type, lua_State* L, T& self, Iter&, std::size_t idx) {
idx -= deferred_uc::index_adjustment(L, self);
idx = static_cast<std::size_t>(static_cast<std::ptrdiff_t>(idx) + deferred_uc::index_adjustment(L, self));
return stack::push(L, idx);
}
@ -879,8 +879,7 @@ namespace sol {
auto backit = self.before_begin();
{
auto e = deferred_uc::end(L, self);
for (auto it = deferred_uc::begin(L, self); it != e; ++backit, ++it) {
}
for (auto it = deferred_uc::begin(L, self); it != e; ++backit, ++it) { }
}
return add_insert_after(std::true_type(), L, self, value, backit);
}
@ -981,7 +980,7 @@ namespace sol {
static detail::error_result insert_lookup(std::false_type, lua_State* L, T& self, stack_object where, stack_object value) {
auto it = deferred_uc::begin(L, self);
auto key = where.as<K>();
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
std::advance(it, key);
self.insert(it, value.as<V>());
return {};
@ -991,7 +990,7 @@ namespace sol {
auto key = where.as<K>();
auto backit = self.before_begin();
{
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
auto e = deferred_uc::end(L, self);
for (auto it = deferred_uc::begin(L, self); key > 0; ++backit, ++it, --key) {
if (backit == e) {
@ -1026,7 +1025,7 @@ namespace sol {
static detail::error_result erase_integral(std::true_type, lua_State* L, T& self, K& key) {
auto it = deferred_uc::begin(L, self);
key += deferred_uc::index_adjustment(L, self);
key = (static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
std::advance(it, key);
self.erase(it);
@ -1057,7 +1056,7 @@ namespace sol {
static detail::error_result erase_after_has(std::true_type, lua_State* L, T& self, K& key) {
auto backit = self.before_begin();
{
key += deferred_uc::index_adjustment(L, self);
key = static_cast<K>(static_cast<std::ptrdiff_t>(key) + deferred_uc::index_adjustment(L, self));
auto e = deferred_uc::end(L, self);
for (auto it = deferred_uc::begin(L, self); key > 0; ++backit, ++it, --key) {
if (backit == e) {
@ -1135,7 +1134,7 @@ namespace sol {
}
static std::size_t size_start(lua_State* L, T& self) {
return size_has(meta::has_size<T>(), L, self);
return static_cast<std::size_t>(size_has(meta::has_size<T>(), L, self));
}
static void clear_start(lua_State* L, T& self) {
@ -1402,7 +1401,7 @@ namespace sol {
using v_t = std::add_const_t<decltype(self[idx])>;
v_t v = self[idx];
if (v == value) {
idx -= deferred_uc::index_adjustment(L, self);
idx = static_cast<std::size_t>(static_cast<std::ptrdiff_t>(idx) + deferred_uc::index_adjustment(L, self));
return stack::push(L, idx);
}
}
@ -1527,11 +1526,11 @@ namespace sol {
};
template <typename X>
struct usertype_container_default<usertype_container<X>> : usertype_container_default<X> {};
struct usertype_container_default<usertype_container<X>> : usertype_container_default<X> { };
} // namespace container_detail
template <typename T>
struct usertype_container : container_detail::usertype_container_default<T> {};
struct usertype_container : container_detail::usertype_container_default<T> { };
} // namespace sol

View File

@ -36,7 +36,7 @@ namespace sol {
using key_type = detail::proxy_key_t<Key>;
template <typename T, std::size_t... I>
decltype(auto) tuple_get(std::index_sequence<I...>) const & {
decltype(auto) tuple_get(std::index_sequence<I...>) const& {
return tbl.template traverse_get<T>(std::get<I>(key)...);
}
@ -70,8 +70,7 @@ namespace sol {
key_type key;
template <typename T>
usertype_proxy(Table table, T&& k)
: tbl(table), key(std::forward<T>(k)) {
usertype_proxy(Table table, T&& k) : tbl(table), key(std::forward<T>(k)) {
}
template <typename T>

View File

@ -1054,7 +1054,7 @@ namespace sol { namespace u_detail {
auto prop_fx = detail::properties_enrollment_allowed(for_each_backing_metatable_calls, storage.properties, enrollments);
auto insert_fx = [&L, &t, &storage](meta_function mf, lua_CFunction reg) {
stack::set_field<false, true>(L, mf, reg, t.stack_index());
storage.properties[static_cast<int>(mf)] = true;
storage.properties[static_cast<std::size_t>(mf)] = true;
};
detail::insert_default_registrations<T>(insert_fx, prop_fx);

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -49,16 +49,13 @@ namespace sol {
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
variadic_args() = default;
variadic_args(lua_State* luastate, int stackindex = -1)
: L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lua_gettop(luastate)) {
variadic_args(lua_State* luastate, int stackindex = -1) : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lua_gettop(luastate)) {
}
variadic_args(lua_State* luastate, int stackindex, int lastindex)
: L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lastindex) {
variadic_args(lua_State* luastate, int stackindex, int lastindex) : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lastindex) {
}
variadic_args(const variadic_args&) = default;
variadic_args& operator=(const variadic_args&) = default;
variadic_args(variadic_args&& o)
: L(o.L), index(o.index), stacktop(o.stacktop) {
variadic_args(variadic_args&& o) : L(o.L), index(o.index), stacktop(o.stacktop) {
// Must be manual, otherwise destructor will screw us
// return count being 0 is enough to keep things clean
// but will be thorough

View File

@ -647,6 +647,16 @@
#define SOL_GET_FUNCTION_POINTER_UNSAFE_I_ SOL_DEFAULT_OFF
#endif
#if defined(SOL_FUNCTION_CALL_VALUE_SEMANTICS)
#if (SOL_FUNCTION_CALL_VALUE_SEMANTICS != 0)
#define SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_ SOL_ON
#else
#define SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_ SOL_OFF
#endif
#else
#define SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_ SOL_DEFAULT_OFF
#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

View File

@ -178,99 +178,100 @@ namespace sol {
};
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...)> : public member_function_wrapper<R (O::*)(Args...), R, O, Args...> {};
struct wrapper<R (O::*)(Args...)> : public member_function_wrapper<R (O::*)(Args...), R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const> : public member_function_wrapper<R (O::*)(Args...) const, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const> : public member_function_wrapper<R (O::*)(Args...) const, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const volatile> : public member_function_wrapper<R (O::*)(Args...) const volatile, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const volatile> : public member_function_wrapper<R (O::*)(Args...) const volatile, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...)&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> {};
struct wrapper<R (O::*)(Args...)&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const volatile&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const volatile&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...)&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...)&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) const&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const volatile&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) const volatile&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) &&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) &&> : public member_function_wrapper<R (O::*)(Args...)&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const&&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const&&> : public member_function_wrapper<R (O::*)(Args...) const&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const volatile&&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const volatile&&> : public member_function_wrapper<R (O::*)(Args...) const volatile&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) &&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) &&> : public member_function_wrapper<R (O::*)(Args..., ...)&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const&&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) const&&> : public member_function_wrapper<R (O::*)(Args..., ...) const&, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const volatile&&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) const volatile&&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> { };
#if SOL_IS_ON(SOL_USE_NOEXCEPT_FUNCTION_TYPE_I_)
// noexcept has become a part of a function's type
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const noexcept> : public member_function_wrapper<R (O::*)(Args...) const noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const noexcept> : public member_function_wrapper<R (O::*)(Args...) const noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const volatile noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const volatile noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) & noexcept> : public member_function_wrapper<R (O::*)(Args...) & noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...)& noexcept> : public member_function_wrapper<R (O::*)(Args...)& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const volatile& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const volatile& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) & noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) & noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...)& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...)& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) const& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const volatile& noexcept>
: public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> {};
: public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) && noexcept> : public member_function_wrapper<R (O::*)(Args...) & noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...)&& noexcept> : public member_function_wrapper<R (O::*)(Args...)& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) const volatile&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args...) const volatile&& noexcept> : public member_function_wrapper<R (O::*)(Args...) const volatile& noexcept, R, O, Args...> {
};
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) && noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) & noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...)&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...)& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> {};
struct wrapper<R (O::*)(Args..., ...) const&& noexcept> : public member_function_wrapper<R (O::*)(Args..., ...) const& noexcept, R, O, Args...> { };
template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args..., ...) const volatile&& noexcept>
: public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> {};
: public member_function_wrapper<R (O::*)(Args..., ...) const volatile& noexcept, R, O, Args...> { };
#endif // noexcept is part of a function's type

View File

@ -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-11-20 22:05:33.707282 UTC
// This header was generated with sol v3.2.3 (revision d0eba0a7)
// Generated 2020-12-16 20:25:14.474291 UTC
// This header was generated with sol v3.2.3 (revision 5b7cf9ad)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_CONFIG_HPP

View File

@ -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-11-20 22:05:33.695273 UTC
// This header was generated with sol v3.2.3 (revision d0eba0a7)
// Generated 2020-12-16 20:25:14.452290 UTC
// This header was generated with sol v3.2.3 (revision 5b7cf9ad)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
@ -653,6 +653,16 @@
#define SOL_GET_FUNCTION_POINTER_UNSAFE_I_ SOL_DEFAULT_OFF
#endif
#if defined(SOL_FUNCTION_CALL_VALUE_SEMANTICS)
#if (SOL_FUNCTION_CALL_VALUE_SEMANTICS != 0)
#define SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_ SOL_ON
#else
#define SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_ SOL_OFF
#endif
#else
#define SOL_FUNCTION_CALL_VALUE_SEMANTICS_I_ SOL_DEFAULT_OFF
#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

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ function(CREATE_TEST test_target_name test_name target_sol)
PRIVATE -std=c++1z -pthread
-Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Wpedantic -Werror -pedantic -pedantic-errors
-Wno-noexcept-type)
-Wno-noexcept-type -Wshadow -Wconversion)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${test_target_name}

View File

@ -169,8 +169,8 @@ struct order_suit {
std::vector<std::pair<int64_t, int>> objs2;
order_suit(int pairs) {
objs.reserve(pairs);
objs2.reserve(pairs * 2);
objs.reserve(static_cast<std::size_t>(pairs));
objs2.reserve(static_cast<std::size_t>(pairs * 2));
for (int i = 0; i < pairs; ++i) {
objs.push_back({ i, i * 10 });
objs2.push_back({ (i + pairs) * 2, (i * 2) * 50 });

View File

@ -451,8 +451,8 @@ TEST_CASE("functions/unsafe protected_function_result handlers",
present = (bool)opvalue;
REQUIRE_FALSE(present);
sol::error err = result;
#ifdef SOL_LUAJIT
#if !((!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)))
#if SOL_IS_ON(SOL_USE_LUAJIT_I_)
#if SOL_IS_OFF(SOL_PROPAGATE_EXCEPTIONS_I_)
REQUIRE(err.what() == std::string("C++ exception"));
#else
REQUIRE(err.what() == handlederrormessage_s);

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -46,7 +46,7 @@ TEST_CASE("gc/destructors", "test if destructors are fired properly through gc o
{
sol::state lua;
lua["t"] = test{};
lua["t"] = test {};
pt = lua["t"];
}
@ -176,15 +176,15 @@ end
gc_entity e;
target = &e;
{
f(e); // same with std::ref(e)!
f(e); // same with std::ref(e)!
lua.collect_garbage(); // destroys e for some reason
}
{
f(&e); // same with std::ref(e)!
f(&e); // same with std::ref(e)!
lua.collect_garbage(); // destroys e for some reason
}
{
f(std::ref(e)); // same with std::ref(e)!
f(std::ref(e)); // same with std::ref(e)!
lua.collect_garbage(); // destroys e for some reason
}
}
@ -315,8 +315,7 @@ TEST_CASE("gc/same type closures", "make sure destructions are per-object, not p
struct my_closure {
int& n;
my_closure(int& n)
: n(n) {
my_closure(int& n) : n(n) {
}
~my_closure() noexcept(false) {
if (!checking_closures)
@ -431,14 +430,14 @@ TEST_CASE("gc/double-deletion tests", "make sure usertypes are properly destruct
sol::state lua;
SECTION("regular") {
lua.new_usertype<crash_class>("CrashClass",
sol::call_constructor, sol::constructors<sol::types<>>());
lua.new_usertype<crash_class>("CrashClass", sol::call_constructor, sol::constructors<sol::types<>>());
auto result1 = lua.safe_script(R"(
function testCrash()
local x = CrashClass()
end
)", sol::script_pass_on_error);
)",
sol::script_pass_on_error);
REQUIRE(result1.valid());
for (int i = 0; i < 1000; ++i) {
@ -468,11 +467,10 @@ TEST_CASE("gc/shared_ptr regression", "metatables should not screw over unique u
sol::state lua;
lua.open_libraries();
lua.new_usertype<test>("test",
"create", [&]() -> std::shared_ptr<test> {
tests.push_back(std::make_shared<test>());
return tests.back();
});
lua.new_usertype<test>("test", "create", [&]() -> std::shared_ptr<test> {
tests.push_back(std::make_shared<test>());
return tests.back();
});
REQUIRE(created == 0);
REQUIRE(destroyed == 0);
auto result1 = lua.safe_script("x = test.create()", sol::script_pass_on_error);
@ -481,8 +479,8 @@ TEST_CASE("gc/shared_ptr regression", "metatables should not screw over unique u
REQUIRE(destroyed == 0);
REQUIRE_FALSE(tests.empty());
std::shared_ptr<test>& x = lua["x"];
std::size_t xuse = x.use_count();
std::size_t tuse = tests.back().use_count();
std::size_t xuse = static_cast<std::size_t>(x.use_count());
std::size_t tuse = static_cast<std::size_t>(tests.back().use_count());
REQUIRE(xuse == tuse);
}
REQUIRE(created == 1);
@ -523,10 +521,9 @@ TEST_CASE("gc/alignment", "test that allocation is always on aligned boundaries,
};
sol::state lua;
lua.new_usertype<test>("test",
"callback", &test::callback);
lua.new_usertype<test>("test", "callback", &test::callback);
test obj{};
test obj {};
lua["obj"] = &obj;
INFO("obj");
{
@ -535,10 +532,10 @@ TEST_CASE("gc/alignment", "test that allocation is always on aligned boundaries,
}
{
// Do not check for stack-created object
//test& lobj = lua["obj"];
//lobj.check_alignment();
// test& lobj = lua["obj"];
// lobj.check_alignment();
}
lua["obj0"] = std::ref(obj);
INFO("obj0");
{
@ -547,8 +544,8 @@ TEST_CASE("gc/alignment", "test that allocation is always on aligned boundaries,
}
{
// Do not check for stack-created object
//test& lobj = lua["obj0"];
//lobj.check_alignment();
// test& lobj = lua["obj0"];
// lobj.check_alignment();
}
lua["obj1"] = obj;
@ -562,7 +559,7 @@ TEST_CASE("gc/alignment", "test that allocation is always on aligned boundaries,
lobj.check_alignment();
}
lua["obj2"] = test{};
lua["obj2"] = test {};
INFO("obj2");
{
auto r = lua.safe_script("obj2.callback()", sol::script_pass_on_error);

View File

@ -34,7 +34,7 @@ struct test_stack_guard {
lua_State* L;
int& begintop;
int& endtop;
test_stack_guard(lua_State* L, int& begintop, int& endtop) : L(L), begintop(begintop), endtop(endtop) {
test_stack_guard(lua_State* L, int& begintop_, int& endtop_) : L(L), begintop(begintop_), endtop(endtop_) {
begintop = lua_gettop(L);
}

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -27,15 +27,15 @@
#include <iostream>
struct test {};
struct test { };
template <typename T>
struct test_t {};
struct test_t { };
namespace muh_namespace {
struct ns_test {};
struct ns_test { };
namespace {
struct ns_anon_test {};
struct ns_anon_test { };
} // namespace
} // namespace muh_namespace
@ -43,15 +43,120 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") {
sol::state lua;
sol::stack_guard luasg(lua);
static const char utf8str[] = "\xF0\x9F\x8D\x8C\x20\xE6\x99\xA5\x20\x46\x6F\x6F\x20\xC2\xA9\x20\x62\x61\x72\x20\xF0\x9D\x8C\x86\x20\x62\x61\x7A\x20\xE2\x98\x83\x20\x71\x75\x78";
static const char16_t utf16str[] = { 0xD83C, 0xDF4C, 0x20, 0x6665, 0x20, 0x46, 0x6F, 0x6F, 0x20, 0xA9, 0x20, 0x62, 0x61, 0x72, 0x20, 0xD834, 0xDF06, 0x20, 0x62, 0x61, 0x7A, 0x20, 0x2603, 0x20, 0x71, 0x75, 0x78, 0x00 };
static const char32_t utf32str[] = { 0x1F34C, 0x0020, 0x6665, 0x0020, 0x0046, 0x006F, 0x006F, 0x0020, 0x00A9, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x1D306, 0x0020, 0x0062, 0x0061, 0x007A, 0x0020, 0x2603, 0x0020, 0x0071, 0x0075, 0x0078, 0x00 };
static const char utf8str[]
= "\xF0\x9F\x8D\x8C\x20\xE6\x99\xA5\x20\x46\x6F\x6F\x20\xC2\xA9\x20\x62\x61\x72\x20\xF0\x9D\x8C\x86\x20\x62\x61\x7A\x20\xE2\x98\x83\x20\x71\x75\x78";
static const char16_t utf16str[] = { 0xD83C,
0xDF4C,
0x20,
0x6665,
0x20,
0x46,
0x6F,
0x6F,
0x20,
0xA9,
0x20,
0x62,
0x61,
0x72,
0x20,
0xD834,
0xDF06,
0x20,
0x62,
0x61,
0x7A,
0x20,
0x2603,
0x20,
0x71,
0x75,
0x78,
0x00 };
static const char32_t utf32str[] = { 0x1F34C,
0x0020,
0x6665,
0x0020,
0x0046,
0x006F,
0x006F,
0x0020,
0x00A9,
0x0020,
0x0062,
0x0061,
0x0072,
0x0020,
0x1D306,
0x0020,
0x0062,
0x0061,
0x007A,
0x0020,
0x2603,
0x0020,
0x0071,
0x0075,
0x0078,
0x00 };
#ifdef _WIN32
INFO("win32 widestr");
static const wchar_t widestr[] = { 0xD83C, 0xDF4C, 0x20, 0x6665, 0x20, 0x46, 0x6F, 0x6F, 0x20, 0xA9, 0x20, 0x62, 0x61, 0x72, 0x20, 0xD834, 0xDF06, 0x20, 0x62, 0x61, 0x7A, 0x20, 0x2603, 0x20, 0x71, 0x75, 0x78, 0x00 };
static const wchar_t widestr[] = { 0xD83C,
0xDF4C,
0x20,
0x6665,
0x20,
0x46,
0x6F,
0x6F,
0x20,
0xA9,
0x20,
0x62,
0x61,
0x72,
0x20,
0xD834,
0xDF06,
0x20,
0x62,
0x61,
0x7A,
0x20,
0x2603,
0x20,
0x71,
0x75,
0x78,
0x00 };
#else
INFO("non-windows widestr");
static const wchar_t widestr[] = { 0x1F34C, 0x0020, 0x6665, 0x0020, 0x0046, 0x006F, 0x006F, 0x0020, 0x00A9, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x1D306, 0x0020, 0x0062, 0x0061, 0x007A, 0x0020, 0x2603, 0x0020, 0x0071, 0x0075, 0x0078, 0x00 };
static const wchar_t widestr[] = { 0x1F34C,
0x0020,
0x6665,
0x0020,
0x0046,
0x006F,
0x006F,
0x0020,
0x00A9,
0x0020,
0x0062,
0x0061,
0x0072,
0x0020,
0x1D306,
0x0020,
0x0062,
0x0061,
0x007A,
0x0020,
0x2603,
0x0020,
0x0071,
0x0075,
0x0078,
0x00 };
#endif
static const std::string utf8str_s = utf8str;
static const std::u16string utf16str_s = utf16str;
@ -161,9 +266,9 @@ TEST_CASE("detail/demangling", "test some basic demangling cases") {
TEST_CASE("object/string-pushers", "test some basic string pushers with in_place constructor") {
sol::state lua;
sol::object ocs(lua, sol::in_place, "bark\0bark", 9);
sol::object os(lua, sol::in_place_type<std::string>, std::string("bark\0bark", 9), 8);
sol::object osv(lua, sol::in_place_type<sol::string_view>, sol::string_view("woofwoof", 8), 8);
sol::object ocs(lua, sol::in_place, "bark\0bark", 9u);
sol::object os(lua, sol::in_place_type<std::string>, std::string("bark\0bark", 9), 8u);
sol::object osv(lua, sol::in_place_type<sol::string_view>, sol::string_view("woofwoof", 8), 8u);
bool test1 = ocs.as<std::string>() == std::string("bark\0bark", 9);
bool test2 = os.as<std::string>() == std::string("bark\0bar", 8);
bool test3 = osv.as<std::string>() == std::string("woofwoof", 8);

View File

@ -245,7 +245,7 @@ TEST_CASE("usertype/static-properties", "allow for static functions to get and s
}
TEST_CASE("usertype/var with string literals", "String literals are the bane of my existence and one day C++ will make them not be fucking arrays") {
struct blah {};
struct blah { };
sol::state lua;
sol::usertype<blah> x = lua.new_usertype<blah>("blah");
@ -303,7 +303,7 @@ TEST_CASE("usertype/coverage", "try all the things") {
sol::meta_function::garbage_collect,
sol::destructor(des<ext_getset>),
"x",
sol::overload(&ext_getset::x, &ext_getset::x2, [](ext_getset& m, std::string x, int y) { return m.meow + 50 + y + x.length(); }),
sol::overload(&ext_getset::x, &ext_getset::x2, [](ext_getset& m, std::string x, int y) { return m.meow + 50 + y + static_cast<int>(x.length()); }),
"bark",
&ext_getset::bark,
"meow",
@ -416,8 +416,8 @@ print(e.bark)
}
TEST_CASE("usertype/alignment", "ensure that alignment does not trigger weird aliasing issues") {
struct aligned_base {};
struct aligned_derived : aligned_base {};
struct aligned_base { };
struct aligned_derived : aligned_base { };
sol::state lua;
sol::stack_guard luasg(lua);
@ -454,7 +454,8 @@ TEST_CASE("usertype/readonly-and-static-functions", "Check if static functions c
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<bark>("bark",
lua.new_usertype<bark>(
"bark",
"var",
&bark::var,
"var2",
@ -537,7 +538,7 @@ TEST_CASE("usertype/vars", "usertype vars can bind various class items") {
sol::state lua;
lua.open_libraries();
struct test {};
struct test { };
lua.new_usertype<test>("test",
"straight",
sol::var(2),

View File

@ -52,7 +52,7 @@ struct self_cons_2 {
static void init_self_cons_2(self_cons_2& mem, sol::variadic_args args, sol::this_state thisL) {
lua_State* L = thisL;
self_cons_2* pself = sol::stack::get<self_cons_2*>(L, 1);
std::allocator<self_cons_2> alloc{};
std::allocator<self_cons_2> alloc {};
std::allocator_traits<std::allocator<self_cons_2>>::construct(alloc, &mem);
REQUIRE(pself == &mem);
REQUIRE(args.size() == 2);
@ -63,7 +63,7 @@ struct self_cons_3 {
static void init_self_cons_3(self_cons_3* mem, sol::variadic_args args, sol::this_state thisL) {
lua_State* L = thisL;
self_cons_3* pself = sol::stack::get<self_cons_3*>(L, 1);
std::allocator<self_cons_3> alloc{};
std::allocator<self_cons_3> alloc {};
std::allocator_traits<std::allocator<self_cons_3>>::construct(alloc, mem);
REQUIRE(pself == mem);
REQUIRE(args.size() == 3);
@ -130,7 +130,7 @@ TEST_CASE("variadics/variadic_args get type", "Make sure we can inspect types pr
bool working = true;
auto b = va.begin();
for (std::size_t i = 0; i < va.size(); ++i, ++b) {
sol::type t1 = va.get_type(i);
sol::type t1 = va.get_type(static_cast<std::ptrdiff_t>(i));
sol::type t2 = b->get_type();
working &= types[i] == t1;
working &= types[i] == t2;
@ -148,11 +148,11 @@ TEST_CASE("variadics/variadic_results", "returning a variable amount of argument
sol::stack_guard luasg(lua);
lua.set_function("f", []() {
std::set<std::string> results{ "arf", "bark", "woof" };
std::set<std::string> results { "arf", "bark", "woof" };
return sol::as_returns(std::move(results));
});
lua.set_function("g", []() {
static const std::deque<int> results{ 25, 82 };
static const std::deque<int> results { 25, 82 };
return sol::as_returns(std::ref(results));
});
@ -256,10 +256,10 @@ TEST_CASE("variadics/fallback_constructor", "ensure constructor matching behaves
lua.new_usertype<vec2x>("vec2x",
sol::call_constructor,
sol::factories([]() { return vec2x{}; },
sol::factories([]() { return vec2x {}; },
[](vec2x const& v) -> vec2x { return v; },
[](sol::variadic_args va) {
vec2x res{};
vec2x res {};
if (va.size() == 1) {
res.x = va[0].get<float>();
res.y = va[0].get<float>();