-
-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💚 Some stuff to make the CI builds a bit better
- Thanks, blobthing & zasz!
- Loading branch information
Showing
28 changed files
with
285 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,30 @@ | ||
#include <sol/sol.hpp> | ||
// sol2 | ||
|
||
// The MIT License (MIT) | ||
|
||
#include <iostream> | ||
// Copyright (c) 2013-2021 Rapptz, ThePhD and contributors | ||
|
||
inline constexpr int magic_value = 24; | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
|
||
using zero_arg_type = int (*)(); | ||
using one_arg_type = int (*)(int); | ||
using callback_type = int (*)(one_arg_type); | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
|
||
int free_function(int value) { | ||
return value + 1; | ||
} | ||
|
||
int callback(one_arg_type f) { | ||
return f(magic_value) + 1; | ||
} | ||
|
||
int main() { | ||
constexpr int expected_value = magic_value; | ||
constexpr int expected_free_function_value = magic_value + 1; | ||
constexpr int expected_callback_value = magic_value + 1 + 1; | ||
|
||
sol::state lua; | ||
lua.open_libraries(sol::lib::base); | ||
|
||
auto lambda = []() { return magic_value; }; | ||
auto lambda_ptr = static_cast<zero_arg_type>(lambda); | ||
|
||
lua["magic_value"] = magic_value; | ||
lua["expected_value"] = expected_value; | ||
lua["expected_free_function_value"] = expected_free_function_value; | ||
lua["expected_callback_value"] = expected_callback_value; | ||
|
||
lua["lambda"] = sol::as_function_reference(lambda); | ||
lua["lambda_ptr"] = lambda_ptr; | ||
lua["free_function"] = &free_function; | ||
lua["callback"] = &callback; | ||
|
||
zero_arg_type lambda_f = lua["lambda"]; | ||
zero_arg_type lambda_ptr_f = lua["lambda_ptr"]; | ||
one_arg_type free_function_f = lua["free_function"]; | ||
callback_type callback_f = lua["callback"]; | ||
sol::function lua_callback_f = lua["callback"]; | ||
|
||
int lambda_f_result = lambda_f(); | ||
int lambda_ptr_f_result = lambda_ptr_f(); | ||
int free_function_f_result = free_function_f(magic_value); | ||
int callback_f_result = callback_f(&free_function); | ||
int lua_callback_f_result = lua_callback_f(&free_function); | ||
sol_c_assert(lambda_f_result == expected_value); | ||
sol_c_assert(lambda_ptr_f_result == expected_value); | ||
sol_c_assert(free_function_f_result == expected_free_function_value); | ||
sol_c_assert(callback_f_result == expected_callback_value); | ||
sol_c_assert(lua_callback_f_result == expected_callback_value); | ||
|
||
const char code[] = R"( | ||
assert(lambda() == expected_value) | ||
assert(lambda_ptr() == expected_value) | ||
assert(free_function(magic_value) == expected_free_function_value) | ||
assert(callback(free_function) == expected_callback_value) | ||
)"; | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
sol::optional<sol::error> err = lua.safe_script(code, sol::script_pass_on_error); | ||
if (err.has_value()) { | ||
std::cerr << err.value().what() << std::endl; | ||
return 1; | ||
} | ||
sol_c_assert(!err.has_value()); | ||
#define CATCH_CONFIG_RUNNER | ||
#include <catch2/catch.hpp> | ||
|
||
return 0; | ||
int main(int argc, char* argv[]) { | ||
int result = Catch::Session().run(argc, argv); | ||
return result; | ||
} |
Oops, something went wrong.