|
|
@@ -9,102 +9,86 @@ void test_function_noret_noparams() {
|
|
|
noret_environment++;
|
|
|
}
|
|
|
|
|
|
-TEST_CASE("wrap_function_noret_noparams") {
|
|
|
- lua_State* state = luaL_newstate();
|
|
|
-
|
|
|
- // Setup environment
|
|
|
- noret_environment = 1337;
|
|
|
-
|
|
|
- // Wrap function
|
|
|
- // lua_CFunction cfun = luwra::wrap_function<void(), test_function_noret_noparams>;
|
|
|
- lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret_noparams);
|
|
|
- REQUIRE(cfun != nullptr);
|
|
|
-
|
|
|
- // Register function
|
|
|
- luwra::setGlobal(state, "test_function_noret_noparams", cfun);
|
|
|
-
|
|
|
- // Invoke function
|
|
|
- REQUIRE(luaL_dostring(state, "test_function_noret_noparams()") == 0);
|
|
|
- REQUIRE(lua_gettop(state) == 0);
|
|
|
- REQUIRE(noret_environment == 1338);
|
|
|
-
|
|
|
- lua_close(state);
|
|
|
-}
|
|
|
-
|
|
|
static
|
|
|
void test_function_noret(int a, int b) {
|
|
|
noret_environment = a + b;
|
|
|
}
|
|
|
|
|
|
-TEST_CASE("wrap_function_noret") {
|
|
|
- lua_State* state = luaL_newstate();
|
|
|
-
|
|
|
- // Test function beforehand
|
|
|
- test_function_noret(13, 37);
|
|
|
- int req_environemt = noret_environment;
|
|
|
+static
|
|
|
+int test_function_noparams() {
|
|
|
+ return 13 * 37;
|
|
|
+}
|
|
|
|
|
|
- // Wrap function
|
|
|
- // lua_CFunction cfun = luwra::wrap_function<void(int, int), test_function_noret>;
|
|
|
- lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret);
|
|
|
- REQUIRE(cfun != nullptr);
|
|
|
+static
|
|
|
+int test_function(int a, int b) {
|
|
|
+ return (a + b) * (a - b);
|
|
|
+}
|
|
|
|
|
|
- // Register function
|
|
|
- luwra::setGlobal(state, "test_function_noret", cfun);
|
|
|
+TEST_CASE("FunctionWrapper") {
|
|
|
+ luwra::StateWrapper state;
|
|
|
|
|
|
- // Invoke function
|
|
|
- REQUIRE(luaL_dostring(state, "test_function_noret(13, 37)") == 0);
|
|
|
- REQUIRE(lua_gettop(state) == 0);
|
|
|
- REQUIRE(noret_environment == req_environemt);
|
|
|
+ SECTION("without return value, without parameters") {
|
|
|
+ // Setup environment
|
|
|
+ noret_environment = 1337;
|
|
|
|
|
|
- lua_close(state);
|
|
|
-}
|
|
|
+ // Wrap function
|
|
|
+ lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret_noparams);
|
|
|
+ REQUIRE(cfun != nullptr);
|
|
|
|
|
|
-static
|
|
|
-int test_function_noparams() {
|
|
|
- return 13 * 37;
|
|
|
-}
|
|
|
+ // Register function
|
|
|
+ luwra::setGlobal(state, "test_function_noret_noparams", cfun);
|
|
|
|
|
|
-TEST_CASE("wrap_function_noparams") {
|
|
|
- lua_State* state = luaL_newstate();
|
|
|
+ // Invoke function
|
|
|
+ REQUIRE(luaL_dostring(state, "test_function_noret_noparams()") == 0);
|
|
|
+ REQUIRE(lua_gettop(state) == 0);
|
|
|
+ REQUIRE(noret_environment == 1338);
|
|
|
+ }
|
|
|
|
|
|
- // Wrap function
|
|
|
- // lua_CFunction cfun = luwra::wrap_function<int(), test_function_noparams>;
|
|
|
- lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noparams);
|
|
|
- REQUIRE(cfun != nullptr);
|
|
|
+ SECTION("without return value, with parameters") {
|
|
|
+ // Test function beforehand
|
|
|
+ test_function_noret(13, 37);
|
|
|
+ int req_environemt = noret_environment;
|
|
|
|
|
|
- // Register function
|
|
|
- luwra::setGlobal(state, "test_function_noparams", cfun);
|
|
|
+ // Wrap function
|
|
|
+ lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noret);
|
|
|
+ REQUIRE(cfun != nullptr);
|
|
|
|
|
|
- // Invoke function
|
|
|
- REQUIRE(luaL_dostring(state, "return test_function_noparams()") == 0);
|
|
|
- REQUIRE(lua_gettop(state) == 1);
|
|
|
- REQUIRE(luwra::Value<int>::read(state, -1) == test_function_noparams());
|
|
|
+ // Register function
|
|
|
+ luwra::setGlobal(state, "test_function_noret", cfun);
|
|
|
|
|
|
- lua_close(state);
|
|
|
-}
|
|
|
+ // Invoke function
|
|
|
+ REQUIRE(luaL_dostring(state, "test_function_noret(13, 37)") == 0);
|
|
|
+ REQUIRE(lua_gettop(state) == 0);
|
|
|
+ REQUIRE(noret_environment == req_environemt);
|
|
|
+ }
|
|
|
|
|
|
-static
|
|
|
-int test_function(int a, int b) {
|
|
|
- return (a + b) * (a - b);
|
|
|
-}
|
|
|
+ SECTION("with return value, without parameters") {
|
|
|
+ // Wrap function
|
|
|
+ lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function_noparams);
|
|
|
+ REQUIRE(cfun != nullptr);
|
|
|
|
|
|
-TEST_CASE("wrap_function") {
|
|
|
- lua_State* state = luaL_newstate();
|
|
|
+ // Register function
|
|
|
+ luwra::setGlobal(state, "test_function_noparams", cfun);
|
|
|
|
|
|
- // Wrap function
|
|
|
- // lua_CFunction cfun = luwra::wrap_function<int(int, int), test_function>;
|
|
|
- lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function);
|
|
|
- REQUIRE(cfun != nullptr);
|
|
|
+ // Invoke function
|
|
|
+ REQUIRE(luaL_dostring(state, "return test_function_noparams()") == 0);
|
|
|
+ REQUIRE(lua_gettop(state) == 1);
|
|
|
+ REQUIRE(luwra::Value<int>::read(state, -1) == test_function_noparams());
|
|
|
+ }
|
|
|
|
|
|
- // Register function
|
|
|
- luwra::setGlobal(state, "test_function", cfun);
|
|
|
+ SECTION("with return value, with parameters") {
|
|
|
+ // Wrap function
|
|
|
+ lua_CFunction cfun = LUWRA_WRAP_FUNCTION(test_function);
|
|
|
+ REQUIRE(cfun != nullptr);
|
|
|
|
|
|
- // Invoke function
|
|
|
- REQUIRE(luaL_dostring(state, "return test_function(37, 13)") == 0);
|
|
|
- REQUIRE(lua_gettop(state) == 1);
|
|
|
- REQUIRE(luwra::Value<int>::read(state, -1) == test_function(37, 13));
|
|
|
+ // Register function
|
|
|
+ luwra::setGlobal(state, "test_function", cfun);
|
|
|
|
|
|
- lua_close(state);
|
|
|
+ // Invoke function
|
|
|
+ REQUIRE(luaL_dostring(state, "return test_function(37, 13)") == 0);
|
|
|
+ REQUIRE(lua_gettop(state) == 1);
|
|
|
+ REQUIRE(luwra::Value<int>::read(state, -1) == test_function(37, 13));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
TEST_CASE("NativeFunction") {
|