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

Function main

examples/customization/source/main.cpp:9–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <iostream>
8
9int main(int, char*[]) {
10 std::cout << "=== customization: vec3 as table ==="
11 << std::endl;
12
13 sol::state lua;
14 lua.open_libraries(sol::lib::base);
15
16 std::cout << "registering entities into Lua ..."
17 << std::endl;
18 register_lua(lua);
19 std::cout << "running script ..." << std::endl;
20
21 const auto& script = R"lua(
22local e = entity.new()
23local pos = e.position
24print("pos type", type(pos))
25print("pos", pos.x, pos.y, pos.z)
26e.position = { x = 52, y = 5.5, z = 47.5 }
27local new_pos = e.position
28print("pos", pos.x, pos.y, pos.z)
29print("new_pos", new_pos.x, new_pos.y, new_pos.z)
30)lua";
31
32 sol::optional<sol::error> result = lua.safe_script(script);
33 if (result.has_value()) {
34 std::cerr << "Something went horribly wrong: "
35 << result.value().what() << std::endl;
36 }
37
38 std::cout << "finishing ..." << std::endl;
39
40 std::cout << std::endl;
41 return 0;
42}

Callers

nothing calls this directly

Calls 6

register_luaFunction · 0.85
open_librariesMethod · 0.80
safe_scriptMethod · 0.80
whatMethod · 0.80
has_valueMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected