| 4 | #include <iostream> |
| 5 | |
| 6 | int main() { |
| 7 | |
| 8 | sol::state lua; |
| 9 | |
| 10 | // open those basic lua libraries |
| 11 | // again, for print() and other basic utilities |
| 12 | lua.open_libraries(sol::lib::base); |
| 13 | |
| 14 | // value in the global table |
| 15 | lua["bark"] = 50; |
| 16 | |
| 17 | // a table being created in the global table |
| 18 | lua["some_table"] = lua.create_table_with("key0", |
| 19 | 24, |
| 20 | "key1", |
| 21 | 25, |
| 22 | lua["bark"], |
| 23 | "the key is 50 and this string is its value!"); |
| 24 | |
| 25 | // Run a plain ol' string of lua code |
| 26 | // Note you can interact with things set through sol in C++ |
| 27 | // with lua! Using a "Raw String Literal" to have multi-line |
| 28 | // goodness: |
| 29 | // http://en.cppreference.com/w/cpp/language/string_literal |
| 30 | lua.script(R"( |
| 31 | |
| 32 | print(some_table[50]) |
| 33 | print(some_table["key0"]) |
| 34 | print(some_table["key1"]) |
| 35 | |
| 36 | -- a lua comment: access a global in a lua script with the _G table |
| 37 | print(_G["bark"]) |
| 38 | |
| 39 | )"); |
| 40 | |
| 41 | return 0; |
| 42 | } |
nothing calls this directly
no test coverage detected