diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-08-30 00:45:36 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-08-30 00:45:36 -0400 |
commit | dc2493e7525bb7633f697ef10f72b72b46222249 (patch) | |
tree | 9816755219e65d3f47fdce81c78f3736a7ddb8ab /deps/sol2/examples/source/static_variables.cpp | |
parent | 9d2b31797d0cfd130802b69261df2cd402e39b49 (diff) |
Forget what I said, I just need to change git attributes to mark for vendor
Diffstat (limited to 'deps/sol2/examples/source/static_variables.cpp')
-rw-r--r-- | deps/sol2/examples/source/static_variables.cpp | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/deps/sol2/examples/source/static_variables.cpp b/deps/sol2/examples/source/static_variables.cpp deleted file mode 100644 index 686eb0d..0000000 --- a/deps/sol2/examples/source/static_variables.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include <sol/sol.hpp> - -#include <iostream> -#include "assert.hpp" - -struct test { - static int muh_variable; -}; -int test::muh_variable = 25; - - -int main() { - std::cout << "=== static_variables ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - lua.new_usertype<test>("test", - "direct", sol::var(2), - "global", sol::var(test::muh_variable), - "ref_global", sol::var(std::ref(test::muh_variable)) - ); - - int direct_value = lua["test"]["direct"]; - // direct_value == 2 - c_assert(direct_value == 2); - std::cout << "direct_value: " << direct_value << std::endl; - - int global = lua["test"]["global"]; - int global2 = lua["test"]["ref_global"]; - // global == 25 - // global2 == 25 - c_assert(global == 25); - c_assert(global2 == 25); - - std::cout << "First round of values --" << std::endl; - std::cout << global << std::endl; - std::cout << global2 << std::endl; - - test::muh_variable = 542; - - global = lua["test"]["global"]; - // global == 25 - // global is its own memory: was passed by value - - global2 = lua["test"]["ref_global"]; - // global2 == 542 - // global2 was passed through std::ref - // global2 holds a reference to muh_variable - // if muh_variable goes out of scope or is deleted - // problems could arise, so be careful! - - c_assert(global == 25); - c_assert(global2 == 542); - - std::cout << "Second round of values --" << std::endl; - std::cout << "global : " << global << std::endl; - std::cout << "global2: " << global2 << std::endl; - std::cout << std::endl; - - return 0; -} |