Skip to content

Commit 80fdb91

Browse files
committed
Add pointers support for virtual methods.
As introduced in godot for virtual methods. Custom structs are not yet supported.
1 parent a44e9aa commit 80fdb91

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

include/godot_cpp/core/method_ptrcall.hpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,47 @@ struct PtrToArg<const T *> {
184184
}
185185
};
186186

187+
// Pointers.
188+
#define GDVIRTUAL_NATIVE_PTR(m_type) \
189+
template <> \
190+
struct PtrToArg<m_type *> { \
191+
_FORCE_INLINE_ static m_type *convert(const void *p_ptr) { \
192+
return (m_type *)(*(void **)p_ptr); \
193+
} \
194+
typedef m_type *EncodeT; \
195+
_FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \
196+
*((void **)p_ptr) = p_var; \
197+
} \
198+
}; \
199+
\
200+
template <> \
201+
struct PtrToArg<const m_type *> { \
202+
_FORCE_INLINE_ static const m_type *convert(const void *p_ptr) { \
203+
return (const m_type *)(*(const void **)p_ptr); \
204+
} \
205+
typedef const m_type *EncodeT; \
206+
_FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \
207+
*((void **)p_ptr) = p_var; \
208+
} \
209+
}
210+
211+
GDVIRTUAL_NATIVE_PTR(bool);
212+
GDVIRTUAL_NATIVE_PTR(char);
213+
GDVIRTUAL_NATIVE_PTR(char16_t);
214+
GDVIRTUAL_NATIVE_PTR(char32_t);
215+
GDVIRTUAL_NATIVE_PTR(wchar_t);
216+
GDVIRTUAL_NATIVE_PTR(uint8_t);
217+
GDVIRTUAL_NATIVE_PTR(uint8_t *);
218+
GDVIRTUAL_NATIVE_PTR(int8_t);
219+
GDVIRTUAL_NATIVE_PTR(uint16_t);
220+
GDVIRTUAL_NATIVE_PTR(int16_t);
221+
GDVIRTUAL_NATIVE_PTR(uint32_t);
222+
GDVIRTUAL_NATIVE_PTR(int32_t);
223+
GDVIRTUAL_NATIVE_PTR(int64_t);
224+
GDVIRTUAL_NATIVE_PTR(uint64_t);
225+
GDVIRTUAL_NATIVE_PTR(float);
226+
GDVIRTUAL_NATIVE_PTR(double);
227+
187228
} // namespace godot
188229

189230
#endif // ! GODOT_CPP_METHOD_PTRCALL_HPP

0 commit comments

Comments
 (0)