mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
update customization points and track un-specialized structs to trigger some safe-guards as a back-compatible safety net
This commit is contained in:
parent
889a45d0b3
commit
ab9126d892
|
@ -24,6 +24,11 @@ These are template class/structs, so you'll override them using a technique C++
|
||||||
template <>
|
template <>
|
||||||
struct lua_size<two_things> : std::integral_constant<int, 2> {};
|
struct lua_size<two_things> : std::integral_constant<int, 2> {};
|
||||||
|
|
||||||
|
// Then, specialize the type to match:
|
||||||
|
// this has multiple types, so we consider it a "poly" type.
|
||||||
|
template <>
|
||||||
|
struct lua_type_of<two_things> : std::integral_constant<sol::type, sol::type::poly> {};
|
||||||
|
|
||||||
// Now, specialize various stack structures
|
// Now, specialize various stack structures
|
||||||
namespace stack {
|
namespace stack {
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,11 @@ namespace sol {
|
||||||
template <>
|
template <>
|
||||||
struct lua_size<two_things> : std::integral_constant<int, 2> {};
|
struct lua_size<two_things> : std::integral_constant<int, 2> {};
|
||||||
|
|
||||||
|
// Then, specialize the type
|
||||||
|
// this makes sure Sol can return it properly
|
||||||
|
template <>
|
||||||
|
struct lua_type_of<two_things> : std::integral_constant<sol::type, sol::type::poly> {};
|
||||||
|
|
||||||
// Now, specialize various stack structures
|
// Now, specialize various stack structures
|
||||||
namespace stack {
|
namespace stack {
|
||||||
|
|
||||||
|
@ -67,22 +72,24 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
std::cout << "=== customization example ===" << std::endl;
|
||||||
|
std::cout << std::boolalpha;
|
||||||
|
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
// Create a pass-through style of function
|
// Create a pass-through style of function
|
||||||
lua.script("function f ( a, b ) return a, b end");
|
lua.script("function f ( a, b ) print(a, b) return a, b end");
|
||||||
|
|
||||||
// get the function out of Lua
|
// get the function out of Lua
|
||||||
sol::function f = lua["f"];
|
sol::function f = lua["f"];
|
||||||
|
|
||||||
two_things things = f(two_things{ 24, true });
|
two_things things = f(two_things{ 24, false });
|
||||||
assert(things.a == 24);
|
assert(things.a == 24);
|
||||||
assert(things.b == true);
|
assert(things.b == false);
|
||||||
// things.a == 24
|
// things.a == 24
|
||||||
// things.b == true
|
// things.b == true
|
||||||
|
|
||||||
std::cout << "=== customization example ===" << std::endl;
|
|
||||||
std::cout << std::boolalpha;
|
|
||||||
std::cout << "things.a: " << things.a << std::endl;
|
std::cout << "things.a: " << things.a << std::endl;
|
||||||
std::cout << "things.b: " << things.b << std::endl;
|
std::cout << "things.b: " << things.b << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2017-02-20 08:45:30.715552 UTC
|
// Generated 2017-02-20 23:06:29.737387 UTC
|
||||||
// This header was generated with sol v2.15.9 (revision b7b6366)
|
// This header was generated with sol v2.15.9 (revision 889a45d)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -3686,10 +3686,14 @@ namespace sol {
|
||||||
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>
|
template <typename T>
|
||||||
struct lua_type_of : detail::lua_type_of<T> {};
|
struct lua_type_of : detail::lua_type_of<T> {
|
||||||
|
typedef int SOL_INTERNAL_UNSPECIALIZED_MARKER_;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct lua_size : std::integral_constant<int, 1> { };
|
struct lua_size : std::integral_constant<int, 1> {
|
||||||
|
typedef int SOL_INTERNAL_UNSPECIALIZED_MARKER_;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename A, typename B>
|
template <typename A, typename B>
|
||||||
struct lua_size<std::pair<A, B>> : std::integral_constant<int, lua_size<A>::value + lua_size<B>::value> { };
|
struct lua_size<std::pair<A, B>> : std::integral_constant<int, lua_size<A>::value + lua_size<B>::value> { };
|
||||||
|
@ -3697,10 +3701,24 @@ namespace sol {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
struct lua_size<std::tuple<Args...>> : std::integral_constant<int, detail::accumulate<int, 0, lua_size, Args...>::value> { };
|
struct lua_size<std::tuple<Args...>> : std::integral_constant<int, detail::accumulate<int, 0, lua_size, Args...>::value> { };
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
template <typename...>
|
||||||
|
struct void_ { typedef void type; };
|
||||||
|
template <typename T, typename = void>
|
||||||
|
struct has_internal_marker_impl : std::false_type {};
|
||||||
|
template <typename T>
|
||||||
|
struct has_internal_marker_impl<T, typename void_<typename T::SOL_INTERNAL_UNSPECIALIZED_MARKER_>::type> : std::true_type {};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct has_internal_marker : has_internal_marker_impl<T> {};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_lua_primitive : std::integral_constant<bool,
|
struct is_lua_primitive : std::integral_constant<bool,
|
||||||
type::userdata != lua_type_of<meta::unqualified_t<T>>::value
|
type::userdata != lua_type_of<meta::unqualified_t<T>>::value
|
||||||
|| (lua_size<T>::value > 1)
|
|| ((type::userdata == lua_type_of<meta::unqualified_t<T>>::value)
|
||||||
|
&& detail::has_internal_marker<lua_type_of<meta::unqualified_t<T>>>::value
|
||||||
|
&& !detail::has_internal_marker<lua_size<meta::unqualified_t<T>>>::value)
|
||||||
|| std::is_base_of<reference, meta::unqualified_t<T>>::value
|
|| std::is_base_of<reference, meta::unqualified_t<T>>::value
|
||||||
|| std::is_base_of<stack_reference, meta::unqualified_t<T>>::value
|
|| std::is_base_of<stack_reference, meta::unqualified_t<T>>::value
|
||||||
|| meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>::value
|
|| meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>::value
|
||||||
|
|
|
@ -704,10 +704,14 @@ namespace sol {
|
||||||
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>
|
template <typename T>
|
||||||
struct lua_type_of : detail::lua_type_of<T> {};
|
struct lua_type_of : detail::lua_type_of<T> {
|
||||||
|
typedef int SOL_INTERNAL_UNSPECIALIZED_MARKER_;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct lua_size : std::integral_constant<int, 1> { };
|
struct lua_size : std::integral_constant<int, 1> {
|
||||||
|
typedef int SOL_INTERNAL_UNSPECIALIZED_MARKER_;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename A, typename B>
|
template <typename A, typename B>
|
||||||
struct lua_size<std::pair<A, B>> : std::integral_constant<int, lua_size<A>::value + lua_size<B>::value> { };
|
struct lua_size<std::pair<A, B>> : std::integral_constant<int, lua_size<A>::value + lua_size<B>::value> { };
|
||||||
|
@ -715,10 +719,24 @@ namespace sol {
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
struct lua_size<std::tuple<Args...>> : std::integral_constant<int, detail::accumulate<int, 0, lua_size, Args...>::value> { };
|
struct lua_size<std::tuple<Args...>> : std::integral_constant<int, detail::accumulate<int, 0, lua_size, Args...>::value> { };
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
template <typename...>
|
||||||
|
struct void_ { typedef void type; };
|
||||||
|
template <typename T, typename = void>
|
||||||
|
struct has_internal_marker_impl : std::false_type {};
|
||||||
|
template <typename T>
|
||||||
|
struct has_internal_marker_impl<T, typename void_<typename T::SOL_INTERNAL_UNSPECIALIZED_MARKER_>::type> : std::true_type {};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct has_internal_marker : has_internal_marker_impl<T> {};
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_lua_primitive : std::integral_constant<bool,
|
struct is_lua_primitive : std::integral_constant<bool,
|
||||||
type::userdata != lua_type_of<meta::unqualified_t<T>>::value
|
type::userdata != lua_type_of<meta::unqualified_t<T>>::value
|
||||||
|| (lua_size<T>::value > 1)
|
|| ((type::userdata == lua_type_of<meta::unqualified_t<T>>::value)
|
||||||
|
&& detail::has_internal_marker<lua_type_of<meta::unqualified_t<T>>>::value
|
||||||
|
&& !detail::has_internal_marker<lua_size<meta::unqualified_t<T>>>::value)
|
||||||
|| std::is_base_of<reference, meta::unqualified_t<T>>::value
|
|| std::is_base_of<reference, meta::unqualified_t<T>>::value
|
||||||
|| std::is_base_of<stack_reference, meta::unqualified_t<T>>::value
|
|| std::is_base_of<stack_reference, meta::unqualified_t<T>>::value
|
||||||
|| meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>::value
|
|| meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>::value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user