| 6 | #include <cstdio> |
| 7 | |
| 8 | int main(int, char*[]) { |
| 9 | std::cout << "=== running lua code (low level) ===" |
| 10 | << std::endl; |
| 11 | |
| 12 | { |
| 13 | std::ofstream out("a_lua_script.lua"); |
| 14 | out << "print('hi from a lua script file')"; |
| 15 | } |
| 16 | |
| 17 | sol::state lua; |
| 18 | lua.open_libraries(sol::lib::base); |
| 19 | |
| 20 | // load file without execute |
| 21 | sol::load_result script1 |
| 22 | = lua.load_file("a_lua_script.lua"); |
| 23 | // execute |
| 24 | script1(); |
| 25 | |
| 26 | // load string without execute |
| 27 | sol::load_result script2 = lua.load("a = 'test'"); |
| 28 | // execute |
| 29 | sol::protected_function_result script2result = script2(); |
| 30 | // optionally, check if it worked |
| 31 | if (script2result.valid()) { |
| 32 | // yay! |
| 33 | } |
| 34 | else { |
| 35 | // aww |
| 36 | } |
| 37 | |
| 38 | sol::load_result script3 = lua.load("return 24"); |
| 39 | // execute, get return value |
| 40 | int value2 = script3(); |
| 41 | SOL_ASSERT(value2 == 24); |
| 42 | |
| 43 | std::cout << std::endl; |
| 44 | |
| 45 | { std::remove("a_lua_script.lua"); } |
| 46 | |
| 47 | return 0; |
| 48 | } |
nothing calls this directly
no test coverage detected