diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-08-30 00:19:31 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-08-30 00:19:31 -0400 |
commit | bd3fe0cac583739bc0d7c4b5c8f301bb350abca0 (patch) | |
tree | 7eeb1aabcebd6999de1c3457d0882246ec0ff4d4 /lib/sol2/examples/source/containers_as_table.cpp | |
parent | 2662ac356ce14dacfbc91689fd37244facff4989 (diff) |
Renamed lib to deps so github will ignore it for language stats
Diffstat (limited to 'lib/sol2/examples/source/containers_as_table.cpp')
-rw-r--r-- | lib/sol2/examples/source/containers_as_table.cpp | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/lib/sol2/examples/source/containers_as_table.cpp b/lib/sol2/examples/source/containers_as_table.cpp deleted file mode 100644 index 5a0ce02..0000000 --- a/lib/sol2/examples/source/containers_as_table.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include <sol/sol.hpp> - -#include <vector> -#include <map> -#include "assert.hpp" -#include <iostream> - - -// nested allows serialization of maps with vectors inside, and vice-versa -// all from a nested structure of Lua tables -// it has less control over which pieces are considered tables in Lua, -// and which ones are considered userdata, but it covers a good 90% of cases -// where someone wants to handle a nested table -void demo(sol::nested<std::map<std::string, std::vector<std::string>>> src) { - std::cout << "demo, sol::nested<...>" << std::endl; - const auto& listmap = src.value(); - c_assert(listmap.size() == 2); - for (const auto& kvp : listmap) { - const std::vector<std::string>& strings = kvp.second; - c_assert(strings.size() == 3); - std::cout << "\t" << kvp.first << " = "; - for (const auto& s : strings) { - std::cout << "'" << s << "'" << " "; - } - std::cout << std::endl; - } - std::cout << std::endl; -} - -// This second demo is equivalent to the first -// Nota bene the signature here -// Every container-type that's meant to be -// a table must be wrapped in `sol::as_table_t` -// it's verbose, so feel free to use typedefs to make it easy on you -// you can mix which parts are considered tables from Lua, and which parts -// are considered other kinds of types, such as userdata and the like -void demo_explicit (sol::as_table_t<std::map<std::string, sol::as_table_t<std::vector<std::string>>>> src) { - std::cout << "demo, explicit sol::as_table_t<...>" << std::endl; - // Have to access the "source" member variable for as_table_t - const auto& listmap = src.value(); - c_assert(listmap.size() == 2); - for (const auto& kvp : listmap) { - // Have to access the internal "source" for the inner as_table_t, as well - const std::vector<std::string>& strings = kvp.second.value(); - c_assert(strings.size() == 3); - std::cout << "\t" << kvp.first << " = "; - for (const auto& s : strings) { - std::cout << "'" << s << "'" << " "; - } - std::cout << std::endl; - } - std::cout << std::endl; -} - -int main(int, char**) { - std::cout << "=== containers retrieved from lua tables ===" << std::endl; - - sol::state lua; - // bind the function - lua.set_function("f", &demo); - lua.set_function("g", &demo_explicit); - // Call it with a table that has string sequences set to distinct keys - lua.script(R"( -t = { - key1 = {'hello', 'there', 'world'}, - key2 = {'bark', 'borf', 'woof'} -} -f(t) -g(t) - )"); - - std::cout << std::endl; - - return 0; -}
\ No newline at end of file |