aboutsummaryrefslogtreecommitdiffstats
path: root/deps/sol2/examples/source/metatable_key_low_level.cpp
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-30 00:19:31 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-30 00:19:31 -0400
commitbd3fe0cac583739bc0d7c4b5c8f301bb350abca0 (patch)
tree7eeb1aabcebd6999de1c3457d0882246ec0ff4d4 /deps/sol2/examples/source/metatable_key_low_level.cpp
parent2662ac356ce14dacfbc91689fd37244facff4989 (diff)
Renamed lib to deps so github will ignore it for language stats
Diffstat (limited to 'deps/sol2/examples/source/metatable_key_low_level.cpp')
-rw-r--r--deps/sol2/examples/source/metatable_key_low_level.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/deps/sol2/examples/source/metatable_key_low_level.cpp b/deps/sol2/examples/source/metatable_key_low_level.cpp
new file mode 100644
index 0000000..8e79ab4
--- /dev/null
+++ b/deps/sol2/examples/source/metatable_key_low_level.cpp
@@ -0,0 +1,35 @@
+#define SOL_ALL_SAFETIES_ON 1
+#include <sol/sol.hpp>
+
+#include "assert.hpp"
+
+int main(int, char* []) {
+
+ struct bark {
+ int operator()(int x) {
+ return x;
+ }
+ };
+
+ sol::state lua;
+ lua.open_libraries(sol::lib::base);
+
+ lua.new_usertype<bark>("bark",
+ sol::meta_function::call_function, &bark::operator()
+ );
+
+ bark b;
+ lua.set("b", &b);
+
+ sol::table b_as_table = lua["b"];
+ sol::table b_metatable = b_as_table[sol::metatable_key];
+ sol::function b_call = b_metatable["__call"];
+ sol::function b_as_function = lua["b"];
+
+ int result1 = b_as_function(1);
+ // pass 'self' directly to argument
+ int result2 = b_call(b, 1);
+ c_assert(result1 == result2);
+ c_assert(result1 == 1);
+ c_assert(result2 == 1);
+}