|
34 | 34 | #include "../utils/MethodBindByName.hpp" |
35 | 35 | #include "../utils/convert_godot_lua.hpp" |
36 | 36 | #include "../utils/convert_godot_std.hpp" |
| 37 | +#include "../utils/function_wrapper.hpp" |
37 | 38 | #include "../utils/string_names.hpp" |
38 | 39 |
|
39 | 40 | using namespace godot; |
@@ -132,11 +133,12 @@ std::tuple<sol::object, sol::object> variant__pairs(sol::this_state state, const |
132 | 133 | return ObjectIterator::object_pairs(state, variant); |
133 | 134 | } |
134 | 135 |
|
135 | | -VariantType variant_get_type(const Variant& variant) { |
136 | | - return VariantType(variant.get_type()); |
| 136 | +VariantType variant_get_type(const sol::stack_object& self) { |
| 137 | + return VariantType(to_variant(self).get_type()); |
137 | 138 | } |
138 | 139 |
|
139 | | -bool variant_is(const Variant& variant, const sol::stack_object& type) { |
| 140 | +bool variant_is(const sol::stack_object& self, const sol::stack_object& type) { |
| 141 | + Variant variant = to_variant(self); |
140 | 142 | if (type.get_type() == sol::type::nil) { |
141 | 143 | return variant.get_type() == Variant::NIL; |
142 | 144 | } |
@@ -186,15 +188,15 @@ extern "C" int luaopen_godot_variant(lua_State *L) { |
186 | 188 | Variant(double v), |
187 | 189 | Variant(const char *v) |
188 | 190 | >(), |
189 | | - "booleanize", &Variant::booleanize, |
190 | | - "duplicate", &Variant::duplicate, |
| 191 | + "booleanize", wrap_function(L, +[](const Variant& v) { return v.booleanize(); }), |
| 192 | + "duplicate", wrap_function(L, +[](const Variant& self) { return self.duplicate(); }), |
191 | 193 | "call", &variant_call, |
192 | 194 | "pcall", &variant_pcall, |
193 | 195 | "get_type", &variant_get_type, |
194 | | - "get_type_name", &get_type_name, |
195 | | - "hash", &Variant::hash, |
196 | | - "recursive_hash", &Variant::recursive_hash, |
197 | | - "hash_compare", &Variant::hash_compare, |
| 196 | + "get_type_name", wrap_function(L, &get_type_name), |
| 197 | + "hash", wrap_function(L, +[](const Variant& self) { return self.hash(); }), |
| 198 | + "recursive_hash", wrap_function(L, +[](const Variant& self, int recursion_count) { return self.recursive_hash(recursion_count); }), |
| 199 | + "hash_compare", wrap_function(L, +[](const Variant& self, const Variant& other) { return self.hash_compare(other); }), |
198 | 200 | "is", &variant_is, |
199 | 201 | // comparison |
200 | 202 | sol::meta_function::equal_to, &evaluate_binary_operator<Variant::OP_EQUAL>, |
|
0 commit comments