Make extension instances create the corresponding godot object in their constructor
This commit is contained in:
56
src/classes/wrapped.cpp
Normal file
56
src/classes/wrapped.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/*************************************************************************/
|
||||
/* wrapped.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include <godot_cpp/classes/wrapped.hpp>
|
||||
|
||||
#include <godot_cpp/variant/builtin_types.hpp>
|
||||
|
||||
#include <godot_cpp/classes/object.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
void Wrapped::_postinitialize() {
|
||||
godot::internal::gdn_interface->object_set_instance(_owner, _get_class(), this);
|
||||
godot::internal::gdn_interface->object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks());
|
||||
}
|
||||
|
||||
Wrapped::Wrapped(const char *p_godot_class) {
|
||||
_owner = godot::internal::gdn_interface->classdb_construct_object(p_godot_class);
|
||||
}
|
||||
|
||||
Wrapped::Wrapped(GodotObject *p_godot_object) {
|
||||
_owner = p_godot_object;
|
||||
}
|
||||
|
||||
void postinitialize_handler(Wrapped *p_wrapped) {
|
||||
p_wrapped->_postinitialize();
|
||||
}
|
||||
|
||||
} // namespace godot
|
||||
@@ -91,17 +91,6 @@ void GDExtensionBinding::deinitialize_level(void *userdata, GDNativeInitializati
|
||||
}
|
||||
}
|
||||
|
||||
void *GDExtensionBinding::create_instance_callback(void *p_token, void *p_instance) {
|
||||
ERR_FAIL_COND_V_MSG(p_token != internal::library, nullptr, "Asking for creating instance with invalid token.");
|
||||
Wrapped *wrapped = memnew(Wrapped(p_instance));
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
void GDExtensionBinding::free_instance_callback(void *p_token, void *p_instance, void *p_binding) {
|
||||
ERR_FAIL_COND_MSG(p_token != internal::library, "Asking for freeing instance with invalid token.");
|
||||
memdelete((Wrapped *)p_binding);
|
||||
}
|
||||
|
||||
void GDExtensionBinding::InitObject::register_core_initializer(Callback p_core_init) const {
|
||||
GDExtensionBinding::init_callbacks[GDNATIVE_INITIALIZATION_CORE] = p_core_init;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user