summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/sol2/examples/protected_functions.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/sol2/examples/protected_functions.cpp')
-rw-r--r--3rdparty/sol2/examples/protected_functions.cpp47
1 files changed, 0 insertions, 47 deletions
diff --git a/3rdparty/sol2/examples/protected_functions.cpp b/3rdparty/sol2/examples/protected_functions.cpp
deleted file mode 100644
index 340f0134d63..00000000000
--- a/3rdparty/sol2/examples/protected_functions.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <sol.hpp>
-
-#include <iostream>
-
-int main() {
- std::cout << "=== protected_functions example ===" << std::endl;
-
- sol::state lua;
-
- // A complicated function which can error out
- // We define both in terms of Lua code
-
- lua.script(R"(
- function handler (message)
- return "Handled this message: " .. message
- end
-
- function f (a)
- if a < 0 then
- error("negative number detected")
- end
- return a + 5
- end
- )");
-
- // Get a protected function out of Lua
- sol::protected_function f = lua["f"];
- // Set a non-default error handler
- f.error_handler = lua["handler"];
-
- sol::protected_function_result result = f(-500);
- if (result.valid()) {
- // Call succeeded
- int x = result;
- std::cout << "call succeeded, result is " << x << std::endl;
- }
- else {
- // Call failed
- sol::error err = result;
- std::string what = err.what();
- std::cout << "call failed, sol::error::what() is " << what << std::endl;
- // 'what' Should read
- // "Handled this message: negative number detected"
- }
-
- std::cout << std::endl;
-}