summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/sol2/examples/self_call.cpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2016-10-07 14:43:09 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2016-10-07 14:43:09 +0200
commit377472a6dd2c9bdff4d5667f5789c49aee2abb4c (patch)
treea0ce4d6fc3db1524609efc61307d48448e703f38 /3rdparty/sol2/examples/self_call.cpp
parent1335933ce00cf6095e403a24d0b1dd9e0b565650 (diff)
Added sol2 header only library as future replacement for luabridge (nw)
Diffstat (limited to '3rdparty/sol2/examples/self_call.cpp')
-rw-r--r--3rdparty/sol2/examples/self_call.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/3rdparty/sol2/examples/self_call.cpp b/3rdparty/sol2/examples/self_call.cpp
new file mode 100644
index 00000000000..c64ded34133
--- /dev/null
+++ b/3rdparty/sol2/examples/self_call.cpp
@@ -0,0 +1,35 @@
+#define SOL_CHECK_ARGUMENTS
+#include <sol.hpp>
+#include <cassert>
+#include <iostream>
+
+int main() {
+ std::cout << "=== self_call example ===" << std::endl;
+
+ sol::state lua;
+
+ lua.open_libraries(sol::lib::base, sol::lib::package, sol::lib::table);
+
+ // a small script using 'self' syntax
+ lua.script(R"(
+ some_table = { some_val = 100 }
+
+ function some_table:add_to_some_val(value)
+ self.some_val = self.some_val + value
+ end
+
+ function print_some_val()
+ print("some_table.some_val = " .. some_table.some_val)
+ end
+ )");
+
+ // do some printing
+ lua["print_some_val"]();
+ // 100
+
+ sol::table self = lua["some_table"];
+ self["add_to_some_val"](self, 10);
+ lua["print_some_val"]();
+
+ std::cout << std::endl;
+} \ No newline at end of file