minor fixes

This commit is contained in:
ThePhD 2018-09-28 00:55:47 -07:00
parent e56cbc1dc5
commit f42a678d20
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
6 changed files with 40 additions and 28 deletions

View File

@ -31,7 +31,7 @@ include(GNUInstallDirs)
# # # General Project Requirements
# Set general standard requirements here
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Features a C++ compiler must have to be used to compile sol2
# This list is not *complete* as CMake does not support features for
@ -74,6 +74,13 @@ if (MSVC)
add_definitions(/DUNICODE /D_UNICODE /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
# Warning level, exceptions
add_compile_options(/W4 /EHsc)
if (MSVC_VERSION GREATER_EQUAL "1900")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported)
if (_cpp_latest_flag_supported)
add_compile_options("/std:c++latest")
endif()
endif()
add_compile_options("$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"

View File

@ -139,9 +139,9 @@ namespace sol {
#define SOL_BASE_CLASSES(T, ...) \
template <> \
struct ::sol::base<T> : ::std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
struct ::sol::base<T> : std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
#define SOL_DERIVED_CLASSES(T, ...) \
template <> \
struct ::sol::derive<T> : ::std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
struct ::sol::derive<T> : std::true_type { typedef ::sol::types<__VA_ARGS__> type; };
#endif // SOL_INHERITANCE_HPP

View File

@ -72,14 +72,14 @@ namespace sol {
: base_t(L, std::forward<T>(r)) {
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
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 defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler {};
constructor_handler handler{};
stack::check<basic_metatable>(L, index, handler);
#endif // Safety
}
@ -87,7 +87,7 @@ namespace sol {
: basic_metatable(detail::no_safety, L, index) {
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this);
constructor_handler handler {};
constructor_handler handler{};
stack::check<basic_metatable>(lua_state(), -1, handler);
#endif // Safety
}
@ -97,7 +97,7 @@ namespace sol {
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
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
@ -107,18 +107,12 @@ namespace sol {
}
template <typename Key, typename Value>
void set(Key&& key, Value&& value) {
optional<usertype_storage_base&> maybe_uts = u_detail::maybe_get_usertype_storage_base(this->lua_state());
if (maybe_uts) {
usertype_storage<T>& uts = *maybe_uts;
uts.set(std::forward<Key>(key), std::forward<Value>(value));
}
}
void set(Key&& key, Value&& value);
void unregister() {
lua_State* L = this->lua_state();
int x = lua_gettop(L);
lua_State* L = this->lua_state();
auto pp = stack::push_pop(*this);
stack_reference mt(L, -1);
stack::get_field(L, meta_function::gc_names, mt.stack_index());

View File

@ -39,6 +39,16 @@ namespace sol {
return mt;
}
template <typename base_type>
template <typename Key, typename Value>
void basic_metatable<base_type>::set(Key&& key, Value&& value) {
optional<u_detail::usertype_storage_base&> maybe_uts = u_detail::maybe_get_usertype_storage_base(this->lua_state());
if (maybe_uts) {
u_detail::usertype_storage_base& uts = *maybe_uts;
uts.set(std::forward<Key>(key), std::forward<Value>(value));
}
}
namespace stack {
template <>
struct getter<metatable_t> {

View File

@ -45,8 +45,8 @@ namespace sol {
}
static int real_index_call(lua_State* L) {
typedef u_detail::map_t<std::string, lua_CFunction> call_map;
static const call_map calls {
typedef detail::map_t<std::string, lua_CFunction> call_map;
static const call_map calls{
{ "at", &at_call },
{ "get", &real_get_call },
{ "set", &real_set_call },
@ -338,7 +338,7 @@ namespace sol {
{ "add", &meta_cumt::add_call },
{ "find", &meta_cumt::find_call },
{ "erase", &meta_cumt::erase_call },
std::is_pointer<T>::value ? luaL_Reg { nullptr, nullptr } : luaL_Reg { "__gc", &detail::usertype_alloc_destruct<T> },
std::is_pointer<T>::value ? luaL_Reg{ nullptr, nullptr } : luaL_Reg{ "__gc", &detail::usertype_alloc_destruct<T> },
{ nullptr, nullptr } } };
if (luaL_newmetatable(L, metakey) == 1) {
@ -355,17 +355,17 @@ namespace sol {
static int push_lvalue(std::true_type, lua_State* L, const C& cont) {
stack_detail::metatable_setup<C*, true> fx(L);
return pusher<detail::as_pointer_tag<const C>> {}.push_fx(L, fx, detail::ptr(cont));
return pusher<detail::as_pointer_tag<const C>>{}.push_fx(L, fx, detail::ptr(cont));
}
static int push_lvalue(std::false_type, lua_State* L, const C& cont) {
stack_detail::metatable_setup<C, true> fx(L);
return pusher<detail::as_value_tag<C>> {}.push_fx(L, fx, cont);
return pusher<detail::as_value_tag<C>>{}.push_fx(L, fx, cont);
}
static int push_rvalue(std::true_type, lua_State* L, C&& cont) {
stack_detail::metatable_setup<C, true> fx(L);
return pusher<detail::as_value_tag<C>> {}.push_fx(L, fx, std::move(cont));
return pusher<detail::as_value_tag<C>>{}.push_fx(L, fx, std::move(cont));
}
static int push_rvalue(std::false_type, lua_State* L, const C& cont) {
@ -387,7 +387,7 @@ namespace sol {
static int push(lua_State* L, T* cont) {
stack_detail::metatable_setup<C> fx(L);
return pusher<detail::as_pointer_tag<T>> {}.push_fx(L, fx, cont);
return pusher<detail::as_pointer_tag<T>>{}.push_fx(L, fx, cont);
}
};
@ -397,12 +397,12 @@ namespace sol {
static int push(lua_State* L, const T& cont) {
stack_detail::metatable_setup<C> fx(L);
return pusher<detail::as_value_tag<T>> {}.push_fx(L, fx, cont);
return pusher<detail::as_value_tag<T>>{}.push_fx(L, fx, cont);
}
static int push(lua_State* L, T&& cont) {
stack_detail::metatable_setup<C> fx(L);
return pusher<detail::as_value_tag<T>> {}.push_fx(L, fx, std::move(cont));
return pusher<detail::as_value_tag<T>>{}.push_fx(L, fx, std::move(cont));
}
};
@ -412,7 +412,7 @@ namespace sol {
static int push(lua_State* L, T* cont) {
stack_detail::metatable_setup<C> fx(L);
return pusher<detail::as_pointer_tag<T>> {}.push_fx(L, fx, cont);
return pusher<detail::as_pointer_tag<T>>{}.push_fx(L, fx, cont);
}
};

View File

@ -36,6 +36,7 @@
#include "usertype_container.hpp"
#include <sstream>
#include <type_traits>
namespace sol {
namespace u_detail {
@ -273,15 +274,15 @@ namespace sol {
void operator()() const {
if (luaL_newmetatable(L, key) == 1) {
luaL_Reg l[64] {};
luaL_Reg l[64]{};
int index = 0;
auto prop_fx = [](meta_function) { return true; };
auto insert_fx = [&l, &index](meta_function mf, lua_CFunction f) {
l[index] = luaL_Reg { to_string(mf).c_str(), f };
l[index] = luaL_Reg{ to_string(mf).c_str(), f };
++index;
};
u_detail::insert_default_registrations<P>(insert_fx, prop_fx);
l[index] = luaL_Reg { to_string(meta_function::garbage_collect).c_str(), u_detail::make_destructor<P>() };
l[index] = luaL_Reg{ to_string(meta_function::garbage_collect).c_str(), u_detail::make_destructor<P>() };
luaL_setfuncs(L, l, 0);
// __type table