mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
update everything
This commit is contained in:
parent
88cafb281f
commit
a6abc0a0d9
|
@ -230,11 +230,11 @@ file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_EXE}" LUA_JIT_SOURC
|
|||
file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_DLL}" LUA_JIT_SOURCE_LUA_DLL)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_EXP}" LUA_JIT_SOURCE_LUA_LIB_EXP)
|
||||
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_LIB_FILE}" LUA_JIT_DESTINATION_LUA_LIB)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_IMP_LIB_FILE}" LUA_JIT_DESTINATION_LUA_IMP_LIB)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_EXE_FILE}" LUA_JIT_DESTINATION_LUA_INTERPRETER)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_DLL_FILE}" LUA_JIT_DESTINATION_LUA_DLL)
|
||||
file(TO_CMAKE_PATH "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${LUA_JIT_LIB_EXP_FILENAME}" LUA_JIT_DESTINATION_LUA_LIB_EXP)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_IMP_LIB_FILE}" LUA_JIT_DESTINATION_LUA_IMP_LIB)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_LIB_FILE}" LUA_JIT_DESTINATION_LUA_LIB)
|
||||
file(TO_CMAKE_PATH "${LUA_JIT_EXE_FILE}" LUA_JIT_DESTINATION_LUA_INTERPRETER)
|
||||
|
||||
if (WIN32 AND NOT MSVC)
|
||||
string(COMPARE EQUAL ${LUA_JIT_VERSION} ${LUA_JIT_2.0_LATEST_VERSION} lua_jit_same_version_20)
|
||||
|
@ -247,21 +247,14 @@ elseif(LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "latest")
|
|||
set(LUA_JIT_PULL_LATEST TRUE)
|
||||
endif()
|
||||
|
||||
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_SOURCE_LUA_LIB}"
|
||||
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_SOURCE_LUA_LIB_EXP}"
|
||||
"${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_SOURCE_LUA_INTERPRETER}")
|
||||
|
||||
set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB}"
|
||||
set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}"
|
||||
"${LUA_JIT_DESTINATION_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}")
|
||||
|
||||
if (MSVC)
|
||||
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}" "${LUA_JIT_SOURCE_LUA_LIB_EXP}")
|
||||
set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_INSTALL_BYPRODUCTS}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}")
|
||||
endif()
|
||||
|
||||
if (CMAKE_IMPORT_LIBRARY_SUFFIX)
|
||||
if (NOT MSVC)
|
||||
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}" "${LUA_JIT_SOURCE_LUA_IMP_LIB}")
|
||||
endif()
|
||||
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}" "${LUA_JIT_SOURCE_LUA_IMP_LIB}")
|
||||
set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_INSTALL_BYPRODUCTS}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}")
|
||||
endif()
|
||||
|
||||
|
@ -271,16 +264,16 @@ set(LUA_JIT_POSTBUILD_COMMENTS "Executable - Moving \"${LUA_JIT_SOURCE_LUA_INTER
|
|||
set(LUA_JIT_POSTBUILD_COMMANDS COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_INTERPRETER}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}")
|
||||
if (BUILD_LUA_AS_DLL)
|
||||
if (MSVC)
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nImport Library - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Import Library - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_IMP_LIB}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}")
|
||||
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nLibrary - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} && "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB_EXP}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}")
|
||||
endif()
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nDynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Dynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_DLL}")
|
||||
else()
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nLibrary - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} | Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"...")
|
||||
set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}")
|
||||
endif()
|
||||
|
||||
|
@ -307,7 +300,7 @@ if (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST)
|
|||
${LUA_JIT_BUILD_COMMAND}
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
BUILD_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}")
|
||||
BUILD_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}" "${LUA_JIT_BYPRODUCTS}")
|
||||
else()
|
||||
ExternalProject_Add(LUA_JIT
|
||||
BUILD_IN_SOURCE TRUE
|
||||
|
@ -326,25 +319,25 @@ else()
|
|||
CONFIGURE_COMMAND ""
|
||||
${LUA_JIT_BUILD_COMMAND}
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
BUILD_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}")
|
||||
TEST_COMMAND "")
|
||||
endif()
|
||||
|
||||
# # MAYBE?:
|
||||
# Add additional post-build step to move all necessary headers/lua files
|
||||
# for now, we just point directly to the `src` directory...
|
||||
|
||||
add_custom_target(luajit_postbuild
|
||||
ExternalProject_Add_Step(LUA_JIT move
|
||||
${LUA_JIT_POSTBUILD_COMMANDS}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
COMMENT ${LUA_JIT_POSTBUILD_COMMENTS}
|
||||
DEPENDS "${LUA_JIT_BYPRODUCTS}"
|
||||
)
|
||||
|
||||
DEPENDS build
|
||||
ALWAYS TRUE)
|
||||
ExternalProject_Add_StepTargets(LUA_JIT move)
|
||||
|
||||
# # Lua Library
|
||||
add_library(${lualib} ${LUA_BUILD_LIBRARY_TYPE} IMPORTED)
|
||||
# make sure the library we export really does depend on Lua JIT's external project
|
||||
add_dependencies(${lualib} luajit_postbuild)
|
||||
add_dependencies(${lualib} LUA_JIT-move)
|
||||
# Configure properties
|
||||
if (BUILD_LUA_AS_DLL)
|
||||
if (MSVC)
|
||||
|
@ -380,7 +373,7 @@ add_executable(${luainterpreter} IMPORTED)
|
|||
set_target_properties(${luainterpreter}
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION "${LUA_JIT_DESTINATION_LUA_INTERPRETER}")
|
||||
add_dependencies(${luainterpreter} luajit_postbuild)
|
||||
add_dependencies(${luainterpreter} LUA_JIT-move)
|
||||
|
||||
# # set externally-visible target indicator
|
||||
set(LUA_LIBRARIES ${lualib})
|
||||
|
|
|
@ -241,7 +241,7 @@ This is an SFINAE-friendly struct that is meant to expose static function ``get`
|
|||
:name: pusher
|
||||
|
||||
template <typename X, typename = void>
|
||||
struct pusher {
|
||||
struct unqualified_pusher {
|
||||
template <typename T>
|
||||
static int push ( lua_State* L, T&&, ... ) {
|
||||
// can optionally take more than just 1 argument
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
adding your own types
|
||||
=====================
|
||||
|
||||
Sometimes, overriding Sol to make it handle certain ``struct``'s and ``class``'es as something other than just userdata is desirable. The way to do this is to take advantage of the 4 customization points for Sol. These are ``sol::lua_size<T>``, ``sol::stack::pusher<T, C>``, ``sol::stack::getter<T, C>``, ``sol::stack::checker<T, sol::type t, C>``.
|
||||
Sometimes, overriding Sol to make it handle certain ``struct``'s and ``class``'es as something other than just userdata is desirable. The way to do this is to take advantage of the 4 customization points for Sol. These are ``sol::lua_size<T>``, ``sol::stack::unqualified_pusher<T, C>``, ``sol::stack::getter<T, C>``, ``sol::stack::checker<T, sol::type t, C>``.
|
||||
|
||||
These are template class/structs, so you'll override them using a technique C++ calls *class/struct specialization*. Below is an example of a struct that gets broken apart into 2 pieces when going in the C++ --> Lua direction, and then pulled back into a struct when going in the Lua --> C++:
|
||||
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
#define SOL_CHECK_ARGUMENTS 1
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include "assert.hpp"
|
||||
|
||||
struct two_things {
|
||||
int a;
|
||||
bool b;
|
||||
};
|
||||
|
||||
namespace sol {
|
||||
|
||||
// First, the expected size
|
||||
// Specialization of a struct
|
||||
template <>
|
||||
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
|
||||
namespace stack {
|
||||
|
||||
template <>
|
||||
struct unqualified_checker<two_things> {
|
||||
template <typename Handler>
|
||||
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
// indices can be negative to count backwards from the top of the stack,
|
||||
// rather than the bottom up
|
||||
// to deal with this, we adjust the index to
|
||||
// its absolute position using the lua_absindex function
|
||||
int absolute_index = lua_absindex(L, index);
|
||||
// Check first and second second index for being the proper types
|
||||
bool success = stack::check<int>(L, absolute_index, handler)
|
||||
&& stack::check<bool>(L, absolute_index + 1, handler);
|
||||
tracking.use(2);
|
||||
return success;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct unqualified_getter<two_things> {
|
||||
static two_things get(lua_State* L, int index, record& tracking) {
|
||||
int absolute_index = lua_absindex(L, index);
|
||||
// Get the first element
|
||||
int a = stack::get<int>(L, absolute_index);
|
||||
// Get the second element,
|
||||
// in the +1 position from the first
|
||||
bool b = stack::get<bool>(L, absolute_index + 1);
|
||||
// we use 2 slots, each of the previous takes 1
|
||||
tracking.use(2);
|
||||
return two_things{ a, b };
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<two_things> {
|
||||
static int push(lua_State* L, const two_things& things) {
|
||||
int amount = stack::push(L, things.a);
|
||||
// amount will be 1: int pushes 1 item
|
||||
amount += stack::push(L, things.b);
|
||||
// amount 2 now, since bool pushes a single item
|
||||
// Return 2 things
|
||||
return amount;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "=== customization ===" << std::endl;
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
|
||||
// Create a pass-through style of function
|
||||
lua.script("function f ( a, b ) print(a, b) return a, b end");
|
||||
|
||||
// get the function out of Lua
|
||||
sol::function f = lua["f"];
|
||||
|
||||
two_things things = f(two_things{ 24, false });
|
||||
c_assert(things.a == 24);
|
||||
c_assert(things.b == false);
|
||||
// things.a == 24
|
||||
// things.b == true
|
||||
|
||||
std::cout << "things.a: " << things.a << std::endl;
|
||||
std::cout << "things.b: " << things.b << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -37,7 +37,7 @@ GlobalResource* sol_lua_get(sol::types<GlobalResource*>, lua_State* L, int /*ind
|
|||
return ls;
|
||||
}
|
||||
|
||||
int sol_lua_push(lua_State* L, GlobalResource* ls) {
|
||||
int sol_lua_push(sol::types<GlobalResource*>, lua_State* L, GlobalResource* ls) {
|
||||
// push light userdata
|
||||
return sol::stack::push(L, static_cast<void*>(ls));
|
||||
}
|
70
examples/source/customization_multiple.cpp
Normal file
70
examples/source/customization_multiple.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#define SOL_CHECK_ARGUMENTS 1
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include "assert.hpp"
|
||||
|
||||
struct two_things {
|
||||
int a;
|
||||
bool b;
|
||||
};
|
||||
|
||||
template <typename Handler>
|
||||
bool check(sol::types<two_things>, lua_State* L, int index, Handler&& handler, sol::stack::record& tracking) {
|
||||
// indices can be negative to count backwards from the top of the stack,
|
||||
// rather than the bottom up
|
||||
// to deal with this, we adjust the index to
|
||||
// its absolute position using the lua_absindex function
|
||||
int absolute_index = lua_absindex(L, index);
|
||||
// Check first and second second index for being the proper types
|
||||
bool success = sol::stack::check<int>(L, absolute_index, handler) && sol::stack::check<bool>(L, absolute_index + 1, handler);
|
||||
tracking.use(2);
|
||||
return success;
|
||||
}
|
||||
|
||||
two_things get(sol::types<two_things>, lua_State* L, int index, sol::stack::record& tracking) {
|
||||
int absolute_index = lua_absindex(L, index);
|
||||
// Get the first element
|
||||
int a = sol::stack::get<int>(L, absolute_index);
|
||||
// Get the second element,
|
||||
// in the +1 position from the first
|
||||
bool b = sol::stack::get<bool>(L, absolute_index + 1);
|
||||
// we use 2 slots, each of the previous takes 1
|
||||
tracking.use(2);
|
||||
return two_things{ a, b };
|
||||
}
|
||||
|
||||
int push(sol::types<two_things>, lua_State* L, const two_things& things) {
|
||||
int amount = sol::stack::push(L, things.a);
|
||||
// amount will be 1: int pushes 1 item
|
||||
amount += sol::stack::push(L, things.b);
|
||||
// amount 2 now, since bool pushes a single item
|
||||
// Return 2 things
|
||||
return amount;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "=== customization ===" << std::endl;
|
||||
std::cout << std::boolalpha;
|
||||
|
||||
sol::state lua;
|
||||
lua.open_libraries(sol::lib::base);
|
||||
|
||||
// Create a pass-through style of function
|
||||
lua.script("function f ( a, b ) print(a, b) return a, b end");
|
||||
|
||||
// get the function out of Lua
|
||||
sol::function f = lua["f"];
|
||||
|
||||
two_things things = f(two_things{ 24, false });
|
||||
c_assert(things.a == 24);
|
||||
c_assert(things.b == false);
|
||||
// things.a == 24
|
||||
// things.b == true
|
||||
|
||||
std::cout << "things.a: " << things.a << std::endl;
|
||||
std::cout << "things.b: " << things.b << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -39,7 +39,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <typename T>
|
||||
struct pusher<as_args_t<T>> {
|
||||
struct unqualified_pusher<as_args_t<T>> {
|
||||
int push(lua_State* L, const as_args_t<T>& e) {
|
||||
int p = 0;
|
||||
for (const auto& i : e.src) {
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <typename T>
|
||||
struct pusher<as_returns_t<T>> {
|
||||
struct unqualified_pusher<as_returns_t<T>> {
|
||||
int push(lua_State* L, const as_returns_t<T>& e) {
|
||||
auto& src = detail::unwrap(e.src);
|
||||
int p = 0;
|
||||
|
|
|
@ -49,6 +49,12 @@
|
|||
#endif // sol luajit
|
||||
#endif // luajit
|
||||
|
||||
#if SOL_LUAJIT && SOL_LUAJIT_VERSION >= 20100
|
||||
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && (!defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) && !(SOL_EXCEPTIONS_ALWAYS_UNSAFE))
|
||||
#define SOL_EXCEPTIONS_SAFE_PROPAGATION 1
|
||||
#endif // Do not catch (...) clauses
|
||||
#endif // LuaJIT beta 02.01.00 have better exception handling on all platforms since beta3
|
||||
|
||||
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502
|
||||
#define SOL_LUA_VERSION LUA_VERSION_NUM
|
||||
#elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
|
||||
|
|
|
@ -198,6 +198,10 @@ namespace sol {
|
|||
template <typename T>
|
||||
bool weak_derive<T>::value = false;
|
||||
|
||||
namespace stack {
|
||||
struct record;
|
||||
}
|
||||
|
||||
} // namespace sol
|
||||
|
||||
#define SOL_BASE_CLASSES(T, ...) \
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <typename... Sigs>
|
||||
struct pusher<function_sig<Sigs...>> {
|
||||
struct unqualified_pusher<function_sig<Sigs...>> {
|
||||
template <bool is_yielding, typename... Sig, typename Fx, typename... Args>
|
||||
static void select_convertible(std::false_type, types<Sig...>, lua_State* L, Fx&& fx, Args&&... args) {
|
||||
typedef std::remove_pointer_t<std::decay_t<Fx>> clean_fx;
|
||||
|
@ -244,24 +244,24 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<yielding_t<T>> {
|
||||
struct unqualified_pusher<yielding_t<T>> {
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, const yielding_t<T>& f, Args&&... args) {
|
||||
pusher<function_sig<>> p{};
|
||||
unqualified_pusher<function_sig<>> p{};
|
||||
(void)p;
|
||||
return p.push(L, detail::yield_tag, f.func, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, yielding_t<T>&& f, Args&&... args) {
|
||||
pusher<function_sig<>> p{};
|
||||
unqualified_pusher<function_sig<>> p{};
|
||||
(void)p;
|
||||
return p.push(L, detail::yield_tag, f.func, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename... Args>
|
||||
struct pusher<function_arguments<T, Args...>> {
|
||||
struct unqualified_pusher<function_arguments<T, Args...>> {
|
||||
template <std::size_t... I, typename FP>
|
||||
static int push_func(std::index_sequence<I...>, lua_State* L, FP&& fp) {
|
||||
return stack::push<T>(L, std::get<I>(std::forward<FP>(fp).arguments)...);
|
||||
|
@ -277,28 +277,28 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename Signature>
|
||||
struct pusher<std::function<Signature>> {
|
||||
struct unqualified_pusher<std::function<Signature>> {
|
||||
static int push(lua_State* L, const std::function<Signature>& fx) {
|
||||
return pusher<function_sig<Signature>>{}.push(L, fx);
|
||||
return unqualified_pusher<function_sig<Signature>>{}.push(L, fx);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, std::function<Signature>&& fx) {
|
||||
return pusher<function_sig<Signature>>{}.push(L, std::move(fx));
|
||||
return unqualified_pusher<function_sig<Signature>>{}.push(L, std::move(fx));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Signature>
|
||||
struct pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
|
||||
struct unqualified_pusher<Signature, std::enable_if_t<std::is_member_pointer<Signature>::value>> {
|
||||
template <typename F, typename... Args>
|
||||
static int push(lua_State* L, F&& f, Args&&... args) {
|
||||
pusher<function_sig<>> p{};
|
||||
unqualified_pusher<function_sig<>> p{};
|
||||
(void)p;
|
||||
return p.push(L, std::forward<F>(f), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Signature>
|
||||
struct pusher<Signature, std::enable_if_t<meta::all<std::is_function<std::remove_pointer_t<Signature>>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>
|
||||
struct unqualified_pusher<Signature, std::enable_if_t<meta::all<std::is_function<std::remove_pointer_t<Signature>>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>
|
||||
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
|
||||
,
|
||||
meta::neg<std::is_same<Signature, detail::lua_CFunction_noexcept>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<detail::lua_CFunction_noexcept>>>
|
||||
|
@ -306,29 +306,29 @@ namespace sol {
|
|||
>::value>> {
|
||||
template <typename F>
|
||||
static int push(lua_State* L, F&& f) {
|
||||
return pusher<function_sig<>>{}.push(L, std::forward<F>(f));
|
||||
return unqualified_pusher<function_sig<>>{}.push(L, std::forward<F>(f));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Functions>
|
||||
struct pusher<overload_set<Functions...>> {
|
||||
struct unqualified_pusher<overload_set<Functions...>> {
|
||||
static int push(lua_State* L, overload_set<Functions...>&& set) {
|
||||
// TODO: yielding
|
||||
typedef function_detail::overloaded_function<0, Functions...> F;
|
||||
pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(set.functions));
|
||||
unqualified_pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(set.functions));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const overload_set<Functions...>& set) {
|
||||
// TODO: yielding
|
||||
typedef function_detail::overloaded_function<0, Functions...> F;
|
||||
pusher<function_sig<>>{}.set_fx<false, F>(L, set.functions);
|
||||
unqualified_pusher<function_sig<>>{}.set_fx<false, F>(L, set.functions);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<protect_t<T>> {
|
||||
struct unqualified_pusher<protect_t<T>> {
|
||||
static int push(lua_State* L, protect_t<T>&& pw) {
|
||||
lua_CFunction cf = call_detail::call_user<void, false, false, protect_t<T>, 2>;
|
||||
int upvalues = 0;
|
||||
|
@ -347,7 +347,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename F, typename G>
|
||||
struct pusher<property_wrapper<F, G>, std::enable_if_t<!std::is_void<F>::value && !std::is_void<G>::value>> {
|
||||
struct unqualified_pusher<property_wrapper<F, G>, std::enable_if_t<!std::is_void<F>::value && !std::is_void<G>::value>> {
|
||||
static int push(lua_State* L, property_wrapper<F, G>&& pw) {
|
||||
return stack::push(L, overload(std::move(pw.read), std::move(pw.write)));
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename F>
|
||||
struct pusher<property_wrapper<F, void>> {
|
||||
struct unqualified_pusher<property_wrapper<F, void>> {
|
||||
static int push(lua_State* L, property_wrapper<F, void>&& pw) {
|
||||
return stack::push(L, std::move(pw.read));
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename F>
|
||||
struct pusher<property_wrapper<void, F>> {
|
||||
struct unqualified_pusher<property_wrapper<void, F>> {
|
||||
static int push(lua_State* L, property_wrapper<void, F>&& pw) {
|
||||
return stack::push(L, std::move(pw.write));
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<var_wrapper<T>> {
|
||||
struct unqualified_pusher<var_wrapper<T>> {
|
||||
static int push(lua_State* L, var_wrapper<T>&& vw) {
|
||||
return stack::push(L, std::move(vw.value));
|
||||
}
|
||||
|
@ -387,34 +387,34 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename... Functions>
|
||||
struct pusher<factory_wrapper<Functions...>> {
|
||||
struct unqualified_pusher<factory_wrapper<Functions...>> {
|
||||
static int push(lua_State* L, const factory_wrapper<Functions...>& fw) {
|
||||
typedef function_detail::overloaded_function<0, Functions...> F;
|
||||
pusher<function_sig<>>{}.set_fx<false, F>(L, fw.functions);
|
||||
unqualified_pusher<function_sig<>>{}.set_fx<false, F>(L, fw.functions);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int push(lua_State* L, factory_wrapper<Functions...>&& fw) {
|
||||
typedef function_detail::overloaded_function<0, Functions...> F;
|
||||
pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(fw.functions));
|
||||
unqualified_pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(fw.functions));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const factory_wrapper<Functions...>& set, function_detail::call_indicator) {
|
||||
typedef function_detail::overloaded_function<1, Functions...> F;
|
||||
pusher<function_sig<>>{}.set_fx<false, F>(L, set.functions);
|
||||
unqualified_pusher<function_sig<>>{}.set_fx<false, F>(L, set.functions);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int push(lua_State* L, factory_wrapper<Functions...>&& set, function_detail::call_indicator) {
|
||||
typedef function_detail::overloaded_function<1, Functions...> F;
|
||||
pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(set.functions));
|
||||
unqualified_pusher<function_sig<>>{}.set_fx<false, F>(L, std::move(set.functions));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<no_construction> {
|
||||
struct unqualified_pusher<no_construction> {
|
||||
static int push(lua_State* L, no_construction) {
|
||||
lua_CFunction cf = &function_detail::no_construction_error;
|
||||
return stack::push(L, cf);
|
||||
|
@ -426,7 +426,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T, typename... Lists>
|
||||
struct pusher<detail::tagged<T, constructor_list<Lists...>>> {
|
||||
struct unqualified_pusher<detail::tagged<T, constructor_list<Lists...>>> {
|
||||
static int push(lua_State* L, detail::tagged<T, constructor_list<Lists...>>) {
|
||||
lua_CFunction cf = call_detail::construct<T, detail::default_safe_function_calls, true, Lists...>;
|
||||
return stack::push(L, cf);
|
||||
|
@ -439,7 +439,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename L0, typename... Lists>
|
||||
struct pusher<constructor_list<L0, Lists...>> {
|
||||
struct unqualified_pusher<constructor_list<L0, Lists...>> {
|
||||
typedef constructor_list<L0, Lists...> cl_t;
|
||||
static int push(lua_State* L, cl_t cl) {
|
||||
typedef typename meta::bind_traits<L0>::return_type T;
|
||||
|
@ -448,7 +448,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T, typename... Fxs>
|
||||
struct pusher<detail::tagged<T, constructor_wrapper<Fxs...>>> {
|
||||
struct unqualified_pusher<detail::tagged<T, constructor_wrapper<Fxs...>>> {
|
||||
template <typename C>
|
||||
static int push(lua_State* L, C&& c) {
|
||||
lua_CFunction cf = call_detail::call_user<T, false, false, constructor_wrapper<Fxs...>, 2>;
|
||||
|
@ -460,7 +460,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename F, typename... Fxs>
|
||||
struct pusher<constructor_wrapper<F, Fxs...>> {
|
||||
struct unqualified_pusher<constructor_wrapper<F, Fxs...>> {
|
||||
template <typename C>
|
||||
static int push(lua_State* L, C&& c) {
|
||||
typedef typename meta::bind_traits<F>::template arg_at<0> arg0;
|
||||
|
@ -470,7 +470,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
||||
struct unqualified_pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
||||
static int push(lua_State* L, destructor_wrapper<void>) {
|
||||
lua_CFunction cf = detail::usertype_alloc_destruct<T>;
|
||||
return stack::push(L, cf);
|
||||
|
@ -478,7 +478,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T, typename Fx>
|
||||
struct pusher<detail::tagged<T, destructor_wrapper<Fx>>> {
|
||||
struct unqualified_pusher<detail::tagged<T, destructor_wrapper<Fx>>> {
|
||||
static int push(lua_State* L, destructor_wrapper<Fx>&& c) {
|
||||
lua_CFunction cf = call_detail::call_user<T, false, false, destructor_wrapper<Fx>, 2>;
|
||||
int upvalues = 0;
|
||||
|
@ -497,7 +497,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename Fx>
|
||||
struct pusher<destructor_wrapper<Fx>> {
|
||||
struct unqualified_pusher<destructor_wrapper<Fx>> {
|
||||
static int push(lua_State* L, destructor_wrapper<Fx>&& c) {
|
||||
lua_CFunction cf = call_detail::call_user<void, false, false, destructor_wrapper<Fx>, 2>;
|
||||
int upvalues = 0;
|
||||
|
@ -516,7 +516,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename F, typename... Filters>
|
||||
struct pusher<filter_wrapper<F, Filters...>> {
|
||||
struct unqualified_pusher<filter_wrapper<F, Filters...>> {
|
||||
typedef filter_wrapper<F, Filters...> P;
|
||||
|
||||
static int push(lua_State* L, const P& p) {
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <>
|
||||
struct pusher<protected_function_result> {
|
||||
struct unqualified_pusher<protected_function_result> {
|
||||
static int push(lua_State* L, const protected_function_result& pfr) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, static_cast<int>(pfr.pop_count()), detail::not_enough_stack_space_generic);
|
||||
|
|
|
@ -253,7 +253,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <typename Table, typename Key>
|
||||
struct pusher<proxy<Table, Key>> {
|
||||
struct unqualified_pusher<proxy<Table, Key>> {
|
||||
static int push(lua_State* L, const proxy<Table, Key>& p) {
|
||||
reference r = p;
|
||||
return r.push(L);
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
inline void luajit_exception_handler(lua_State* L, int (*handler)(lua_State*, lua_CFunction) = detail::c_trampoline) {
|
||||
#if defined(SOL_LUAJIT) && !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION)
|
||||
#if defined(SOL_LUAJIT) && (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION))
|
||||
if (L == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -26,17 +26,60 @@
|
|||
|
||||
#include "stack_core.hpp"
|
||||
#include "stack_check_get_unqualified.hpp"
|
||||
#include "optional.hpp"
|
||||
|
||||
namespace sol {
|
||||
namespace stack {
|
||||
namespace sol { namespace stack {
|
||||
template <typename T, typename C>
|
||||
struct qualified_check_getter {
|
||||
typedef decltype(stack_detail::unchecked_get<T>(nullptr, -1, std::declval<record&>())) R;
|
||||
|
||||
template <typename Handler>
|
||||
static decltype(auto) get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
return stack::unqualified_check_get<T>(L, index, std::forward<Handler>(handler), tracking);
|
||||
static optional<R> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
if (!check<T>(L, index, std::forward<Handler>(handler))) {
|
||||
tracking.use(static_cast<int>(!lua_isnone(L, index)));
|
||||
return nullopt;
|
||||
}
|
||||
return stack_detail::unchecked_get<T>(L, index, tracking);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace sol::stack
|
||||
|
||||
template <typename T>
|
||||
struct qualified_check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
// actually check if it's none here, otherwise
|
||||
// we'll have a none object inside an optional!
|
||||
bool success = lua_isnoneornil(L, index) == 0 && stack::check<T>(L, index, no_panic);
|
||||
if (!success) {
|
||||
// expected type, actual type
|
||||
tracking.use(static_cast<int>(success));
|
||||
handler(L, index, type::poly, type_of(L, index), "");
|
||||
return nullopt;
|
||||
}
|
||||
return stack_detail::unchecked_get<T>(L, index, tracking);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct qualified_getter<optional<T>> {
|
||||
static decltype(auto) get(lua_State* L, int index, record& tracking) {
|
||||
return check_get<T>(L, index, no_panic, tracking);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
|
||||
template <typename T>
|
||||
struct qualified_getter<std::optional<T>> {
|
||||
static std::optional<T> get(lua_State* L, int index, record& tracking) {
|
||||
if (!check<T>(L, index, no_panic)) {
|
||||
tracking.use(static_cast<int>(!lua_isnone(L, index)));
|
||||
return std::nullopt;
|
||||
}
|
||||
return stack_detail::unchecked_get<T>(L, index, tracking);
|
||||
}
|
||||
};
|
||||
#endif // C++17 features
|
||||
|
||||
}} // namespace sol::stack
|
||||
|
||||
#endif // SOL_STACK_CHECK_QUALIFIED_GET_HPP
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
namespace sol {
|
||||
namespace stack {
|
||||
template <typename T, typename>
|
||||
struct check_getter {
|
||||
struct unqualified_check_getter {
|
||||
typedef decltype(stack_detail::unchecked_unqualified_get<T>(nullptr, -1, std::declval<record&>())) R;
|
||||
|
||||
template <typename Handler>
|
||||
|
@ -54,7 +54,7 @@ namespace stack {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
struct unqualified_check_getter<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
// actually check if it's none here, otherwise
|
||||
|
@ -71,7 +71,7 @@ namespace stack {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct check_getter<T, std::enable_if_t<std::is_integral<T>::value && lua_type_of<T>::value == type::number>> {
|
||||
struct unqualified_check_getter<T, std::enable_if_t<std::is_integral<T>::value && lua_type_of<T>::value == type::number>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
#if SOL_LUA_VERSION >= 503
|
||||
|
@ -102,7 +102,7 @@ namespace stack {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct check_getter<T, std::enable_if_t<std::is_enum<T>::value && !meta::any_same<T, meta_function, type>::value>> {
|
||||
struct unqualified_check_getter<T, std::enable_if_t<std::is_enum<T>::value && !meta::any_same<T, meta_function, type>::value>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
int isnum = 0;
|
||||
|
@ -119,7 +119,7 @@ namespace stack {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct check_getter<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
struct unqualified_check_getter<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
template <typename Handler>
|
||||
static optional<T> get(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
int isnum = 0;
|
||||
|
@ -156,7 +156,7 @@ namespace stack {
|
|||
|
||||
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
|
||||
template <typename... Tn>
|
||||
struct check_getter<std::variant<Tn...>> {
|
||||
struct unqualified_check_getter<std::variant<Tn...>> {
|
||||
typedef std::variant<Tn...> V;
|
||||
typedef std::variant_size<V> V_size;
|
||||
typedef std::integral_constant<bool, V_size::value == 0> V_is_empty;
|
||||
|
|
|
@ -38,8 +38,7 @@
|
|||
#endif // SOL_STD_VARIANT
|
||||
#endif // SOL_CXX17_FEATURES
|
||||
|
||||
namespace sol {
|
||||
namespace stack {
|
||||
namespace sol { namespace stack {
|
||||
namespace stack_detail {
|
||||
template <typename T, bool poptable = true>
|
||||
inline bool check_metatable(lua_State* L, int index = -2) {
|
||||
|
@ -95,7 +94,12 @@ namespace stack {
|
|||
};
|
||||
|
||||
template <typename T, type expected, typename C>
|
||||
struct qualified_checker : unqualified_checker<meta::unqualified_t<T>, lua_type_of<meta::unqualified_t<T>>::value, C> {};
|
||||
struct qualified_checker {
|
||||
template <typename Handler>
|
||||
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
|
||||
return stack::unqualified_check<T>(L, index, std::forward<Handler>(handler), tracking);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct unqualified_checker<T, type::number, std::enable_if_t<std::is_integral<T>::value>> {
|
||||
|
@ -459,7 +463,8 @@ namespace stack {
|
|||
handler(L, index, type::userdata, indextype, "value is not a valid userdata");
|
||||
return false;
|
||||
}
|
||||
if (meta::any<std::is_same<T, lightuserdata_value>, std::is_same<T, userdata_value>, std::is_same<T, userdata>, std::is_same<T, lightuserdata>>::value)
|
||||
if (meta::any<std::is_same<T, lightuserdata_value>, std::is_same<T, userdata_value>, std::is_same<T, userdata>, std::is_same<T, lightuserdata>>::
|
||||
value)
|
||||
return true;
|
||||
if (lua_getmetatable(L, index) == 0) {
|
||||
return true;
|
||||
|
@ -668,7 +673,6 @@ namespace stack {
|
|||
#endif // SOL_STD_VARIANT
|
||||
|
||||
#endif // SOL_CXX17_FEATURES
|
||||
}
|
||||
} // namespace sol::stack
|
||||
}} // namespace sol::stack
|
||||
|
||||
#endif // SOL_STACK_CHECK_UNQUALIFIED_HPP
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
namespace sol {
|
||||
namespace detail {
|
||||
struct with_function_tag {};
|
||||
struct as_reference_tag {};
|
||||
template <typename T>
|
||||
struct as_pointer_tag {};
|
||||
|
@ -570,7 +571,7 @@ namespace sol {
|
|||
template <typename T, typename = void>
|
||||
struct popper;
|
||||
template <typename T, typename = void>
|
||||
struct pusher;
|
||||
struct unqualified_pusher;
|
||||
template <typename T, type = lua_type_of<T>::value, typename = void>
|
||||
struct unqualified_checker;
|
||||
template <typename T, type = lua_type_of<T>::value, typename = void>
|
||||
|
@ -578,7 +579,7 @@ namespace sol {
|
|||
template <typename T, typename = void>
|
||||
struct userdata_checker;
|
||||
template <typename T, typename = void>
|
||||
struct check_getter;
|
||||
struct unqualified_check_getter;
|
||||
template <typename T, typename = void>
|
||||
struct qualified_check_getter;
|
||||
|
||||
|
@ -613,7 +614,8 @@ namespace sol {
|
|||
struct is_adl_sol_lua_get {
|
||||
private:
|
||||
template <typename C>
|
||||
static meta::sfinae_yes_t test(decltype(sol_lua_get(types<C>(), static_cast<lua_State*>(nullptr), -1, std::declval<stack::record>()))*);
|
||||
static meta::sfinae_yes_t test(
|
||||
std::remove_reference_t<decltype(sol_lua_get(types<C>(), static_cast<lua_State*>(nullptr), -1, std::declval<stack::record&>()))>*);
|
||||
template <typename C>
|
||||
static meta::sfinae_no_t test(...);
|
||||
|
||||
|
@ -625,8 +627,8 @@ namespace sol {
|
|||
struct is_adl_sol_lua_check {
|
||||
private:
|
||||
template <typename C>
|
||||
static meta::sfinae_yes_t test(
|
||||
decltype(sol_lua_check(types<C>(), static_cast<lua_State*>(nullptr), -1, no_panic, std::declval<stack::record>()))*);
|
||||
static meta::sfinae_yes_t test(std::remove_reference_t<decltype(
|
||||
sol_lua_check(types<C>(), static_cast<lua_State*>(nullptr), -1, no_panic, std::declval<stack::record&>()))>*);
|
||||
template <typename C>
|
||||
static meta::sfinae_no_t test(...);
|
||||
|
||||
|
@ -638,8 +640,8 @@ namespace sol {
|
|||
struct is_adl_sol_lua_check_get {
|
||||
private:
|
||||
template <typename C>
|
||||
static meta::sfinae_yes_t test(
|
||||
decltype(sol_lua_check_get(types<C>(), static_cast<lua_State*>(nullptr), -1, no_panic, std::declval<stack::record>()))*);
|
||||
static meta::sfinae_yes_t test(std::remove_reference_t<decltype(
|
||||
sol_lua_check_get(types<C>(), static_cast<lua_State*>(nullptr), -1, no_panic, std::declval<stack::record&>()))>*);
|
||||
template <typename C>
|
||||
static meta::sfinae_no_t test(...);
|
||||
|
||||
|
@ -651,7 +653,7 @@ namespace sol {
|
|||
struct is_adl_sol_lua_push {
|
||||
private:
|
||||
template <typename... C>
|
||||
static meta::sfinae_yes_t test(decltype(sol_lua_push(static_cast<lua_State*>(nullptr), std::declval<C>()...))*);
|
||||
static meta::sfinae_yes_t test(std::remove_reference_t<decltype(sol_lua_push(static_cast<lua_State*>(nullptr), std::declval<C>()...))>*);
|
||||
template <typename... C>
|
||||
static meta::sfinae_no_t test(...);
|
||||
|
||||
|
@ -663,7 +665,8 @@ namespace sol {
|
|||
struct is_adl_sol_lua_push_exact {
|
||||
private:
|
||||
template <typename... C>
|
||||
static meta::sfinae_yes_t test(decltype(sol_lua_push(types<T>(), static_cast<lua_State*>(nullptr), std::declval<C>()...))*);
|
||||
static meta::sfinae_yes_t test(
|
||||
std::remove_reference_t<decltype(sol_lua_push(types<T>(), static_cast<lua_State*>(nullptr), std::declval<C>()...))>*);
|
||||
template <typename... C>
|
||||
static meta::sfinae_no_t test(...);
|
||||
|
||||
|
@ -812,7 +815,7 @@ namespace sol {
|
|||
return sol_lua_push(L, std::forward<T>(t), std::forward<Args>(args)...);
|
||||
}
|
||||
else {
|
||||
pusher<Tu> p{};
|
||||
unqualified_pusher<Tu> p{};
|
||||
(void)p;
|
||||
return p.push(L, std::forward<T>(t), std::forward<Args>(args)...);
|
||||
}
|
||||
|
@ -832,7 +835,7 @@ namespace sol {
|
|||
return sol_lua_push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
|
||||
}
|
||||
else {
|
||||
pusher<Tu> p{};
|
||||
unqualified_pusher<Tu> p{};
|
||||
(void)p;
|
||||
return p.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
|
||||
}
|
||||
|
@ -974,7 +977,7 @@ namespace sol {
|
|||
return sol_lua_check_get(types<Tu>(), L, index, std::forward<Handler>(handler), tracking);
|
||||
}
|
||||
else {
|
||||
check_getter<Tu> cg{};
|
||||
unqualified_check_getter<Tu> cg{};
|
||||
(void)cg;
|
||||
return cg.get(L, index, std::forward<Handler>(handler), tracking);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<stack_proxy> {
|
||||
struct unqualified_pusher<stack_proxy> {
|
||||
static int push(lua_State*, const stack_proxy& ref) {
|
||||
return ref.push();
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<stack_proxy_base> {
|
||||
struct unqualified_pusher<stack_proxy_base> {
|
||||
static int push(lua_State*, const stack_proxy_base& ref) {
|
||||
return ref.push();
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace sol {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
struct pusher<detail::as_value_tag<T>> {
|
||||
struct unqualified_pusher<detail::as_value_tag<T>> {
|
||||
template <typename F, typename... Args>
|
||||
static int push_fx(lua_State* L, F&& f, Args&&... args) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
|
@ -95,14 +95,23 @@ namespace sol {
|
|||
return push_fx(L, fx, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename Arg, typename... Args, typename = std::enable_if_t<!std::is_same_v<meta::unqualified_t<Arg>, detail::with_function_tag>>>
|
||||
static int push(lua_State* L, Arg&& arg, Args&&... args) {
|
||||
return push_keyed(L, usertype_traits<T>::metatable(), std::forward<Arg>(arg), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static int push(lua_State* L) {
|
||||
return push_keyed(L, usertype_traits<T>::metatable());
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, Args&&... args) {
|
||||
return push_keyed(L, usertype_traits<T>::metatable(), std::forward<Args>(args)...);
|
||||
static int push(lua_State* L, detail::with_function_tag, Args&&... args) {
|
||||
return push_fx(L, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<detail::as_pointer_tag<T>> {
|
||||
struct unqualified_pusher<detail::as_pointer_tag<T>> {
|
||||
typedef meta::unqualified_t<T> U;
|
||||
|
||||
template <typename F>
|
||||
|
@ -124,13 +133,19 @@ namespace sol {
|
|||
return push_fx(L, fx, obj);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, T* obj) {
|
||||
return push_keyed(L, usertype_traits<U*>::metatable(), obj);
|
||||
template <typename Arg, typename... Args, typename = std::enable_if_t<!std::is_same_v<meta::unqualified_t<Arg>, detail::with_function_tag>>>
|
||||
static int push(lua_State* L, Arg&& arg, Args&&... args) {
|
||||
return push_keyed(L, usertype_traits<U*>::metatable(), std::forward<Arg>(arg), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, detail::with_function_tag, Args&&... args) {
|
||||
return push_fx(L, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<detail::as_reference_tag> {
|
||||
struct unqualified_pusher<detail::as_reference_tag> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& obj) {
|
||||
return stack::push(L, detail::ptr(obj));
|
||||
|
@ -138,25 +153,25 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T, typename>
|
||||
struct pusher {
|
||||
struct unqualified_pusher {
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, Args&&... args) {
|
||||
return pusher<detail::as_value_tag<T>>{}.push(L, std::forward<Args>(args)...);
|
||||
return stack::push<detail::as_value_tag<T>>(L, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T*,
|
||||
struct unqualified_pusher<T*,
|
||||
meta::disable_if_t<meta::any<is_container<meta::unqualified_t<T>>, std::is_function<meta::unqualified_t<T>>,
|
||||
is_lua_reference<meta::unqualified_t<T>>>::value>> {
|
||||
template <typename... Args>
|
||||
static int push(lua_State* L, Args&&... args) {
|
||||
return pusher<detail::as_pointer_tag<T>>{}.push(L, std::forward<Args>(args)...);
|
||||
return stack::push<detail::as_pointer_tag<T>>(L, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
|
||||
struct unqualified_pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
|
||||
typedef unique_usertype_traits<T> u_traits;
|
||||
typedef typename u_traits::type P;
|
||||
typedef typename u_traits::actual_type Real;
|
||||
|
@ -202,14 +217,14 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<std::reference_wrapper<T>> {
|
||||
struct unqualified_pusher<std::reference_wrapper<T>> {
|
||||
static int push(lua_State* L, const std::reference_wrapper<T>& t) {
|
||||
return stack::push(L, std::addressof(detail::deref(t.get())));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
struct unqualified_pusher<T, std::enable_if_t<std::is_floating_point<T>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_floating);
|
||||
|
@ -220,7 +235,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T, std::enable_if_t<std::is_integral<T>::value>> {
|
||||
struct unqualified_pusher<T, std::enable_if_t<std::is_integral<T>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_integral);
|
||||
|
@ -259,7 +274,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T, std::enable_if_t<std::is_enum<T>::value>> {
|
||||
struct unqualified_pusher<T, std::enable_if_t<std::is_enum<T>::value>> {
|
||||
static int push(lua_State* L, const T& value) {
|
||||
if (std::is_same<char, std::underlying_type_t<T>>::value) {
|
||||
return stack::push(L, static_cast<int>(value));
|
||||
|
@ -269,7 +284,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<detail::as_table_tag<T>> {
|
||||
struct unqualified_pusher<detail::as_table_tag<T>> {
|
||||
static int push(lua_State* L, const T& tablecont) {
|
||||
typedef meta::has_key_value_pair<meta::unqualified_t<std::remove_pointer_t<T>>> has_kvp;
|
||||
return push(has_kvp(), std::false_type(), L, tablecont);
|
||||
|
@ -346,23 +361,23 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<as_table_t<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
struct unqualified_pusher<as_table_t<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
static int push(lua_State* L, const T& tablecont) {
|
||||
return stack::push<detail::as_table_tag<T>>(L, tablecont);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<as_table_t<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
struct unqualified_pusher<as_table_t<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
static int push(lua_State* L, const T& v) {
|
||||
return stack::push(L, v);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<nested<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
struct unqualified_pusher<nested<T>, std::enable_if_t<is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
static int push(lua_State* L, const T& tablecont) {
|
||||
pusher<detail::as_table_tag<T>> p{};
|
||||
unqualified_pusher<detail::as_table_tag<T>> p{};
|
||||
// silence annoying VC++ warning
|
||||
(void)p;
|
||||
return p.push(std::true_type(), L, tablecont);
|
||||
|
@ -370,9 +385,9 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<nested<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
struct unqualified_pusher<nested<T>, std::enable_if_t<!is_container<std::remove_pointer_t<meta::unwrap_unqualified_t<T>>>::value>> {
|
||||
static int push(lua_State* L, const T& tablecont) {
|
||||
pusher<meta::unqualified_t<T>> p{};
|
||||
unqualified_pusher<meta::unqualified_t<T>> p{};
|
||||
// silence annoying VC++ warning
|
||||
(void)p;
|
||||
return p.push(L, tablecont);
|
||||
|
@ -380,9 +395,9 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<std::initializer_list<T>> {
|
||||
struct unqualified_pusher<std::initializer_list<T>> {
|
||||
static int push(lua_State* L, const std::initializer_list<T>& il) {
|
||||
pusher<detail::as_table_tag<std::initializer_list<T>>> p{};
|
||||
unqualified_pusher<detail::as_table_tag<std::initializer_list<T>>> p{};
|
||||
// silence annoying VC++ warning
|
||||
(void)p;
|
||||
return p.push(L, il);
|
||||
|
@ -390,7 +405,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
struct unqualified_pusher<T, std::enable_if_t<is_lua_reference<T>::value>> {
|
||||
static int push(lua_State* L, const T& ref) {
|
||||
return ref.push(L);
|
||||
}
|
||||
|
@ -401,7 +416,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<bool> {
|
||||
struct unqualified_pusher<bool> {
|
||||
static int push(lua_State* L, bool b) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -412,7 +427,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<lua_nil_t> {
|
||||
struct unqualified_pusher<lua_nil_t> {
|
||||
static int push(lua_State* L, lua_nil_t) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -423,14 +438,14 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<stack_count> {
|
||||
struct unqualified_pusher<stack_count> {
|
||||
static int push(lua_State*, stack_count st) {
|
||||
return st.count;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<metatable_t> {
|
||||
struct unqualified_pusher<metatable_t> {
|
||||
static int push(lua_State* L, metatable_t) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -441,7 +456,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<std::remove_pointer_t<lua_CFunction>> {
|
||||
struct unqualified_pusher<std::remove_pointer_t<lua_CFunction>> {
|
||||
static int push(lua_State* L, lua_CFunction func, int n = 0) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -452,7 +467,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<lua_CFunction> {
|
||||
struct unqualified_pusher<lua_CFunction> {
|
||||
static int push(lua_State* L, lua_CFunction func, int n = 0) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -464,7 +479,7 @@ namespace sol {
|
|||
|
||||
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
|
||||
template <>
|
||||
struct pusher<std::remove_pointer_t<detail::lua_CFunction_noexcept>> {
|
||||
struct unqualified_pusher<std::remove_pointer_t<detail::lua_CFunction_noexcept>> {
|
||||
static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -475,7 +490,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<detail::lua_CFunction_noexcept> {
|
||||
struct unqualified_pusher<detail::lua_CFunction_noexcept> {
|
||||
static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -487,7 +502,7 @@ namespace sol {
|
|||
#endif // noexcept function type
|
||||
|
||||
template <>
|
||||
struct pusher<c_closure> {
|
||||
struct unqualified_pusher<c_closure> {
|
||||
static int push(lua_State* L, c_closure cc) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -498,7 +513,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename Arg, typename... Args>
|
||||
struct pusher<closure<Arg, Args...>> {
|
||||
struct unqualified_pusher<closure<Arg, Args...>> {
|
||||
template <std::size_t... I, typename T>
|
||||
static int push(std::index_sequence<I...>, lua_State* L, T&& c) {
|
||||
using f_tuple = decltype(std::forward<T>(c).upvalues);
|
||||
|
@ -513,7 +528,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<void*> {
|
||||
struct unqualified_pusher<void*> {
|
||||
static int push(lua_State* L, void* userdata) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -524,7 +539,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const void*> {
|
||||
struct unqualified_pusher<const void*> {
|
||||
static int push(lua_State* L, const void* userdata) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -535,7 +550,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<lightuserdata_value> {
|
||||
struct unqualified_pusher<lightuserdata_value> {
|
||||
static int push(lua_State* L, lightuserdata_value userdata) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -546,7 +561,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<light<T>> {
|
||||
struct unqualified_pusher<light<T>> {
|
||||
static int push(lua_State* L, light<T> l) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -557,7 +572,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<user<T>> {
|
||||
struct unqualified_pusher<user<T>> {
|
||||
template <bool with_meta = true, typename Key, typename... Args>
|
||||
static int push_with(lua_State* L, Key&& name, Args&&... args) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
|
@ -622,7 +637,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<userdata_value> {
|
||||
struct unqualified_pusher<userdata_value> {
|
||||
static int push(lua_State* L, userdata_value data) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_userdata);
|
||||
|
@ -634,7 +649,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const char*> {
|
||||
struct unqualified_pusher<const char*> {
|
||||
static int push_sized(lua_State* L, const char* str, std::size_t len) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_string);
|
||||
|
@ -659,34 +674,34 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char*> {
|
||||
struct unqualified_pusher<char*> {
|
||||
static int push_sized(lua_State* L, const char* str, std::size_t len) {
|
||||
pusher<const char*> p{};
|
||||
unqualified_pusher<const char*> p{};
|
||||
(void)p;
|
||||
return p.push_sized(L, str, len);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char* str) {
|
||||
pusher<const char*> p{};
|
||||
unqualified_pusher<const char*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char* strb, const char* stre) {
|
||||
pusher<const char*> p{};
|
||||
unqualified_pusher<const char*> p{};
|
||||
(void)p;
|
||||
return p.push(L, strb, stre);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char* str, std::size_t len) {
|
||||
pusher<const char*> p{};
|
||||
unqualified_pusher<const char*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str, len);
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t N>
|
||||
struct pusher<char[N]> {
|
||||
struct unqualified_pusher<char[N]> {
|
||||
static int push(lua_State* L, const char (&str)[N]) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_string);
|
||||
|
@ -705,7 +720,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char> {
|
||||
struct unqualified_pusher<char> {
|
||||
static int push(lua_State* L, char c) {
|
||||
const char str[2] = { c, '\0' };
|
||||
return stack::push(L, str, 1);
|
||||
|
@ -713,7 +728,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename Traits, typename Al>
|
||||
struct pusher<std::basic_string<char, Traits, Al>> {
|
||||
struct unqualified_pusher<std::basic_string<char, Traits, Al>> {
|
||||
static int push(lua_State* L, const std::basic_string<char, Traits, Al>& str) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_string);
|
||||
|
@ -732,7 +747,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename Ch, typename Traits>
|
||||
struct pusher<basic_string_view<Ch, Traits>> {
|
||||
struct unqualified_pusher<basic_string_view<Ch, Traits>> {
|
||||
static int push(lua_State* L, const basic_string_view<Ch, Traits>& sv) {
|
||||
return stack::push(L, sv.data(), sv.length());
|
||||
}
|
||||
|
@ -743,7 +758,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<meta_function> {
|
||||
struct unqualified_pusher<meta_function> {
|
||||
static int push(lua_State* L, meta_function m) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_meta_function_name);
|
||||
|
@ -755,7 +770,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<absolute_index> {
|
||||
struct unqualified_pusher<absolute_index> {
|
||||
static int push(lua_State* L, absolute_index ai) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -766,7 +781,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<raw_index> {
|
||||
struct unqualified_pusher<raw_index> {
|
||||
static int push(lua_State* L, raw_index ri) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -777,7 +792,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<ref_index> {
|
||||
struct unqualified_pusher<ref_index> {
|
||||
static int push(lua_State* L, ref_index ri) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
luaL_checkstack(L, 1, detail::not_enough_stack_space_generic);
|
||||
|
@ -788,7 +803,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const wchar_t*> {
|
||||
struct unqualified_pusher<const wchar_t*> {
|
||||
static int push(lua_State* L, const wchar_t* wstr) {
|
||||
return push(L, wstr, std::char_traits<wchar_t>::length(wstr));
|
||||
}
|
||||
|
@ -810,28 +825,28 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<wchar_t*> {
|
||||
struct unqualified_pusher<wchar_t*> {
|
||||
static int push(lua_State* L, const wchar_t* str) {
|
||||
pusher<const wchar_t*> p{};
|
||||
unqualified_pusher<const wchar_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const wchar_t* strb, const wchar_t* stre) {
|
||||
pusher<const wchar_t*> p{};
|
||||
unqualified_pusher<const wchar_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, strb, stre);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const wchar_t* str, std::size_t len) {
|
||||
pusher<const wchar_t*> p{};
|
||||
unqualified_pusher<const wchar_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str, len);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const char16_t*> {
|
||||
struct unqualified_pusher<const char16_t*> {
|
||||
static int convert_into(lua_State* L, char* start, std::size_t, const char16_t* strb, const char16_t* stre) {
|
||||
char* target = start;
|
||||
char32_t cp = 0;
|
||||
|
@ -888,28 +903,28 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char16_t*> {
|
||||
struct unqualified_pusher<char16_t*> {
|
||||
static int push(lua_State* L, const char16_t* str) {
|
||||
pusher<const char16_t*> p{};
|
||||
unqualified_pusher<const char16_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char16_t* strb, const char16_t* stre) {
|
||||
pusher<const char16_t*> p{};
|
||||
unqualified_pusher<const char16_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, strb, stre);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char16_t* str, std::size_t len) {
|
||||
pusher<const char16_t*> p{};
|
||||
unqualified_pusher<const char16_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str, len);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<const char32_t*> {
|
||||
struct unqualified_pusher<const char32_t*> {
|
||||
static int convert_into(lua_State* L, char* start, std::size_t, const char32_t* strb, const char32_t* stre) {
|
||||
char* target = start;
|
||||
char32_t cp = 0;
|
||||
|
@ -965,28 +980,28 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char32_t*> {
|
||||
struct unqualified_pusher<char32_t*> {
|
||||
static int push(lua_State* L, const char32_t* str) {
|
||||
pusher<const char32_t*> p{};
|
||||
unqualified_pusher<const char32_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char32_t* strb, const char32_t* stre) {
|
||||
pusher<const char32_t*> p{};
|
||||
unqualified_pusher<const char32_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, strb, stre);
|
||||
}
|
||||
|
||||
static int push(lua_State* L, const char32_t* str, std::size_t len) {
|
||||
pusher<const char32_t*> p{};
|
||||
unqualified_pusher<const char32_t*> p{};
|
||||
(void)p;
|
||||
return p.push(L, str, len);
|
||||
}
|
||||
};
|
||||
|
||||
template <size_t N>
|
||||
struct pusher<wchar_t[N]> {
|
||||
struct unqualified_pusher<wchar_t[N]> {
|
||||
static int push(lua_State* L, const wchar_t (&str)[N]) {
|
||||
return push(L, str, std::char_traits<wchar_t>::length(str));
|
||||
}
|
||||
|
@ -997,7 +1012,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <size_t N>
|
||||
struct pusher<char16_t[N]> {
|
||||
struct unqualified_pusher<char16_t[N]> {
|
||||
static int push(lua_State* L, const char16_t (&str)[N]) {
|
||||
return push(L, str, std::char_traits<char16_t>::length(str));
|
||||
}
|
||||
|
@ -1008,7 +1023,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <size_t N>
|
||||
struct pusher<char32_t[N]> {
|
||||
struct unqualified_pusher<char32_t[N]> {
|
||||
static int push(lua_State* L, const char32_t (&str)[N]) {
|
||||
return push(L, str, std::char_traits<char32_t>::length(str));
|
||||
}
|
||||
|
@ -1019,7 +1034,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<wchar_t> {
|
||||
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, &str[0], 1);
|
||||
|
@ -1027,7 +1042,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char16_t> {
|
||||
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, &str[0], 1);
|
||||
|
@ -1035,7 +1050,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<char32_t> {
|
||||
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, &str[0], 1);
|
||||
|
@ -1043,7 +1058,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename Ch, typename Traits, typename Al>
|
||||
struct pusher<std::basic_string<Ch, Traits, Al>, std::enable_if_t<!std::is_same<Ch, char>::value>> {
|
||||
struct unqualified_pusher<std::basic_string<Ch, Traits, Al>, std::enable_if_t<!std::is_same<Ch, char>::value>> {
|
||||
static int push(lua_State* L, const std::basic_string<Ch, Traits, Al>& wstr) {
|
||||
return push(L, wstr, wstr.size());
|
||||
}
|
||||
|
@ -1054,7 +1069,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename... Args>
|
||||
struct pusher<std::tuple<Args...>> {
|
||||
struct unqualified_pusher<std::tuple<Args...>> {
|
||||
template <std::size_t... I, typename T>
|
||||
static int push(std::index_sequence<I...>, lua_State* L, T&& t) {
|
||||
#if defined(SOL_SAFE_STACK_CHECK) && SOL_SAFE_STACK_CHECK
|
||||
|
@ -1072,7 +1087,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename A, typename B>
|
||||
struct pusher<std::pair<A, B>> {
|
||||
struct unqualified_pusher<std::pair<A, B>> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& t) {
|
||||
int pushcount = stack::push(L, std::get<0>(std::forward<T>(t)));
|
||||
|
@ -1082,7 +1097,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename O>
|
||||
struct pusher<optional<O>> {
|
||||
struct unqualified_pusher<optional<O>> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& t) {
|
||||
if (t == nullopt) {
|
||||
|
@ -1093,35 +1108,35 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<nullopt_t> {
|
||||
struct unqualified_pusher<nullopt_t> {
|
||||
static int push(lua_State* L, nullopt_t) {
|
||||
return stack::push(L, lua_nil);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<std::nullptr_t> {
|
||||
struct unqualified_pusher<std::nullptr_t> {
|
||||
static int push(lua_State* L, std::nullptr_t) {
|
||||
return stack::push(L, lua_nil);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<this_state> {
|
||||
struct unqualified_pusher<this_state> {
|
||||
static int push(lua_State*, const this_state&) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<this_main_state> {
|
||||
struct unqualified_pusher<this_main_state> {
|
||||
static int push(lua_State*, const this_main_state&) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pusher<new_table> {
|
||||
struct unqualified_pusher<new_table> {
|
||||
static int push(lua_State* L, const new_table& nt) {
|
||||
lua_createtable(L, nt.sequence_hint, nt.map_hint);
|
||||
return 1;
|
||||
|
@ -1130,7 +1145,7 @@ namespace sol {
|
|||
|
||||
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
|
||||
template <typename O>
|
||||
struct pusher<std::optional<O>> {
|
||||
struct unqualified_pusher<std::optional<O>> {
|
||||
template <typename T>
|
||||
static int push(lua_State* L, T&& t) {
|
||||
if (t == std::nullopt) {
|
||||
|
@ -1158,7 +1173,7 @@ namespace sol {
|
|||
} // namespace stack_detail
|
||||
|
||||
template <typename... Tn>
|
||||
struct pusher<std::variant<Tn...>> {
|
||||
struct unqualified_pusher<std::variant<Tn...>> {
|
||||
static int push(lua_State* L, const std::variant<Tn...>& v) {
|
||||
return std::visit(stack_detail::push_function(L), v);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <>
|
||||
struct pusher<lua_thread_state> {
|
||||
struct unqualified_pusher<lua_thread_state> {
|
||||
int push(lua_State*, lua_thread_state lts) {
|
||||
lua_pushthread(lts.L);
|
||||
return 1;
|
||||
|
@ -66,7 +66,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct check_getter<lua_thread_state> {
|
||||
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) );
|
||||
|
|
|
@ -159,7 +159,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <>
|
||||
struct pusher<unsafe_function_result> {
|
||||
struct unqualified_pusher<unsafe_function_result> {
|
||||
static int push(lua_State* L, const unsafe_function_result& fr) {
|
||||
int p = 0;
|
||||
for (int i = 0; i < fr.return_count(); ++i) {
|
||||
|
|
|
@ -372,22 +372,22 @@ namespace sol {
|
|||
} // namespace stack_detail
|
||||
|
||||
template <typename T>
|
||||
struct pusher<as_container_t<T>> {
|
||||
struct unqualified_pusher<as_container_t<T>> {
|
||||
typedef meta::unqualified_t<T> C;
|
||||
|
||||
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 stack::push<detail::as_pointer_tag<const C>>(L, detail::with_function_tag(), 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 stack::push<detail::as_value_tag<C>>(L, detail::with_function_tag(), 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 stack::push<detail::as_value_tag<C>>(L, detail::with_function_tag(), fx, std::move(cont));
|
||||
}
|
||||
|
||||
static int push_rvalue(std::false_type, lua_State* L, const C& cont) {
|
||||
|
@ -404,37 +404,37 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<as_container_t<T*>> {
|
||||
struct unqualified_pusher<as_container_t<T*>> {
|
||||
typedef std::add_pointer_t<meta::unqualified_t<std::remove_pointer_t<T>>> C;
|
||||
|
||||
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 stack::push<detail::as_pointer_tag<T>>(L, detail::with_function_tag(), fx, cont);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T, std::enable_if_t<meta::all<is_container<meta::unqualified_t<T>>, meta::neg<is_lua_reference<meta::unqualified_t<T>>>>::value>> {
|
||||
struct unqualified_pusher<T, std::enable_if_t<meta::all<is_container<meta::unqualified_t<T>>, meta::neg<is_lua_reference<meta::unqualified_t<T>>>>::value>> {
|
||||
typedef meta::unqualified_t<T> C;
|
||||
|
||||
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 stack::push<detail::as_value_tag<T>>(L, detail::with_function_tag(), 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 stack::push<detail::as_value_tag<T>>(L, detail::with_function_tag(), fx, std::move(cont));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pusher<T*, std::enable_if_t<meta::all<is_container<meta::unqualified_t<T>>, meta::neg<is_lua_reference<meta::unqualified_t<T>>>>::value>> {
|
||||
struct unqualified_pusher<T*, std::enable_if_t<meta::all<is_container<meta::unqualified_t<T>>, meta::neg<is_lua_reference<meta::unqualified_t<T>>>>::value>> {
|
||||
typedef std::add_pointer_t<meta::unqualified_t<std::remove_pointer_t<T>>> C;
|
||||
|
||||
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 stack::push<detail::as_pointer_tag<T>>(L, detail::with_function_tag(), fx, cont);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<variadic_args> {
|
||||
struct unqualified_pusher<variadic_args> {
|
||||
static int push(lua_State* L, const variadic_args& ref) {
|
||||
return ref.push(L);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace sol {
|
|||
|
||||
namespace stack {
|
||||
template <>
|
||||
struct pusher<variadic_results> {
|
||||
struct unqualified_pusher<variadic_results> {
|
||||
int push(lua_State* L, const variadic_results& e) {
|
||||
int p = 0;
|
||||
for (const auto& i : e) {
|
||||
|
|
|
@ -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 2018-12-21 06:03:11.681784 UTC
|
||||
// This header was generated with sol v2.20.6 (revision c35c66b)
|
||||
// Generated 2018-12-22 20:32:42.897539 UTC
|
||||
// This header was generated with sol v2.20.6 (revision 88cafb2)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP
|
||||
|
@ -414,6 +414,10 @@ namespace sol {
|
|||
template <typename T>
|
||||
bool weak_derive<T>::value = false;
|
||||
|
||||
namespace stack {
|
||||
struct record;
|
||||
}
|
||||
|
||||
} // namespace sol
|
||||
|
||||
#define SOL_BASE_CLASSES(T, ...) \
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -66,19 +66,11 @@ sol::optional<custom> sol_lua_check_get(sol::types<custom> type_tag, lua_State*
|
|||
|
||||
int sol_lua_push(lua_State* L, const custom& c) {
|
||||
++custom::push_calls;
|
||||
// ensure there's enough space for 1 more thing on the stack
|
||||
lua_checkstack(L, 1);
|
||||
// tell Lua we've left something on
|
||||
// the stack: return what comes from pushing an integer
|
||||
return sol::stack::push(L, c.bweh);
|
||||
}
|
||||
|
||||
int sol_lua_push(sol::types<custom>, lua_State* L, const custom& c) {
|
||||
++custom::exact_push_calls;
|
||||
// ensure there's enough space for 1 more thing on the stack
|
||||
lua_checkstack(L, 1);
|
||||
// tell Lua we've left something on
|
||||
// the stack: return what comes from pushing an integer
|
||||
return sol::stack::push(L, c.bweh);
|
||||
}
|
||||
|
||||
|
@ -118,13 +110,9 @@ bool sol_lua_check(sol::types<multi_custom>, lua_State* L, int index, Handler&&
|
|||
|
||||
int sol_lua_push(lua_State* L, const multi_custom& c) {
|
||||
++multi_custom::push_calls;
|
||||
// ensure there's enough space for 1 more thing on the stack
|
||||
lua_checkstack(L, 3);
|
||||
int p = sol::stack::push(L, c.bweh);
|
||||
p += sol::stack::push(L, c.bwuh);
|
||||
p += sol::stack::push(L, c.blah);
|
||||
// tell Lua we've left something on
|
||||
// the stack: return what comes from pushing an integer
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -136,12 +124,14 @@ struct super_custom {
|
|||
static int check_get_calls;
|
||||
static int push_calls;
|
||||
static int exact_push_calls;
|
||||
static int pointer_push_calls;
|
||||
};
|
||||
|
||||
int super_custom::get_calls = 0;
|
||||
int super_custom::check_calls = 0;
|
||||
int super_custom::check_get_calls = 0;
|
||||
int super_custom::push_calls = 0;
|
||||
int super_custom::pointer_push_calls = 0;
|
||||
int super_custom::exact_push_calls = 0;
|
||||
|
||||
super_custom* sol_lua_get(sol::types<super_custom*>, lua_State* L, int index, sol::stack::record& tracking) {
|
||||
|
@ -169,6 +159,11 @@ bool sol_lua_check(sol::types<super_custom>, lua_State* L, int index, Handler&&
|
|||
return true;
|
||||
}
|
||||
|
||||
template <typename Handler>
|
||||
bool sol_lua_check(sol::types<super_custom*>, lua_State* L, int index, Handler&& handler, sol::stack::record& tracking) {
|
||||
return sol_lua_check(sol::types<super_custom>(), L, index, std::forward<Handler>(handler), tracking);
|
||||
}
|
||||
|
||||
int sol_lua_push(lua_State* L, const super_custom& c) {
|
||||
++super_custom::push_calls;
|
||||
// ensure there's enough space for 1 more thing on the stack
|
||||
|
@ -185,7 +180,7 @@ int sol_lua_push(lua_State* L, const super_custom& c) {
|
|||
}
|
||||
|
||||
int sol_lua_push(lua_State* L, super_custom* c) {
|
||||
++super_custom::push_calls;
|
||||
++super_custom::pointer_push_calls;
|
||||
// ensure there's enough space for 1 more thing on the stack
|
||||
lua_checkstack(L, 1);
|
||||
// tell Lua we've left something on
|
||||
|
@ -197,7 +192,8 @@ int sol_lua_push(lua_State* L, super_custom* c) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int sol_lua_push(lua_State* L, std::reference_wrapper<super_custom> c) {
|
||||
int sol_lua_push(sol::types<std::reference_wrapper<super_custom>>, lua_State* L, std::reference_wrapper<super_custom> c) {
|
||||
++super_custom::exact_push_calls;
|
||||
return sol::stack::push(L, std::addressof(c.get()));
|
||||
}
|
||||
|
||||
|
@ -248,20 +244,26 @@ TEST_CASE("customization/adl", "using the ADL customization points in various si
|
|||
super_custom::check_calls = 0;
|
||||
super_custom::check_get_calls = 0;
|
||||
super_custom::push_calls = 0;
|
||||
super_custom::pointer_push_calls = 0;
|
||||
super_custom::exact_push_calls = 0;
|
||||
|
||||
super_custom meow_original{ 50 };
|
||||
lua["meow"] = std::ref(meow_original);
|
||||
super_custom& meow = lua["meow"];
|
||||
super_custom* p_meow = lua["meow"];
|
||||
std::reference_wrapper<super_custom> ref_meow = lua["meow"];
|
||||
super_custom meow_copy = lua["meow"];
|
||||
|
||||
REQUIRE(meow.bweh == 50);
|
||||
REQUIRE(&meow == &meow_original);
|
||||
REQUIRE(p_meow == &meow_original);
|
||||
REQUIRE(&ref_meow.get() == &meow_original);
|
||||
REQUIRE(meow_copy.bweh == 50);
|
||||
REQUIRE(super_custom::get_calls > 0);
|
||||
REQUIRE(super_custom::check_calls > 0);
|
||||
REQUIRE(super_custom::push_calls > 0);
|
||||
REQUIRE(super_custom::check_get_calls == 0);
|
||||
REQUIRE(super_custom::exact_push_calls == 0);
|
||||
REQUIRE(super_custom::push_calls == 0);
|
||||
REQUIRE(super_custom::pointer_push_calls > 0);
|
||||
REQUIRE(super_custom::exact_push_calls > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,15 @@ struct number_shim {
|
|||
double num = 0;
|
||||
};
|
||||
|
||||
|
||||
// HEY:
|
||||
// Don't do this.
|
||||
// The code below is for sol3 to specialize things,
|
||||
// not for YOU to specialize things.
|
||||
// If you customize things in this fashion,
|
||||
// I will break your code sometime in the future when fixing things.
|
||||
// Do. Not. Use the designated ADL customization points, or file
|
||||
// a bug.
|
||||
namespace sol {
|
||||
|
||||
template <>
|
||||
|
@ -71,7 +80,7 @@ namespace sol {
|
|||
};
|
||||
|
||||
template <>
|
||||
struct pusher<two_things> {
|
||||
struct unqualified_pusher<two_things> {
|
||||
static int push(lua_State* L, const two_things& things) {
|
||||
int amount = stack::push(L, things.a);
|
||||
amount += stack::push(L, things.b);
|
||||
|
@ -108,7 +117,7 @@ namespace sol {
|
|||
} // namespace stack
|
||||
} // namespace sol
|
||||
|
||||
TEST_CASE("customization/split struct", "using the newly documented customization points to handle different kinds of classes") {
|
||||
TEST_CASE("customization/split struct", "using the old customization points to handle different kinds of classes") {
|
||||
sol::state lua;
|
||||
|
||||
// Create a pass-through style of function
|
||||
|
@ -132,7 +141,7 @@ TEST_CASE("customization/split struct", "using the newly documented customizatio
|
|||
REQUIRE(d == 36.5);
|
||||
}
|
||||
|
||||
TEST_CASE("customization/usertype", "using the newly documented customization points to handle different kinds of classes") {
|
||||
TEST_CASE("customization/usertype", "using the old customization points to handle different kinds of classes") {
|
||||
sol::state lua;
|
||||
|
||||
// Create a pass-through style of function
|
||||
|
|
Loading…
Reference in New Issue
Block a user