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

Function main

examples/source/tutorials/quick_n_dirty/running_lua_code_low_level.cpp:8–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <cstdio>
7
8int 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}

Callers

nothing calls this directly

Calls 5

removeFunction · 0.85
open_librariesMethod · 0.80
load_fileMethod · 0.80
loadMethod · 0.80
validMethod · 0.45

Tested by

no test coverage detected