diff options
author | clyne <clyne@bitgloo.com> | 2022-11-17 07:41:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-17 07:41:09 -0500 |
commit | 6663c25633a27fcc14d0648bd1afea7ea12f497f (patch) | |
tree | dcc2ec993db3c4b75c3e7e3df35b0494a9ce1f32 /lib/sol2/examples/source/functions_empty_arguments.cpp | |
parent | da0913771538fd9b1ca538615fd9aa0388608466 (diff) | |
parent | 57013add5b7c524086272be7d395f9ec5109bde2 (diff) |
Lib cleanup
Diffstat (limited to 'lib/sol2/examples/source/functions_empty_arguments.cpp')
-rw-r--r-- | lib/sol2/examples/source/functions_empty_arguments.cpp | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/lib/sol2/examples/source/functions_empty_arguments.cpp b/lib/sol2/examples/source/functions_empty_arguments.cpp deleted file mode 100644 index 6d93e9b..0000000 --- a/lib/sol2/examples/source/functions_empty_arguments.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1
-#include <sol/sol.hpp>
-
-#include "assert.hpp"
-#include <iostream>
-
-int main(int, char*[]) {
- std::cout << "=== functions empty args ===" << std::endl;
-
- // sol::reference, sol::Stack_reference,
- // sol::object (and main_* types) can all be
- // used to capture "nil", or "none" when a function
- // leaves it off
- auto my_defaulting_function = [](sol::object maybe_defaulted) -> int {
- // if it's nil, it's "unused" or "inactive"
- bool inactive = maybe_defaulted == sol::lua_nil;
- if (inactive) {
- return 0;
- }
- if (maybe_defaulted.is<int>()) {
- int value = maybe_defaulted.as<int>();
- return value;
- }
- return 1;
- };
-
- sol::state lua;
- lua.open_libraries(sol::lib::base);
-
- // copy function in (use std::ref to change this behavior)
- lua.set_function("defaulting_function", my_defaulting_function);
-
- sol::string_view code = R"(
- result = defaulting_function(24)
- result_nothing = defaulting_function()
- result_nil = defaulting_function(nil)
- result_string = defaulting_function('meow')
- print('defaulting_function(24), returned:', result)
- print('defaulting_function(), returned:', result_nothing)
- print('defaulting_function(nil), returned:', result_nil)
- print('defaulting_function(\'meow\'), returned:', result_string)
- assert(result == 24)
- assert(result_nothing == 0)
- assert(result_nil == 0)
- assert(result_string == 1)
- )";
-
- lua.safe_script(code);
-
- std::cout << std::endl;
-
- return 0;
-}
\ No newline at end of file |