| 4 | #include <iostream> |
| 5 | |
| 6 | void test_environment(std::string key, |
| 7 | const sol::environment& env, const sol::state_view& lua) { |
| 8 | sol::optional<int> maybe_env_a = env[key]; |
| 9 | sol::optional<int> maybe_global_a = lua[key]; |
| 10 | if (maybe_global_a) { |
| 11 | std::cout << "\t'" << key << "' is " |
| 12 | << maybe_global_a.value() |
| 13 | << " in the global environment" << std::endl; |
| 14 | } |
| 15 | else { |
| 16 | std::cout |
| 17 | << "\t'" << key |
| 18 | << "' does not exist in the global environment" |
| 19 | << std::endl; |
| 20 | } |
| 21 | if (maybe_env_a) { |
| 22 | std::cout << "\t'" << key << "' is " |
| 23 | << maybe_env_a.value() |
| 24 | << " in target environment" << std::endl; |
| 25 | } |
| 26 | else { |
| 27 | std::cout << "\t'" << key |
| 28 | << "' does not exist in target environment" |
| 29 | << std::endl; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | int main(int, char**) { |
| 34 | std::cout << "=== environments ===" << std::endl; |