From 459bbcaba0c6d802e2153aca13f6849528c9e735 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 12:42:00 -0500 Subject: [PATCH] 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). --- build.ninja | 2 +- sol.scratch.cpp | 10 ++++++---- sol/function.hpp | 14 +++++++++----- sol/stack.hpp | 6 +----- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/build.ninja b/build.ninja index c6a0c4a9..8693c9ae 100644 --- a/build.ninja +++ b/build.ninja @@ -6,7 +6,7 @@ objdir = obj cxx = g++ 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/" -linkflags = -static liblua.a -L"./lib" +linkflags = -static -L"./lib" -llua rule compile command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags diff --git a/sol.scratch.cpp b/sol.scratch.cpp index 2ee0c5ae..efde5c1f 100644 --- a/sol.scratch.cpp +++ b/sol.scratch.cpp @@ -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")); auto f = lua.get("my_add"); - REQUIRE_NOTHROW(f.call(1, 2, 3)); - REQUIRE_THROWS(f.call(1, 2, "arf")); + int a; + REQUIRE_NOTHROW(a = f.call(1, 2, 3)); + REQUIRE(a == 6); + REQUIRE_THROWS(a = f.call(1, 2, "arf")); } TEST_CASE("simple/callCppFunction", "C++ function is called from lua") { @@ -164,7 +166,7 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") { std::cout << "stateless lambda()" << std::endl; return "test"; } - ); + ); run_script(lua); lua.get("os").set_function("fun", &free_function); @@ -183,7 +185,7 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") { std::cout << "stateless lambda()" << std::endl; return "test"; } - ); + ); run_script(lua); // r-value, cannot optomize diff --git a/sol/function.hpp b/sol/function.hpp index edf44337..49319308 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -29,24 +29,28 @@ namespace sol { class function : virtual public reference { private: + void luacall (std::size_t argcount, std::size_t resultcount) { + lua_call(state(), static_cast(argcount), static_cast(resultcount)); + } + template std::tuple invoke(types, std::size_t n) { - lua_pcall(state(), static_cast(n), sizeof...(Ret), 0); - return stack::pop_call(state(), std::make_tuple, types()); + luacall(n, sizeof...(Ret)); + return stack::pop_call(state(), std::make_tuple, types()); } template Ret invoke(types, std::size_t n) { - lua_pcall(state(), static_cast(n), 1, 0); + luacall(n, 1); return stack::pop(state()); } void invoke(types, std::size_t n) { - lua_pcall(state(), static_cast(n), 0, 0); + luacall(n, 0); } void invoke(types<>, std::size_t n) { - lua_pcall(state(), static_cast(n), 0, 0); + luacall(n, 0); } public: diff --git a/sol/stack.hpp b/sol/stack.hpp index ce8be78e..b301072a 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -222,16 +222,12 @@ template auto ltr_pop(lua_State*, F&& f, types<>, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { return f(std::forward(vs)...); } -template -auto ltr_pop(lua_State*, F&& f, types, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { - return f(std::forward(vs)...); -} template auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(ltr_pop(L, std::forward(f), types<>(), std::forward(vs)..., pop(L))) { return ltr_pop(L, std::forward(f), types<>(), std::forward(vs)..., pop(L)); } template -auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(ltr_pop(L, std::forward(f), types(), std::forward(vs)..., pop(L))) { +auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(f(std::forward(vs)..., std::declval(), std::declval()...)) { return ltr_pop(L, std::forward(f), types(), std::forward(vs)..., pop(L)); } } // detail