| 4 | #include <iostream> |
| 5 | |
| 6 | int main() { |
| 7 | std::cout << "=== variables ===" << std::endl; |
| 8 | |
| 9 | sol::state lua; |
| 10 | |
| 11 | // need the base library for assertions |
| 12 | lua.open_libraries(sol::lib::base); |
| 13 | |
| 14 | // basic setting of a variable |
| 15 | // through multiple ways |
| 16 | lua["x"] = 10; |
| 17 | lua.set("y", "hello"); |
| 18 | |
| 19 | // assert values are as given |
| 20 | lua.script("assert(x == 10)"); |
| 21 | lua.script("assert(y == 'hello')"); |
| 22 | |
| 23 | |
| 24 | // basic retrieval of a variable |
| 25 | // through multiple ways |
| 26 | int x = lua["x"]; |
| 27 | auto y = lua.get<std::string>("y"); |
| 28 | |
| 29 | int x2; |
| 30 | std::string y2; |
| 31 | std::tie(x2, y2) = lua.get<int, std::string>("x", "y"); |
| 32 | |
| 33 | // show the values |
| 34 | std::cout << x << std::endl; |
| 35 | std::cout << y << std::endl; |
| 36 | std::cout << x2 << std::endl; |
| 37 | std::cout << y2 << std::endl; |
| 38 | std::cout << std::endl; |
| 39 | } |
nothing calls this directly
no test coverage detected