diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-19 19:48:10 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-19 19:48:10 -0400 |
commit | c467671ae8b6ec161c17e86f3383fd0625f755b8 (patch) | |
tree | fd126d5721256b15c0d71e4c47033e341bdb7816 /lib/sol2/examples/source/environments.cpp | |
parent | da0913771538fd9b1ca538615fd9aa0388608466 (diff) |
remove sol2 (will re-add as submodule)
Diffstat (limited to 'lib/sol2/examples/source/environments.cpp')
-rw-r--r-- | lib/sol2/examples/source/environments.cpp | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/lib/sol2/examples/source/environments.cpp b/lib/sol2/examples/source/environments.cpp deleted file mode 100644 index 0087dea..0000000 --- a/lib/sol2/examples/source/environments.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include <sol/sol.hpp> - -#include <iostream> - -void test_environment(std::string key, const sol::environment& env, const sol::state_view& lua) { - sol::optional<int> maybe_env_a = env[key]; - sol::optional<int> maybe_global_a = lua[key]; - if (maybe_global_a) { - std::cout << "\t'" << key << "' is " << maybe_global_a.value() << " in the global environment" << std::endl; - } - else { - std::cout << "\t'" << key << "' does not exist in the global environment" << std::endl; - } - if (maybe_env_a) { - std::cout << "\t'" << key << "' is " << maybe_env_a.value() << " in target environment" << std::endl; - } - else { - std::cout << "\t'" << key << "' does not exist in target environment" << std::endl; - } -} - -int main(int, char**) { - std::cout << "=== environments ===" << std::endl; - - sol::state lua; - // A global variable to see if we can "fallback" into it - lua["b"] = 2142; - - // Create a new environment - sol::environment plain_env(lua, sol::create); - // Use it - lua.script("a = 24", plain_env); - std::cout << "-- target: plain_env" << std::endl; - test_environment("a", plain_env, lua); - test_environment("b", plain_env, lua); - std::cout << std::endl; - - // Create an environment with a fallback - sol::environment env_with_fallback(lua, sol::create, lua.globals()); - // Use it - lua.script("a = 56", env_with_fallback); - std::cout << "-- target: env_with_fallback (fallback is global table)" << std::endl; - test_environment("a", env_with_fallback, lua); - test_environment("b", env_with_fallback, lua); - std::cout << std::endl; - - - return 0; -} |