| 2 | #include <sol/sol.hpp> |
| 3 | |
| 4 | int main(int, char*[]) { |
| 5 | sol::state lua; |
| 6 | lua.open_libraries(); |
| 7 | sol::environment my_env(lua, sol::create); |
| 8 | // set value, and we need to explicitly allow for |
| 9 | // access to "print", since a new environment hides |
| 10 | // everything that's not defined inside of it |
| 11 | // NOTE: hiding also hides library functions (!!) |
| 12 | // BE WARNED |
| 13 | my_env["var"] = 50; |
| 14 | my_env["print"] = lua["print"]; |
| 15 | |
| 16 | sol::environment my_other_env( |
| 17 | lua, sol::create, lua.globals()); |
| 18 | // do not need to explicitly allow access to "print", |
| 19 | // since we used the "Set a fallback" version |
| 20 | // of the sol::environment constructor |
| 21 | my_other_env["var"] = 443; |
| 22 | |
| 23 | // output: 50 |
| 24 | lua.script("print(var)", my_env); |
| 25 | |
| 26 | // output: 443 |
| 27 | lua.script("print(var)", my_other_env); |
| 28 | |
| 29 | return 0; |
| 30 | } |
nothing calls this directly
no test coverage detected