mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
GCC is lame. But at least it's building now. Fixed up the build.ninja and made all tests pass (exceptions weren't being thrown because of lua_pcall
: use lua_call
to let exceptions propogate naturally).
This commit is contained in:
parent
bcf4b9b08f
commit
459bbcaba0
|
@ -6,7 +6,7 @@ objdir = obj
|
||||||
cxx = g++
|
cxx = g++
|
||||||
cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG
|
cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG
|
||||||
incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/"
|
incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/"
|
||||||
linkflags = -static liblua.a -L"./lib"
|
linkflags = -static -L"./lib" -llua
|
||||||
|
|
||||||
rule compile
|
rule compile
|
||||||
command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags
|
command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags
|
||||||
|
|
|
@ -97,8 +97,10 @@ TEST_CASE("simple/callWithParameters", "Lua function is called with a few parame
|
||||||
|
|
||||||
REQUIRE_NOTHROW(lua.script("function my_add(i, j, k) return i + j + k end"));
|
REQUIRE_NOTHROW(lua.script("function my_add(i, j, k) return i + j + k end"));
|
||||||
auto f = lua.get<sol::function>("my_add");
|
auto f = lua.get<sol::function>("my_add");
|
||||||
REQUIRE_NOTHROW(f.call<int>(1, 2, 3));
|
int a;
|
||||||
REQUIRE_THROWS(f.call<int>(1, 2, "arf"));
|
REQUIRE_NOTHROW(a = f.call<int>(1, 2, 3));
|
||||||
|
REQUIRE(a == 6);
|
||||||
|
REQUIRE_THROWS(a = f.call<int>(1, 2, "arf"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("simple/callCppFunction", "C++ function is called from lua") {
|
TEST_CASE("simple/callCppFunction", "C++ function is called from lua") {
|
||||||
|
|
|
@ -29,24 +29,28 @@
|
||||||
namespace sol {
|
namespace sol {
|
||||||
class function : virtual public reference {
|
class function : virtual public reference {
|
||||||
private:
|
private:
|
||||||
|
void luacall (std::size_t argcount, std::size_t resultcount) {
|
||||||
|
lua_call(state(), static_cast<uint32_t>(argcount), static_cast<uint32_t>(resultcount));
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Ret>
|
template<typename... Ret>
|
||||||
std::tuple<Ret...> invoke(types<Ret...>, std::size_t n) {
|
std::tuple<Ret...> invoke(types<Ret...>, std::size_t n) {
|
||||||
lua_pcall(state(), static_cast<int>(n), sizeof...(Ret), 0);
|
luacall(n, sizeof...(Ret));
|
||||||
return stack::pop_call(state(), std::make_tuple<Ret...>, types<Ret...>());
|
return stack::pop_call(state(), std::make_tuple<Ret...>, types<Ret...>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
Ret invoke(types<Ret>, std::size_t n) {
|
Ret invoke(types<Ret>, std::size_t n) {
|
||||||
lua_pcall(state(), static_cast<int>(n), 1, 0);
|
luacall(n, 1);
|
||||||
return stack::pop<Ret>(state());
|
return stack::pop<Ret>(state());
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke(types<void>, std::size_t n) {
|
void invoke(types<void>, std::size_t n) {
|
||||||
lua_pcall(state(), static_cast<uint32_t>(n), 0, 0);
|
luacall(n, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void invoke(types<>, std::size_t n) {
|
void invoke(types<>, std::size_t n) {
|
||||||
lua_pcall(state(), static_cast<uint32_t>(n), 0, 0);
|
luacall(n, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -222,16 +222,12 @@ 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));
|
||||||
}
|
}
|
||||||
template<typename F, typename Head, typename... Tail, typename... Vs>
|
template<typename F, typename Head, typename... Tail, typename... Vs>
|
||||||
auto ltr_pop(lua_State* L, F&& f, types<Head, Tail...>, Vs&&... vs) -> decltype(ltr_pop(L, std::forward<F>(f), types<Tail...>(), std::forward<Vs>(vs)..., pop<Head>(L))) {
|
auto ltr_pop(lua_State* L, F&& f, types<Head, Tail...>, Vs&&... vs) -> decltype(f(std::forward<Vs>(vs)..., std::declval<Head>(), std::declval<Tail>()...)) {
|
||||||
return ltr_pop(L, std::forward<F>(f), types<Tail...>(), std::forward<Vs>(vs)..., pop<Head>(L));
|
return ltr_pop(L, std::forward<F>(f), types<Tail...>(), std::forward<Vs>(vs)..., pop<Head>(L));
|
||||||
}
|
}
|
||||||
} // detail
|
} // detail
|
||||||
|
|
Loading…
Reference in New Issue
Block a user