mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Have I mentioned I hate GCC? I hate GCC.
This commit is contained in:
parent
350f430d74
commit
bcf4b9b08f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -17,3 +17,4 @@ x64/
|
||||||
liblua.a
|
liblua.a
|
||||||
sol/include/
|
sol/include/
|
||||||
.ninja*
|
.ninja*
|
||||||
|
include/
|
||||||
|
|
|
@ -50,7 +50,7 @@ TEST_CASE("simple/get", "Tests if the get function works properly.") {
|
||||||
REQUIRE(a == 9.0);
|
REQUIRE(a == 9.0);
|
||||||
|
|
||||||
lua.script("b = nil");
|
lua.script("b = nil");
|
||||||
REQUIRE_NOTHROW(auto b = lua.get<sol::nil_t>("b"));
|
REQUIRE_NOTHROW(lua.get<sol::nil_t>("b"));
|
||||||
|
|
||||||
lua.script("d = 'hello'");
|
lua.script("d = 'hello'");
|
||||||
auto d = lua.get<std::string>("d");
|
auto d = lua.get<std::string>("d");
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
// 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.
|
||||||
|
|
||||||
#include "tuple.hpp"
|
|
||||||
|
|
||||||
#ifndef SOL_FUNCTIONAL_HPP
|
#ifndef SOL_FUNCTIONAL_HPP
|
||||||
#define SOL_FUNCTIONAL_HPP
|
#define SOL_FUNCTIONAL_HPP
|
||||||
|
|
||||||
|
#include "tuple.hpp"
|
||||||
|
|
||||||
namespace sol {
|
namespace sol {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct static_lua_func {
|
||||||
static int call(lua_State* L) {
|
static int call(lua_State* L) {
|
||||||
int upvalue = 1;
|
int upvalue = 1;
|
||||||
fx_t* fx;
|
fx_t* fx;
|
||||||
detail::get_upvalue(L, fx, upvalue);
|
detail::get_upvalue(L, fx, upvalue);
|
||||||
int r = typed_call(tuple_types<typename fx_traits::return_type>(), typename fx_traits::args_type(), fx, L);
|
int r = typed_call(tuple_types<typename fx_traits::return_type>(), typename fx_traits::args_type(), fx, L);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ struct static_object_lua_func {
|
||||||
static int typed_call(types<TR>, types<Args...>, T& item, fx_t& ifx, lua_State* L) {
|
static int typed_call(types<TR>, types<Args...>, T& item, fx_t& ifx, lua_State* L) {
|
||||||
auto fx = [ &item, &ifx ] (Args&&... args) -> TR {
|
auto fx = [ &item, &ifx ] (Args&&... args) -> TR {
|
||||||
return (item.*ifx)(std::forward<Args>(args)...);
|
return (item.*ifx)(std::forward<Args>(args)...);
|
||||||
};
|
};
|
||||||
auto r = stack::pop_call(L, fx, types<Args...>());
|
auto r = stack::pop_call(L, fx, types<Args...>());
|
||||||
stack::push(L, std::move(r));
|
stack::push(L, std::move(r));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -121,7 +121,7 @@ struct static_object_lua_func {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int call(lua_State* L) {
|
static int call(lua_State* L) {
|
||||||
const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*);
|
const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*);
|
||||||
typedef std::array<void*, data_t_count> data_t;
|
typedef std::array<void*, data_t_count> data_t;
|
||||||
int upvalue = 1;
|
int upvalue = 1;
|
||||||
data_t data = { { } };
|
data_t data = { { } };
|
||||||
|
|
|
@ -60,11 +60,6 @@ inline T get_arithmetic(lua_State* L, std::true_type, int index = -1) {
|
||||||
return get_unsigned<T>(L, std::is_unsigned<T>{}, index);
|
return get_unsigned<T>(L, std::is_unsigned<T>{}, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
inline T get_helper(lua_State* L, std::true_type, int index = -1) {
|
|
||||||
return get_nil<T>(L, std::is_same<nil_t, T>(), index);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T get_nil(lua_State* L, std::true_type, int index = -1) {
|
inline T get_nil(lua_State* L, std::true_type, int index = -1) {
|
||||||
if (lua_isnil(L, index) == 0)
|
if (lua_isnil(L, index) == 0)
|
||||||
|
@ -78,6 +73,11 @@ inline T get_nil(lua_State* L, std::false_type, int index = -1) {
|
||||||
return T(L, index);
|
return T(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T get_helper(lua_State* L, std::true_type, int index = -1) {
|
||||||
|
return get_nil<T>(L, std::is_same<nil_t, T>(), index);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T get_helper(lua_State* L, std::false_type, int index = -1) {
|
inline T get_helper(lua_State* L, std::false_type, int index = -1) {
|
||||||
// T is a fundamental type
|
// T is a fundamental type
|
||||||
|
@ -222,6 +222,10 @@ template<typename F, typename... Vs>
|
||||||
auto ltr_pop(lua_State*, F&& f, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
|
auto ltr_pop(lua_State*, F&& f, types<>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
|
||||||
return f(std::forward<Vs>(vs)...);
|
return f(std::forward<Vs>(vs)...);
|
||||||
}
|
}
|
||||||
|
template<typename F, typename... Vs>
|
||||||
|
auto ltr_pop(lua_State*, F&& f, types<void>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)...)) {
|
||||||
|
return f(std::forward<Vs>(vs)...);
|
||||||
|
}
|
||||||
template<typename F, typename Head, typename... Vs>
|
template<typename F, typename Head, typename... Vs>
|
||||||
auto ltr_pop(lua_State* L, F&& f, types<Head>, Vs&&... vs) -> decltype(ltr_pop(L, std::forward<F>(f), types<>(), std::forward<Vs>(vs)..., pop<Head>(L))) {
|
auto ltr_pop(lua_State* L, F&& f, types<Head>, Vs&&... vs) -> decltype(ltr_pop(L, std::forward<F>(f), types<>(), std::forward<Vs>(vs)..., pop<Head>(L))) {
|
||||||
return ltr_pop(L, std::forward<F>(f), types<>(), std::forward<Vs>(vs)..., pop<Head>(L));
|
return ltr_pop(L, std::forward<F>(f), types<>(), std::forward<Vs>(vs)..., pop<Head>(L));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user