functions.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <catch.hpp>
  2. #include <luwra.hpp>
  3. TEST_CASE("NativeFunction<R>") {
  4. luwra::StateWrapper state;
  5. REQUIRE(state.runString("return function (x, y) return x + y end") == LUA_OK);
  6. auto fun = luwra::read<luwra::NativeFunction<int>>(state, -1);
  7. REQUIRE(fun(13, 37) == 50);
  8. }
  9. TEST_CASE("NativeFunction<void>") {
  10. luwra::StateWrapper state;
  11. REQUIRE(state.runString("return function (x, y) returnValue = x + y end") == LUA_OK);
  12. auto fun = luwra::read<luwra::NativeFunction<void>>(state, -1);
  13. fun(13, 37);
  14. int returnValue = state.get<int>("returnValue");
  15. REQUIRE(returnValue == 50);
  16. }
  17. TEST_CASE("function<R(A...)>") {
  18. luwra::StateWrapper state;
  19. REQUIRE(state.runString("return function (x, y) return x + y end") == LUA_OK);
  20. auto fun = luwra::read<std::function<int(int, int)>>(state, -1);
  21. REQUIRE(fun(13, 37) == 50);
  22. }
  23. TEST_CASE("function<void(A...)>") {
  24. luwra::StateWrapper state;
  25. REQUIRE(state.runString("return function (x, y) returnValue = x + y end") == LUA_OK);
  26. auto fun = luwra::read<std::function<void(int, int)>>(state, -1);
  27. fun(13, 37);
  28. int returnValue = state.get<int>("returnValue");
  29. REQUIRE(returnValue == 50);
  30. }