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

Function main

examples/source/lua_value.cpp:25–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23};
24
25int main(int, char*[]) {
26
27 std::cout << "=== sol::lua_value/sol::array_value ==="
28 << std::endl;
29
30 sol::state lua;
31 lua.open_libraries(sol::lib::base, sol::lib::io);
32
33 sol::lua_value lv_int(lua, 56);
34 sol::lua_value lv_int_table(lua, { 1, 2, 3, 4, 5 });
35 sol::lua_value lv_map(lua,
36 { { "bark bark", "meow hiss!" },
37 { 3, 4 },
38 { ":D", 6 } });
39 sol::lua_value lv_mixed_table(lua,
40 sol::array_value {
41 1, int_entry(2), 3, int_entry(4), 5 });
42 sol::lua_value lv_mixed_nested_table(lua,
43 sol::array_value { 1,
44 int_entry(2),
45 3,
46 int_entry(4),
47 sol::array_value { 5, 6, int_entry(7), "8" } });
48
49 const auto& code = R"(
50 function real_print_recursive (e, level)
51 local et = type(e)
52 if et == 'table' then
53 io.write("{ ")
54 local iters = 0
55 for k, v in pairs(e) do
56 if iters ~= 0 then
57 io.write(", ")
58 end
59 real_print_recursive(k, level + 1)
60 io.write(": ")
61 real_print_recursive(v, level + 1)
62 iters = iters + 1
63 end
64 io.write(" }")
65 elseif et == 'string' then
66 io.write('"')
67 io.write(e)
68 io.write('"')
69 else
70 io.write(tostring(e))
71 end
72 if level == 0 then
73 io.write("\n")
74 end
75 end
76
77 function print_recursive (e)
78 real_print_recursive(e, 0)
79 end
80 )";
81
82 sol::optional<sol::error> maybe_error

Callers

nothing calls this directly

Calls 4

open_librariesMethod · 0.80
safe_scriptMethod · 0.80
whatMethod · 0.80
int_entryClass · 0.70

Tested by

no test coverage detected