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:
ThePhD 2013-12-11 12:42:00 -05:00
parent bcf4b9b08f
commit 459bbcaba0
4 changed files with 17 additions and 15 deletions

View File

@ -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

View File

@ -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") {
@ -164,7 +166,7 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") {
std::cout << "stateless lambda()" << std::endl; std::cout << "stateless lambda()" << std::endl;
return "test"; return "test";
} }
); );
run_script(lua); run_script(lua);
lua.get<sol::table>("os").set_function("fun", &free_function); lua.get<sol::table>("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; std::cout << "stateless lambda()" << std::endl;
return "test"; return "test";
} }
); );
run_script(lua); run_script(lua);
// r-value, cannot optomize // r-value, cannot optomize

View File

@ -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:

View File

@ -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