diff --git a/include/wrenbind17/any.hpp b/include/wrenbind17/any.hpp index a208d1a..6d27c6c 100644 --- a/include/wrenbind17/any.hpp +++ b/include/wrenbind17/any.hpp @@ -199,6 +199,10 @@ namespace wrenbind17 { return type == WREN_TYPE_STRING; } + template <> inline bool ReturnValue::is() const { + return type == WREN_TYPE_STRING; + } + template <> inline std::nullptr_t ReturnValue::as() { if (!is()) { throw BadCast("Return value is not a null"); diff --git a/include/wrenbind17/caller.hpp b/include/wrenbind17/caller.hpp index 9521cbb..d537cf3 100644 --- a/include/wrenbind17/caller.hpp +++ b/include/wrenbind17/caller.hpp @@ -74,6 +74,11 @@ namespace wrenbind17 { } }; + template <> + inline void ForeginMethodReturnHelper::push(WrenVM* vm, int index, std::string_view ret) { + PushHelper::f(vm, index, ret); + } + template <> inline void ForeginMethodReturnHelper::push(WrenVM* vm, int index, const std::string& ret) { PushHelper::f(vm, index, ret); diff --git a/include/wrenbind17/pop.hpp b/include/wrenbind17/pop.hpp index ba0c41f..6e87633 100644 --- a/include/wrenbind17/pop.hpp +++ b/include/wrenbind17/pop.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include "object.hpp" @@ -54,6 +55,10 @@ namespace wrenbind17 { return wrenGetSlotType(vm, idx) == WrenType::WREN_TYPE_STRING; } + template <> inline bool is(WrenVM* vm, const int idx) { + return wrenGetSlotType(vm, idx) == WrenType::WREN_TYPE_STRING; + } + template <> inline bool is(WrenVM* vm, const int idx) { return wrenGetSlotType(vm, idx) == WrenType::WREN_TYPE_NULL; } @@ -255,6 +260,11 @@ namespace wrenbind17 { return std::string(wrenGetSlotString(vm, idx)); } + template <> inline std::string_view getSlot(WrenVM* vm, int idx) { + validate(vm, idx); + return std::string_view(wrenGetSlotString(vm, idx)); + } + template <> inline std::nullptr_t getSlot(WrenVM* vm, int idx) { validate(vm, idx); return nullptr; diff --git a/include/wrenbind17/push.hpp b/include/wrenbind17/push.hpp index 7c94a40..ae70ec4 100644 --- a/include/wrenbind17/push.hpp +++ b/include/wrenbind17/push.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "exception.hpp" #include "object.hpp" @@ -199,6 +200,12 @@ namespace wrenbind17 { } }; + template <> struct PushHelper { + static inline void f(WrenVM* vm, int idx, std::string_view value) { + wrenSetSlotString(vm, idx, value.data()); + } + }; + template <> struct PushHelper { static inline void f(WrenVM* vm, int idx, const std::string value) { wrenSetSlotString(vm, idx, value.c_str());