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/customization_global_transparent_argument.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/customization_global_transparent_argument.cpp')
-rw-r--r-- | deps/sol2/examples/source/customization_global_transparent_argument.cpp | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/deps/sol2/examples/source/customization_global_transparent_argument.cpp b/deps/sol2/examples/source/customization_global_transparent_argument.cpp deleted file mode 100644 index a7e93c3..0000000 --- a/deps/sol2/examples/source/customization_global_transparent_argument.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1
-#include <sol/sol.hpp>
-
-// Something that can't be collided with
-static const auto& script_key = "GlobalResource.MySpecialIdentifier123";
-
-struct GlobalResource {
- int value = 2;
-};
-
-template <typename Handler>
-bool sol_lua_check(sol::types<GlobalResource*>, lua_State* L, int /*index*/, Handler&& handler, sol::stack::record& tracking) {
- // not actually taking anything off the stack
- tracking.use(0);
- // get the field from global storage
- sol::stack::get_field<true>(L, script_key);
- // verify type
- sol::type t = static_cast<sol::type>(lua_type(L, -1));
- lua_pop(L, 1);
- if (t != sol::type::lightuserdata) {
- handler(L, 0, sol::type::lightuserdata, t, "global resource is not present as a light userdata");
- return false;
- }
- return true;
-}
-
-GlobalResource* sol_lua_get(sol::types<GlobalResource*>, lua_State* L, int /*index*/, sol::stack::record& tracking) {
- // retrieve the (light) userdata for this type
-
- // not actually pulling anything off the stack
- tracking.use(0);
- sol::stack::get_field<true>(L, script_key);
- GlobalResource* ls = static_cast<GlobalResource*>(lua_touserdata(L, -1));
-
- // clean up stack value returned by `get_field`
- lua_pop(L, 1);
- return ls;
-}
-
-int sol_lua_push(sol::types<GlobalResource*>, lua_State* L, GlobalResource* ls) {
- // push light userdata
- return sol::stack::push(L, static_cast<void*>(ls));
-}
-
-int main() {
-
- sol::state lua;
- lua.open_libraries(sol::lib::base);
-
- GlobalResource instance;
-
- // get GlobalResource
- lua.set_function("f", [](GlobalResource* l, int value) {
- return l->value + value;
- });
- lua.set(script_key, &instance);
-
- // note only 1 argument,
- // despite f having 2 arguments to recieve
- lua.script("assert(f(1) == 3)");
-
- return 0;
-}
|