MCPcopy Create free account
hub / github.com/ThePhD/sol2 / test_environment

Function test_environment

examples/source/environments.cpp:6–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <iostream>
5
6void 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
33int main(int, char**) {
34 std::cout << "=== environments ===" << std::endl;

Callers 1

mainFunction · 0.85

Calls 1

valueMethod · 0.45

Tested by

no test coverage detected