mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
minor fixes
This commit is contained in:
parent
e56cbc1dc5
commit
f42a678d20
|
@ -31,7 +31,7 @@ include(GNUInstallDirs)
|
||||||
|
|
||||||
# # # General Project Requirements
|
# # # General Project Requirements
|
||||||
# Set general standard requirements here
|
# Set general standard requirements here
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
# Features a C++ compiler must have to be used to compile sol2
|
# Features a C++ compiler must have to be used to compile sol2
|
||||||
# This list is not *complete* as CMake does not support features for
|
# 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)
|
add_definitions(/DUNICODE /D_UNICODE /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
|
||||||
# Warning level, exceptions
|
# Warning level, exceptions
|
||||||
add_compile_options(/W4 /EHsc)
|
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>"
|
add_compile_options("$<$<CONFIG:Debug>:/MDd>"
|
||||||
"$<$<CONFIG:Release>:/MD>"
|
"$<$<CONFIG:Release>:/MD>"
|
||||||
"$<$<CONFIG:RelWithDebInfo>:/MD>"
|
"$<$<CONFIG:RelWithDebInfo>:/MD>"
|
||||||
|
|
|
@ -139,9 +139,9 @@ namespace sol {
|
||||||
|
|
||||||
#define SOL_BASE_CLASSES(T, ...) \
|
#define SOL_BASE_CLASSES(T, ...) \
|
||||||
template <> \
|
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, ...) \
|
#define SOL_DERIVED_CLASSES(T, ...) \
|
||||||
template <> \
|
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
|
#endif // SOL_INHERITANCE_HPP
|
||||||
|
|
|
@ -72,14 +72,14 @@ namespace sol {
|
||||||
: base_t(L, std::forward<T>(r)) {
|
: base_t(L, std::forward<T>(r)) {
|
||||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||||
auto pp = stack::push_pop(*this);
|
auto pp = stack::push_pop(*this);
|
||||||
constructor_handler handler {};
|
constructor_handler handler{};
|
||||||
stack::check<basic_metatable>(lua_state(), -1, handler);
|
stack::check<basic_metatable>(lua_state(), -1, handler);
|
||||||
#endif // Safety
|
#endif // Safety
|
||||||
}
|
}
|
||||||
basic_metatable(lua_State* L, int index = -1)
|
basic_metatable(lua_State* L, int index = -1)
|
||||||
: basic_metatable(detail::no_safety, L, index) {
|
: basic_metatable(detail::no_safety, L, index) {
|
||||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||||
constructor_handler handler {};
|
constructor_handler handler{};
|
||||||
stack::check<basic_metatable>(L, index, handler);
|
stack::check<basic_metatable>(L, index, handler);
|
||||||
#endif // Safety
|
#endif // Safety
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace sol {
|
||||||
: basic_metatable(detail::no_safety, L, index) {
|
: basic_metatable(detail::no_safety, L, index) {
|
||||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||||
auto pp = stack::push_pop(*this);
|
auto pp = stack::push_pop(*this);
|
||||||
constructor_handler handler {};
|
constructor_handler handler{};
|
||||||
stack::check<basic_metatable>(lua_state(), -1, handler);
|
stack::check<basic_metatable>(lua_state(), -1, handler);
|
||||||
#endif // Safety
|
#endif // Safety
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ namespace sol {
|
||||||
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
|
||||||
if (!is_table<meta::unqualified_t<T>>::value) {
|
if (!is_table<meta::unqualified_t<T>>::value) {
|
||||||
auto pp = stack::push_pop(*this);
|
auto pp = stack::push_pop(*this);
|
||||||
constructor_handler handler {};
|
constructor_handler handler{};
|
||||||
stack::check<basic_metatable>(base_t::lua_state(), -1, handler);
|
stack::check<basic_metatable>(base_t::lua_state(), -1, handler);
|
||||||
}
|
}
|
||||||
#endif // Safety
|
#endif // Safety
|
||||||
|
@ -107,18 +107,12 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
void set(Key&& key, Value&& 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 unregister() {
|
void unregister() {
|
||||||
|
lua_State* L = this->lua_state();
|
||||||
int x = lua_gettop(L);
|
int x = lua_gettop(L);
|
||||||
|
|
||||||
lua_State* L = this->lua_state();
|
|
||||||
auto pp = stack::push_pop(*this);
|
auto pp = stack::push_pop(*this);
|
||||||
stack_reference mt(L, -1);
|
stack_reference mt(L, -1);
|
||||||
stack::get_field(L, meta_function::gc_names, mt.stack_index());
|
stack::get_field(L, meta_function::gc_names, mt.stack_index());
|
||||||
|
|
|
@ -39,6 +39,16 @@ namespace sol {
|
||||||
return mt;
|
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 {
|
namespace stack {
|
||||||
template <>
|
template <>
|
||||||
struct getter<metatable_t> {
|
struct getter<metatable_t> {
|
||||||
|
|
|
@ -45,8 +45,8 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int real_index_call(lua_State* L) {
|
static int real_index_call(lua_State* L) {
|
||||||
typedef u_detail::map_t<std::string, lua_CFunction> call_map;
|
typedef detail::map_t<std::string, lua_CFunction> call_map;
|
||||||
static const call_map calls {
|
static const call_map calls{
|
||||||
{ "at", &at_call },
|
{ "at", &at_call },
|
||||||
{ "get", &real_get_call },
|
{ "get", &real_get_call },
|
||||||
{ "set", &real_set_call },
|
{ "set", &real_set_call },
|
||||||
|
@ -338,7 +338,7 @@ namespace sol {
|
||||||
{ "add", &meta_cumt::add_call },
|
{ "add", &meta_cumt::add_call },
|
||||||
{ "find", &meta_cumt::find_call },
|
{ "find", &meta_cumt::find_call },
|
||||||
{ "erase", &meta_cumt::erase_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 } } };
|
{ nullptr, nullptr } } };
|
||||||
|
|
||||||
if (luaL_newmetatable(L, metakey) == 1) {
|
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) {
|
static int push_lvalue(std::true_type, lua_State* L, const C& cont) {
|
||||||
stack_detail::metatable_setup<C*, true> fx(L);
|
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) {
|
static int push_lvalue(std::false_type, lua_State* L, const C& cont) {
|
||||||
stack_detail::metatable_setup<C, true> fx(L);
|
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) {
|
static int push_rvalue(std::true_type, lua_State* L, C&& cont) {
|
||||||
stack_detail::metatable_setup<C, true> fx(L);
|
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) {
|
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) {
|
static int push(lua_State* L, T* cont) {
|
||||||
stack_detail::metatable_setup<C> fx(L);
|
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) {
|
static int push(lua_State* L, const T& cont) {
|
||||||
stack_detail::metatable_setup<C> fx(L);
|
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) {
|
static int push(lua_State* L, T&& cont) {
|
||||||
stack_detail::metatable_setup<C> fx(L);
|
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) {
|
static int push(lua_State* L, T* cont) {
|
||||||
stack_detail::metatable_setup<C> fx(L);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "usertype_container.hpp"
|
#include "usertype_container.hpp"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace u_detail {
|
namespace u_detail {
|
||||||
|
@ -273,15 +274,15 @@ namespace sol {
|
||||||
|
|
||||||
void operator()() const {
|
void operator()() const {
|
||||||
if (luaL_newmetatable(L, key) == 1) {
|
if (luaL_newmetatable(L, key) == 1) {
|
||||||
luaL_Reg l[64] {};
|
luaL_Reg l[64]{};
|
||||||
int index = 0;
|
int index = 0;
|
||||||
auto prop_fx = [](meta_function) { return true; };
|
auto prop_fx = [](meta_function) { return true; };
|
||||||
auto insert_fx = [&l, &index](meta_function mf, lua_CFunction f) {
|
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;
|
++index;
|
||||||
};
|
};
|
||||||
u_detail::insert_default_registrations<P>(insert_fx, prop_fx);
|
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);
|
luaL_setfuncs(L, l, 0);
|
||||||
|
|
||||||
// __type table
|
// __type table
|
||||||
|
|
Loading…
Reference in New Issue
Block a user