ᕕ༼ •̀︿•́༽ᕗ VC++ COMING THROUGH WAHAAAY ᕕ༼ •̀︿•́༽ᕗ

This commit is contained in:
ThePhD 2018-03-06 17:36:33 -05:00
parent 0fe9b160b7
commit 560b5b2673
4 changed files with 86 additions and 4 deletions

View File

@ -0,0 +1,70 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
// Something that can't be collided with
constexpr static const auto& script_key = "GlobalResource.MySpecialIdentifier123";
struct GlobalResource {
int value = 2;
};
// Customize sol2 to handle this type
namespace sol {
template <>
struct lua_type_of<GlobalResource*> : std::integral_constant<sol::type, sol::type::lightuserdata> {};
namespace stack {
template <>
struct checker<GlobalResource*> {
template <typename Handler>
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
// get the field from global storage
stack::get_field<true>(L, script_key);
// verify type
type t = static_cast<type>(lua_type(L, -1));
lua_pop(L, 1);
return t == type::lightuserdata;
}
};
template <>
struct getter<GlobalResource*> {
static GlobalResource* get(lua_State* L, int index, record& tracking) {
// retrieve the (light) userdata for this type
tracking.use(0); // not actually pulling anything off the stack
(void)index; // unused
stack::get_field<true>(L, script_key);
GlobalResource* ls = static_cast<GlobalResource*>(lua_touserdata(L, -1));
lua_pop(L, 1); // clean up stack value returned by `get_field`
return ls;
};
};
template <>
struct pusher<GlobalResource*> {
static int push(lua_State* L, GlobalResource* ls) {
// push light userdata
return stack::push(L, make_light(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 being 2
lua.script("assert(f(1) == 3)");
return 0;
}

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2018-03-06 03:55:05.726661 UTC
// This header was generated with sol v2.19.5 (revision 68738cd)
// Generated 2018-03-06 22:35:07.056602 UTC
// This header was generated with sol v2.19.5 (revision 0fe9b16)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -19868,7 +19868,13 @@ namespace sol {
template <typename... Ret, typename... Args>
decltype(auto) call(Args&&... args) {
#if defined(_MSC_VER) && _MSC_VER == 1913
// This compiler is bananas
// B, A N A N A S
return get<protected_function>().call<Ret...>(std::forward<Args>(args)...);
#else
return get<protected_function>().template call<Ret...>(std::forward<Args>(args)...);
#endif
}
template <typename... Args>

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2018-03-06 03:55:05.939310 UTC
// This header was generated with sol v2.19.5 (revision 68738cd)
// Generated 2018-03-06 22:35:07.265771 UTC
// This header was generated with sol v2.19.5 (revision 0fe9b16)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -122,7 +122,13 @@ namespace sol {
template <typename... Ret, typename... Args>
decltype(auto) call(Args&&... args) {
#if defined(_MSC_VER) && _MSC_VER == 1913
// This compiler is bananas
// B, A N A N A S
return get<protected_function>().call<Ret...>(std::forward<Args>(args)...);
#else
return get<protected_function>().template call<Ret...>(std::forward<Args>(args)...);
#endif
}
template <typename... Args>