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

Function main

examples/source/calling_lua_functions.cpp:28–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28int main(int, char*[]) {
29 std::cout << "=== calling lua functions ===" << std::endl;
30
31 sol::state lua;
32 lua.open_libraries();
33
34 sol::table mLuaPackets
35 = lua.create_named_table("mLuaPackets");
36 mLuaPackets[1] = lua.create_table_with("timestamp", 0LL);
37 mLuaPackets[2] = lua.create_table_with("timestamp", 3LL);
38 mLuaPackets[3] = lua.create_table_with("timestamp", 1LL);
39
40 lua.script("print('--- pre sort ---')");
41 lua.script(
42 "for i=1,#mLuaPackets do print(i, "
43 "mLuaPackets[i].timestamp) end");
44
45 lua["table"]["sort"](mLuaPackets,
46 sol::as_function([](sol::table l, sol::table r) {
47 std::uint64_t tl = l["timestamp"];
48 std::uint64_t tr = r["timestamp"];
49 return tl < tr;
50 }));
51
52 lua.script("print('--- post sort ---')");
53 lua.script(
54 "for i=1,#mLuaPackets do print(i, "
55 "mLuaPackets[i].timestamp) end");
56
57 return 0;
58}

Callers

nothing calls this directly

Calls 5

as_functionFunction · 0.85
open_librariesMethod · 0.80
create_named_tableMethod · 0.80
create_table_withMethod · 0.80
scriptMethod · 0.80

Tested by

no test coverage detected