functions.cpp 607 B

1234567891011121314151617181920212223
  1. #include <catch.hpp>
  2. #include <luwra.hpp>
  3. TEST_CASE("NativeFunction") {
  4. luwra::StateWrapper state;
  5. SECTION("with return value") {
  6. REQUIRE(state.runString("return function (x, y) return x + y end") == LUA_OK);
  7. auto fun = luwra::read<luwra::NativeFunction<int>>(state, -1);
  8. REQUIRE(fun(13, 37) == 50);
  9. }
  10. SECTION("without return value") {
  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. }