aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/examples/source/table_proxy.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-08-19 19:48:10 -0400
committerClyne Sullivan <clyne@bitgloo.com>2022-08-19 19:48:10 -0400
commitc467671ae8b6ec161c17e86f3383fd0625f755b8 (patch)
treefd126d5721256b15c0d71e4c47033e341bdb7816 /lib/sol2/examples/source/table_proxy.cpp
parentda0913771538fd9b1ca538615fd9aa0388608466 (diff)
remove sol2 (will re-add as submodule)
Diffstat (limited to 'lib/sol2/examples/source/table_proxy.cpp')
-rw-r--r--lib/sol2/examples/source/table_proxy.cpp55
1 files changed, 0 insertions, 55 deletions
diff --git a/lib/sol2/examples/source/table_proxy.cpp b/lib/sol2/examples/source/table_proxy.cpp
deleted file mode 100644
index 899143a..0000000
--- a/lib/sol2/examples/source/table_proxy.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#define SOL_ALL_SAFETIES_ON 1
-#include <sol/sol.hpp>
-
-#include "assert.hpp"
-
-#include <iostream>
-
-int main () {
-
- const auto& code = R"(
- bark = {
- woof = {
- [2] = "arf!"
- }
- }
- )";
-
- sol::state lua;
- lua.open_libraries(sol::lib::base);
- lua.script(code);
-
- // produces proxy, implicitly converts to std::string, quietly destroys proxy
- std::string arf_string = lua["bark"]["woof"][2];
-
- // lazy-evaluation of tables
- auto x = lua["bark"];
- auto y = x["woof"];
- auto z = y[2];
-
- // retrivies value inside of lua table above
- std::string value = z;
- c_assert(value == "arf!");
-
- // Can change the value later...
- z = 20;
-
- // Yay, lazy-evaluation!
- int changed_value = z; // now it's 20!
- c_assert(changed_value == 20);
- lua.script("assert(bark.woof[2] == 20)");
-
- lua["a_new_value"] = 24;
- lua["chase_tail"] = [](int chasing) {
- int r = 2;
- for (int i = 0; i < chasing; ++i) {
- r *= r;
- }
- return r;
- };
-
- lua.script("assert(a_new_value == 24)");
- lua.script("assert(chase_tail(2) == 16)");
-
- return 0;
-}