summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/sol2/examples/namespacing.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/namespacing.cpp
parent1335933ce00cf6095e403a24d0b1dd9e0b565650 (diff)
Added sol2 header only library as future replacement for luabridge (nw)
Diffstat (limited to '3rdparty/sol2/examples/namespacing.cpp')
-rw-r--r--3rdparty/sol2/examples/namespacing.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/3rdparty/sol2/examples/namespacing.cpp b/3rdparty/sol2/examples/namespacing.cpp
new file mode 100644
index 00000000000..8d32744eb64
--- /dev/null
+++ b/3rdparty/sol2/examples/namespacing.cpp
@@ -0,0 +1,33 @@
+#define SOL_CHECK_ARGUMENTS
+#include <sol.hpp>
+#include <cassert>
+
+int main() {
+ struct my_class {
+ int b = 24;
+
+ int f() const {
+ return 24;
+ }
+
+ void g() {
+ ++b;
+ }
+ };
+
+ sol::state lua;
+ lua.open_libraries();
+
+ sol::table bark = lua.create_named_table("bark");
+ bark.new_usertype<my_class>("my_class",
+ "f", &my_class::f,
+ "g", &my_class::g
+ ); // the usual
+
+ lua.script("obj = bark.my_class.new()"); // this works
+ lua.script("obj:g()");
+ my_class& obj = lua["obj"];
+ assert(obj.b == 25);
+
+ return 0;
+}