aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/examples/source/docs/state_script_safe.cpp
diff options
context:
space:
mode:
authorclyne <clyne@bitgloo.com>2022-11-17 07:41:09 -0500
committerGitHub <noreply@github.com>2022-11-17 07:41:09 -0500
commit6663c25633a27fcc14d0648bd1afea7ea12f497f (patch)
treedcc2ec993db3c4b75c3e7e3df35b0494a9ce1f32 /lib/sol2/examples/source/docs/state_script_safe.cpp
parentda0913771538fd9b1ca538615fd9aa0388608466 (diff)
parent57013add5b7c524086272be7d395f9ec5109bde2 (diff)
Merge pull request #3 from tcsullivan/lib-cleanupHEADmaster
Lib cleanup
Diffstat (limited to 'lib/sol2/examples/source/docs/state_script_safe.cpp')
-rw-r--r--lib/sol2/examples/source/docs/state_script_safe.cpp35
1 files changed, 0 insertions, 35 deletions
diff --git a/lib/sol2/examples/source/docs/state_script_safe.cpp b/lib/sol2/examples/source/docs/state_script_safe.cpp
deleted file mode 100644
index 22defee..0000000
--- a/lib/sol2/examples/source/docs/state_script_safe.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#define SOL_ALL_SAFETIES_ON 1
-#include <sol/sol.hpp>
-
-#include <iostream>
-
-int main () {
-
- std::cout << "=== safe_script usage ===" << std::endl;
-
- sol::state lua;
- // uses sol::script_default_on_error, which either panics or throws,
- // depending on your configuration and compiler settings
- try {
- auto result1 = lua.safe_script("bad.code");
- }
- catch( const sol::error& e ) {
- std::cout << "an expected error has occurred: " << e.what() << std::endl;
- }
-
- // a custom handler that you write yourself
- // is only called when an error happens with loading or running the script
- auto result2 = lua.safe_script("123 bad.code", [](lua_State*, sol::protected_function_result pfr) {
- // pfr will contain things that went wrong, for either loading or executing the script
- // the user can do whatever they like here, including throw. Otherwise...
- sol::error err = pfr;
- std::cout << "An error (an expected one) occurred: " << err.what() << std::endl;
-
- // ... they need to return the protected_function_result
- return pfr;
- });
-
- std::cout << std::endl;
-
- return 0;
-}