Merge pull request #9804 from karroffel/gdnative-rewrite

[GDNative] new GDNative API
This commit is contained in:
Thomas Herzog 2017-07-24 04:51:34 +02:00 committed by GitHub
commit b31973b64d
50 changed files with 2611 additions and 2074 deletions

File diff suppressed because it is too large Load diff

View file

@ -34,382 +34,112 @@
#include "io/resource_saver.h"
#include "os/thread_safe.h"
#include "resource.h"
#include "scene/main/node.h"
#include "script_language.h"
#include "self_list.h"
#include "godot.h"
struct GDNativeScriptData;
class GDNativeLibrary;
struct NativeLibrary {
StringName path;
void *handle;
GDNativeLibrary *dllib;
Map<StringName, GDNativeScriptData *> scripts;
static Error initialize(NativeLibrary *&p_native_lib, const StringName p_path);
static Error terminate(NativeLibrary *&p_native_lib);
};
struct GDNativeScriptData {
/* typedef void* (InstanceFunc)(godot_object* instance);
typedef void (DestroyFunc)(godot_object* instance,void* userdata);
typedef godot_variant (MethodFunc)(godot_object *instance, void *userdata, void *method_data, int arg_count,godot_variant **args);
typedef void (MethodDataFreeFunc)(void *method_data);
typedef void (SetterFunc)(godot_object* instance,void* userdata,godot_variant value);
typedef godot_variant (GetterFunc)(godot_object* instance,void* userdata);*/
struct Method {
godot_instance_method method;
MethodInfo info;
int rpc_mode;
Method() {
}
Method(godot_instance_method p_method, MethodInfo p_info, int p_rpc_mode) {
method = p_method;
info = p_info;
rpc_mode = p_rpc_mode;
}
};
struct Property {
godot_property_set_func setter;
godot_property_get_func getter;
PropertyInfo info;
Variant default_value;
int rset_mode;
Property() {
}
Property(godot_property_set_func p_setter, godot_property_get_func p_getter) {
setter = p_setter;
getter = p_getter;
}
Property(godot_property_set_func p_setter, godot_property_get_func p_getter, PropertyInfo p_info, Variant p_default_value, int p_rset_mode) {
setter = p_setter;
getter = p_getter;
info = p_info;
default_value = p_default_value;
rset_mode = p_rset_mode;
}
};
struct Signal {
MethodInfo signal;
};
Map<StringName, Method> methods;
Map<StringName, Property> properties;
Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals
StringName base;
StringName base_native_type;
GDNativeScriptData *base_data;
godot_instance_create_func create_func;
godot_instance_destroy_func destroy_func;
bool is_tool;
GDNativeScriptData() {
base = StringName();
base_data = NULL;
is_tool = false;
}
GDNativeScriptData(StringName p_base, godot_instance_create_func p_instance, godot_instance_destroy_func p_free) {
base = p_base;
base_data = NULL;
create_func = p_instance;
destroy_func = p_free;
is_tool = false;
}
};
class GDNativeScript : public Script {
GDCLASS(GDNativeScript, Script);
Ref<GDNativeLibrary> library;
StringName script_name;
StringName base_native_type;
Set<Object *> instances;
GDNativeScriptData *script_data;
#ifdef TOOLS_ENABLED
Set<PlaceHolderScriptInstance *> placeholders;
void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
#endif
friend class GDNativeInstance;
friend class GDNativeScriptLanguage;
friend class GDNativeReloadNode;
friend class GDNativeLibrary;
protected:
static void _bind_methods();
public:
virtual bool can_instance() const;
virtual Ref<Script> get_base_script() const; //for script inheritance
virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so
virtual ScriptInstance *instance_create(Object *p_this);
virtual bool instance_has(const Object *p_this) const;
virtual bool has_source_code() const;
virtual String get_source_code() const;
virtual void set_source_code(const String &p_code) {}
virtual Error reload(bool p_keep_state = false);
virtual bool has_method(const StringName &p_method) const;
virtual MethodInfo get_method_info(const StringName &p_method) const;
virtual bool is_tool() const;
virtual String get_node_type() const;
virtual ScriptLanguage *get_language() const;
virtual bool has_script_signal(const StringName &p_signal) const;
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void update_exports() {} //editor tool
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
Ref<GDNativeLibrary> get_library() const;
void set_library(Ref<GDNativeLibrary> p_library);
StringName get_script_name() const;
void set_script_name(StringName p_script_name);
GDNativeScript();
~GDNativeScript();
};
#include "godot/gdnative.h"
class GDNativeLibrary : public Resource {
_THREAD_SAFE_CLASS_
GDCLASS(GDNativeLibrary, Resource)
GDCLASS(GDNativeLibrary, Resource);
OBJ_SAVE_TYPE(GDNativeLibrary);
enum Platform {
X11_32BIT,
X11_64BIT,
WINDOWS_32BIT,
WINDOWS_64BIT,
// NOTE(karroffel): I heard OSX 32 bit is dead, so 64 only
OSX,
Map<StringName, String> platform_files;
NativeLibrary *native_library;
static GDNativeLibrary *currently_initialized_library;
// TODO(karroffel): all different android versions and archs
ANDROID,
// TODO(karroffe): all different iOS versions and archs
IOS,
// TODO(karroffel): figure out how to deal with web stuff at all...
WASM,
// TODO(karroffel): does UWP have different libs??
// UWP,
NUM_PLATFORMS
};
static String platform_names[NUM_PLATFORMS];
static String platform_lib_ext[NUM_PLATFORMS];
// TODO(karroffel): make this actually do something lol.
static Platform current_platform;
String library_paths[NUM_PLATFORMS];
protected:
friend class GDNativeScript;
friend struct NativeLibrary;
friend class GDNativeReloadNode;
GDNativeScriptData *get_script_data(const StringName p_name);
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
Error _initialize();
Error _terminate();
static GDNativeLibrary *get_currently_initialized_library();
void _register_script(const StringName p_name, const StringName p_base, godot_instance_create_func p_instance_func, godot_instance_destroy_func p_destroy_func);
void _register_tool_script(const StringName p_name, const StringName p_base, godot_instance_create_func p_instance_func, godot_instance_destroy_func p_destroy_func);
void _register_script_method(const StringName p_name, const StringName p_method, godot_method_attributes p_attr, godot_instance_method p_func, MethodInfo p_info);
void _register_script_property(const StringName p_name, const String p_path, godot_property_attributes *p_attr, godot_property_set_func p_setter, godot_property_get_func p_getter);
void _register_script_signal(const StringName p_name, const godot_signal *p_signal);
void set_platform_file(StringName p_platform, String p_file);
String get_platform_file(StringName p_platform) const;
GDNativeLibrary();
~GDNativeLibrary();
};
class GDNativeInstance : public ScriptInstance {
friend class GDNativeScript;
Object *owner;
Ref<GDNativeScript> script;
void *userdata;
void _ml_call_reversed(GDNativeScriptData *data_ptr, const StringName &p_method, const Variant **p_args, int p_argcount);
public:
_FORCE_INLINE_ Object *get_owner() { return owner; }
_FORCE_INLINE_ void *get_userdata() { return userdata; }
virtual bool set(const StringName &p_name, const Variant &p_value);
virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = NULL) const;
virtual void get_method_list(List<MethodInfo> *p_list) const;
virtual bool has_method(const StringName &p_method) const;
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
Variant debug_get_member_by_index(int p_idx) const { return Variant(); }
virtual void notification(int p_notification);
virtual Ref<Script> get_script() const;
virtual ScriptLanguage *get_language();
void set_path(const String &p_path);
void reload_members();
virtual RPCMode get_rpc_mode(const StringName &p_method) const;
virtual RPCMode get_rset_mode(const StringName &p_variable) const;
GDNativeInstance();
~GDNativeInstance();
};
class GDNativeReloadNode;
class GDNativeScriptLanguage : public ScriptLanguage {
friend class GDNativeScript;
friend class GDNativeInstance;
friend class GDNativeReloadNode;
friend class GDNativeLibrary;
static GDNativeScriptLanguage *singleton;
Variant *_global_array; // @Unused necessary?
Vector<Variant> global_array; // @Unused necessary?
Map<StringName, int> globals; // @Unused necessary?
// @Unused necessary?
void _add_global(const StringName &p_name, const Variant &p_value);
Mutex *lock;
Set<GDNativeScript *> script_list;
bool profiling;
uint64_t script_frame_time;
struct {
StringName _notification;
} strings;
public:
Map<StringName, NativeLibrary *> initialized_libraries;
_FORCE_INLINE_ static GDNativeScriptLanguage *get_singleton() { return singleton; }
virtual String get_name() const;
/* LANGUAGE FUNCTIONS */
virtual void init();
virtual String get_type() const;
virtual String get_extension() const;
virtual Error execute_file(const String &p_path);
virtual void finish();
/* EDITOR FUNCTIONS */
virtual void get_reserved_words(List<String> *p_words) const {};
virtual void get_comment_delimiters(List<String> *p_delimiters) const {};
virtual void get_string_delimiters(List<String> *p_delimiters) const {};
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint) { return ERR_UNAVAILABLE; }
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; }
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {};
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
/* MULTITHREAD FUNCTIONS */
//some VMs need to be notified of thread creation/exiting to allocate a stack
virtual void thread_enter() {}
virtual void thread_exit() {}
/* DEBUGGER FUNCTIONS */
virtual String debug_get_error() const;
virtual int debug_get_stack_level_count() const;
virtual int debug_get_stack_level_line(int p_level) const;
virtual String debug_get_stack_level_function(int p_level) const;
virtual String debug_get_stack_level_source(int p_level) const;
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1){};
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); }
virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
/* LOADER FUNCTIONS */
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
virtual void get_public_constants(List<Pair<String, Variant> > *p_constants) const;
/* PROFILLER FUNCTIONS */
virtual void profiling_start();
virtual void profiling_stop();
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual void frame();
static String get_init_symbol_name();
static String get_terminate_symbol_name();
/* HACKER FUNCTIONS */
void _compile_dummy_for_the_api();
GDNativeScriptLanguage();
~GDNativeScriptLanguage();
};
class GDNativeReloadNode : public Node {
GDCLASS(GDNativeReloadNode, Node)
public:
static void _bind_methods();
void _notification(int p_what);
void set_library_path(StringName p_platform, String p_path);
String get_library_path(StringName p_platform) const;
String get_active_library_path() const;
};
class ResourceFormatLoaderGDNativeScript : public ResourceFormatLoader {
typedef godot_variant (*native_call_cb)(void *, godot_string *, godot_array *);
typedef void (*native_raw_call_cb)(void *, godot_string *, void *, int, void **, void *);
struct GDNativeCallRegistry {
static GDNativeCallRegistry *singleton;
inline GDNativeCallRegistry *get_singleton() {
return singleton;
}
inline GDNativeCallRegistry()
: native_calls(),
native_raw_calls() {}
Map<StringName, native_call_cb> native_calls;
Map<StringName, native_raw_call_cb> native_raw_calls;
void register_native_call_type(StringName p_call_type, native_call_cb p_callback);
void register_native_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback);
Vector<StringName> get_native_call_types();
Vector<StringName> get_native_raw_call_types();
};
class GDNative : public Reference {
GDCLASS(GDNative, Reference)
Ref<GDNativeLibrary> library;
bool initialized;
// TODO(karroffel): different platforms? WASM????
void *native_handle;
void _compile_dummy_for_api();
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
GDNative();
~GDNative();
class ResourceFormatSaverGDNativeScript : public ResourceFormatSaver {
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual bool recognize(const RES &p_resource) const;
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
static void _bind_methods();
void set_library(Ref<GDNativeLibrary> p_library);
Ref<GDNativeLibrary> get_library();
bool is_initialized();
bool initialize();
bool terminate();
Variant call_native(StringName p_call_type, StringName p_procedure_name, Array p_arguments = Array());
void call_native_raw(StringName p_raw_call_type, StringName p_procedure_name, void *data, int num_args, void **args, void *r_return);
};
#endif // GDNATIVE_H

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_array.cpp */
/* array.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_array.h"
#include "array.h"
#include "core/array.h"
#include "core/os/memory.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_array.h */
/* array.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -37,16 +37,19 @@ extern "C" {
#include <stdint.h>
#define GODOT_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED
typedef struct godot_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_ARRAY_SIZE];
} godot_array;
#endif
#include "godot_pool_arrays.h"
#include "godot_variant.h"
#include "pool_arrays.h"
#include "variant.h"
#include "../godot.h"
#include "gdnative.h"
void GDAPI godot_array_new(godot_array *r_dest);
void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_basis.cpp */
/* basis.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_basis.h"
#include "basis.h"
#include "core/variant.h"
#include "core/math/matrix3.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_basis.h */
/* basis.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,15 +36,18 @@ extern "C" {
#include <stdint.h>
#define GODOT_BASIS_SIZE 36
#ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED
typedef struct godot_basis {
uint8_t _dont_touch_that[36];
typedef struct {
uint8_t _dont_touch_that[GODOT_BASIS_SIZE];
} godot_basis;
#endif
#include "../godot.h"
#include "godot_vector3.h"
#include "gdnative.h"
#include "quat.h"
#include "vector3.h"
void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis);
void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_color.cpp */
/* color.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_color.h"
#include "color.h"
#include "core/variant.h"
#include "core/color.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_color.h */
/* color.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,15 +36,17 @@ extern "C" {
#include <stdint.h>
#define GODOT_COLOR_SIZE 16
#ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED
typedef struct godot_color {
uint8_t _dont_touch_that[16];
typedef struct {
uint8_t _dont_touch_that[GODOT_COLOR_SIZE];
} godot_color;
#endif
#include "../godot.h"
#include "godot_string.h"
#include "gdnative.h"
#include "string.h"
void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a);
void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_dictionary.cpp */
/* dictionary.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_dictionary.h"
#include "dictionary.h"
#include "core/variant.h"
#include "core/dictionary.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_dictionary.h */
/* dictionary.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,16 +36,18 @@ extern "C" {
#include <stdint.h>
#define GODOT_DICTIONARY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED
typedef struct godot_dictionary {
uint8_t _dont_touch_that[8];
typedef struct {
uint8_t _dont_touch_that[GODOT_DICTIONARY_SIZE];
} godot_dictionary;
#endif
#include "../godot.h"
#include "godot_array.h"
#include "godot_variant.h"
#include "array.h"
#include "gdnative.h"
#include "variant.h"
void GDAPI godot_dictionary_new(godot_dictionary *r_dest);
void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot.cpp */
/* gdnative.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot.h"
#include "gdnative.h"
#include "class_db.h"
#include "error_macros.h"
@ -79,13 +79,6 @@ void _api_anchor() {
_variant_api_anchor();
}
extern "C++" {
template <class a, class b>
_FORCE_INLINE_ a memcast(b v) {
return *((a *)&v);
}
}
void GDAPI godot_object_destroy(godot_object *p_o) {
memdelete((Object *)p_o);
}
@ -142,65 +135,6 @@ void GDAPI godot_method_bind_varcall(godot_method_bind *p_method_bind)
}
*/
// Script API
void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library();
if (!library) {
ERR_EXPLAIN("Attempt to register script after initializing library!");
ERR_FAIL();
}
library->_register_script(p_name, p_base, p_create_func, p_destroy_func);
}
void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library();
if (!library) {
ERR_EXPLAIN("Attempt to register script after initializing library!");
ERR_FAIL();
}
library->_register_tool_script(p_name, p_base, p_create_func, p_destroy_func);
}
void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) {
GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library();
if (!library) {
ERR_EXPLAIN("Attempt to register script after initializing library!");
ERR_FAIL();
}
library->_register_script_method(p_name, p_function_name, p_attr, p_method, MethodInfo());
}
void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func) {
GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library();
if (!library) {
ERR_EXPLAIN("Attempt to register script after initializing library!");
ERR_FAIL();
}
library->_register_script_property(p_name, p_path, p_attr, p_set_func, p_get_func);
}
void GDAPI godot_script_register_signal(const char *p_name, const godot_signal *p_signal) {
GDNativeLibrary *library = GDNativeLibrary::get_currently_initialized_library();
if (!library) {
ERR_EXPLAIN("Attempt to register script after initializing library!");
ERR_FAIL();
}
library->_register_script_signal(p_name, p_signal);
}
void GDAPI *godot_native_get_userdata(godot_object *p_instance) {
Object *instance = (Object *)p_instance;
if (!instance)
return NULL;
if (instance->get_script_instance() && instance->get_script_instance()->get_language() == GDNativeScriptLanguage::get_singleton()) {
return ((GDNativeInstance *)instance->get_script_instance())->get_userdata();
}
return NULL;
}
godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname) {
ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname));
if (class_info)

View file

@ -0,0 +1,298 @@
/*************************************************************************/
/* gdnative.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 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. */
/*************************************************************************/
#ifndef GODOT_GDNATIVE_H
#define GODOT_GDNATIVE_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef GDAPI_BUILT_IN
#define GDAPI_EXPORT
#endif
#ifdef _WIN32
#if defined(GDAPI_EXPORT)
#define GDCALLINGCONV
#define GDAPI __declspec(dllexport) GDCALLINGCONV
#else
#define GDCALLINGCONV
#define GDAPI __declspec(dllimport) GDCALLINGCONV
#endif
#elif defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
#define GDCALLINGCONV
#define GDAPI
#elif TARGET_OS_MAC
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
#else
#define GDCALLINGCONV __attribute__((sysv_abi))
#define GDAPI GDCALLINGCONV
#endif
// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!!
#ifdef _WIN32
#define GDN_EXPORT __declspec(dllexport)
#else
#define GDN_EXPORT
#endif
#include <stdbool.h>
#include <stdint.h>
#define GODOT_API_VERSION 1
////// Error
typedef enum {
GODOT_OK,
GODOT_FAILED, ///< Generic fail error
GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
GODOT_ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet
GODOT_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
GODOT_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
GODOT_ERR_OUT_OF_MEMORY, ///< Out of memory
GODOT_ERR_FILE_NOT_FOUND,
GODOT_ERR_FILE_BAD_DRIVE,
GODOT_ERR_FILE_BAD_PATH,
GODOT_ERR_FILE_NO_PERMISSION, // (10)
GODOT_ERR_FILE_ALREADY_IN_USE,
GODOT_ERR_FILE_CANT_OPEN,
GODOT_ERR_FILE_CANT_WRITE,
GODOT_ERR_FILE_CANT_READ,
GODOT_ERR_FILE_UNRECOGNIZED, // (15)
GODOT_ERR_FILE_CORRUPT,
GODOT_ERR_FILE_MISSING_DEPENDENCIES,
GODOT_ERR_FILE_EOF,
GODOT_ERR_CANT_OPEN, ///< Can't open a resource/socket/file
GODOT_ERR_CANT_CREATE, // (20)
GODOT_ERR_QUERY_FAILED,
GODOT_ERR_ALREADY_IN_USE,
GODOT_ERR_LOCKED, ///< resource is locked
GODOT_ERR_TIMEOUT,
GODOT_ERR_CANT_CONNECT, // (25)
GODOT_ERR_CANT_RESOLVE,
GODOT_ERR_CONNECTION_ERROR,
GODOT_ERR_CANT_AQUIRE_RESOURCE,
GODOT_ERR_CANT_FORK,
GODOT_ERR_INVALID_DATA, ///< Data passed is invalid (30)
GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists
GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
GODOT_ERR_DATABASE_CANT_READ, ///< database is full
GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full (35)
GODOT_ERR_COMPILATION_FAILED,
GODOT_ERR_METHOD_NOT_FOUND,
GODOT_ERR_LINK_FAILED,
GODOT_ERR_SCRIPT_FAILED,
GODOT_ERR_CYCLIC_LINK, // (40)
GODOT_ERR_INVALID_DECLARATION,
GODOT_ERR_DUPLICATE_SYMBOL,
GODOT_ERR_PARSE_ERROR,
GODOT_ERR_BUSY,
GODOT_ERR_SKIP, // (45)
GODOT_ERR_HELP, ///< user requested help!!
GODOT_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
GODOT_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
GODOT_ERR_WTF = GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
} godot_error;
////// bool
typedef bool godot_bool;
#define GODOT_TRUE 1
#define GODOT_FALSE 0
/////// int
typedef int godot_int;
/////// real
typedef float godot_real;
/////// Object (forward declared)
typedef void godot_object;
/////// Brute force forward declarations for the rest
/*
typedef struct godot_variant godot_variant;
typedef struct godot_string godot_string;
typedef struct godot_vector2 godot_vector2;
typedef struct godot_rect2 godot_rect2;
typedef struct godot_vector3 godot_vector3;
typedef struct godot_transform2d godot_transform2d;
typedef struct godot_plane godot_plane;
typedef struct godot_quat godot_quat;
typedef struct godot_rect3 godot_rect3;
typedef struct godot_basis godot_basis;
typedef struct godot_transform godot_transform;
typedef struct godot_color godot_color;
typedef struct godot_node_path godot_node_path;
typedef struct godot_rid godot_rid;
typedef struct godot_dictionary godot_dictionary;
typedef struct godot_array godot_array;
typedef struct godot_pool_byte_array godot_pool_byte_array;
typedef struct godot_pool_int_array godot_pool_int_array;
typedef struct godot_pool_real_array godot_pool_real_array;
typedef struct godot_pool_string_array godot_pool_string_array;
typedef struct godot_pool_vector2_array godot_pool_vector2_array;
typedef struct godot_pool_vector3_array godot_pool_vector3_array;
typedef struct godot_pool_color_array godot_pool_color_array;
*/
/////// String
#include "string.h"
////// Vector2
#include "vector2.h"
////// Rect2
#include "rect2.h"
////// Vector3
#include "vector3.h"
////// Transform2D
#include "transform2d.h"
/////// Plane
#include "plane.h"
/////// Quat
#include "quat.h"
/////// Rect3
#include "rect3.h"
/////// Basis
#include "basis.h"
/////// Transform
#include "transform.h"
/////// Color
#include "color.h"
/////// NodePath
#include "node_path.h"
/////// RID
#include "rid.h"
/////// Dictionary
#include "dictionary.h"
/////// Array
#include "array.h"
// single API file for Pool*Array
#include "pool_arrays.h"
void GDAPI godot_object_destroy(godot_object *p_o);
////// Variant
#include "variant.h"
////// Singleton API
godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed
////// MethodBind API
typedef struct {
uint8_t _dont_touch_that[1]; // TODO
} godot_method_bind;
godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname);
void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret);
godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error);
////// Script API
typedef struct {
godot_bool in_editor;
uint64_t core_api_hash;
uint64_t editor_api_hash;
uint64_t no_api_hash;
} godot_gdnative_init_options;
typedef struct {
godot_bool in_editor;
} godot_gdnative_terminate_options;
// Calling convention?
typedef godot_object *(*godot_class_constructor)();
godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname);
godot_dictionary GDAPI godot_get_global_constants();
////// GDNative procedure types
typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_options *);
typedef void (*godot_gdnative_terminate_fn)(godot_gdnative_terminate_options *);
typedef godot_variant (*godot_gdnative_procedure_fn)(void *, godot_array *);
////// System Functions
//using these will help Godot track how much memory is in use in debug mode
void GDAPI *godot_alloc(int p_bytes);
void GDAPI *godot_realloc(void *p_ptr, int p_bytes);
void GDAPI godot_free(void *p_ptr);
//print using Godot's error handler list
void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print(const godot_string *p_message);
#ifdef __cplusplus
}
#endif
#endif // GODOT_C_H

View file

@ -0,0 +1,23 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-aa47d037a37fb38b3b7e7828e4eec407.stex"
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
stream=false
size_limit=0
detect_3d=true

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_node_path.cpp */
/* node_path.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_node_path.h"
#include "node_path.h"
#include "core/variant.h"
#include "core/path_db.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_node_path.h */
/* node_path.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,15 +36,17 @@ extern "C" {
#include <stdint.h>
#define GODOT_NODE_PATH_SIZE 8
#ifndef GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED
typedef struct godot_node_path {
uint8_t _dont_touch_that[8];
typedef struct {
uint8_t _dont_touch_that[GODOT_NODE_PATH_SIZE];
} godot_node_path;
#endif
#include "../godot.h"
#include "godot_string.h"
#include "gdnative.h"
#include "string.h"
void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from);
void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_plane.cpp */
/* plane.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_plane.h"
#include "plane.h"
#include "core/variant.h"
#include "core/math/plane.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_plane.h */
/* plane.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,15 +36,17 @@ extern "C" {
#include <stdint.h>
#define GODOT_PLANE_SIZE 16
#ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED
typedef struct godot_plane {
uint8_t _dont_touch_that[16];
typedef struct {
uint8_t _dont_touch_that[GODOT_PLANE_SIZE];
} godot_plane;
#endif
#include "../godot.h"
#include "godot_vector3.h"
#include "gdnative.h"
#include "vector3.h"
void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d);
void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_pool_arrays.cpp */
/* pool_arrays.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,11 +27,15 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_pool_arrays.h"
#include "pool_arrays.h"
#include "array.h"
#include "core/variant.h"
#include "dvector.h"
#include "variant.h"
#include "core/color.h"
#include "core/math/math_2d.h"
#include "core/math/vector3.h"
#ifdef __cplusplus
extern "C" {

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_pool_arrays.h */
/* pool_arrays.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -38,66 +38,87 @@ extern "C" {
/////// PoolByteArray
#define GODOT_POOL_BYTE_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED
typedef struct godot_pool_byte_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_BYTE_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_BYTE_ARRAY_SIZE];
} godot_pool_byte_array;
#endif
/////// PoolIntArray
#define GODOT_POOL_INT_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED
typedef struct godot_pool_int_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_INT_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_INT_ARRAY_SIZE];
} godot_pool_int_array;
#endif
/////// PoolRealArray
#define GODOT_POOL_REAL_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED
typedef struct godot_pool_real_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_REAL_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_REAL_ARRAY_SIZE];
} godot_pool_real_array;
#endif
/////// PoolStringArray
#define GODOT_POOL_STRING_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED
typedef struct godot_pool_string_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_STRING_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_STRING_ARRAY_SIZE];
} godot_pool_string_array;
#endif
/////// PoolVector2Array
#define GODOT_POOL_VECTOR2_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED
typedef struct godot_pool_vector2_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_VECTOR2_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_VECTOR2_ARRAY_SIZE];
} godot_pool_vector2_array;
#endif
/////// PoolVector3Array
#define GODOT_POOL_VECTOR3_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED
typedef struct godot_pool_vector3_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_VECTOR3_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_VECTOR3_ARRAY_SIZE];
} godot_pool_vector3_array;
#endif
/////// PoolColorArray
#define GODOT_POOL_COLOR_ARRAY_SIZE 8
#ifndef GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED
typedef struct godot_pool_color_array {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_POOL_COLOR_ARRAY_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_POOL_COLOR_ARRAY_SIZE];
} godot_pool_color_array;
#endif
#include "godot_array.h"
#include "godot_color.h"
#include "godot_vector2.h"
#include "godot_vector3.h"
#include "array.h"
#include "color.h"
#include "vector2.h"
#include "vector3.h"
#include "../godot.h"
#include "gdnative.h"
// byte

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_quat.cpp */
/* quat.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_quat.h"
#include "quat.h"
#include "core/variant.h"
#include "core/math/quat.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_quat.h */
/* quat.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,15 +36,17 @@ extern "C" {
#include <stdint.h>
#define GODOT_QUAT_SIZE 16
#ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED
typedef struct godot_quat {
uint8_t _dont_touch_that[16];
typedef struct {
uint8_t _dont_touch_that[GODOT_QUAT_SIZE];
} godot_quat;
#endif
#include "../godot.h"
#include "godot_vector3.h"
#include "gdnative.h"
#include "vector3.h"
void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w);
void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_rect2.cpp */
/* rect2.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_rect2.h"
#include "rect2.h"
#include "core/variant.h"
#include "core/math/math_2d.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_rect2.h */
/* rect2.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -43,8 +43,8 @@ typedef struct godot_rect2 {
} godot_rect2;
#endif
#include "../godot.h"
#include "godot_vector2.h"
#include "gdnative.h"
#include "vector2.h"
void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size);
void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_rect3.cpp */
/* rect3.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_rect3.h"
#include "rect3.h"
#include "core/variant.h"
#include "core/math/rect3.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_rect3.h */
/* rect3.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,16 +36,18 @@ extern "C" {
#include <stdint.h>
#define GODOT_RECT3_SIZE 24
#ifndef GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED
typedef struct godot_rect3 {
uint8_t _dont_touch_that[24];
typedef struct {
uint8_t _dont_touch_that[GODOT_RECT3_SIZE];
} godot_rect3;
#endif
#include "../godot.h"
#include "godot_plane.h"
#include "godot_vector3.h"
#include "gdnative.h"
#include "plane.h"
#include "vector3.h"
void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_rid.cpp */
/* rid.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_rid.h"
#include "rid.h"
#include "core/variant.h"
#include "core/resource.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_rid.h */
/* rid.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,14 +36,16 @@ extern "C" {
#include <stdint.h>
#define GODOT_RID_SIZE 8
#ifndef GODOT_CORE_API_GODOT_RID_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_RID_TYPE_DEFINED
typedef struct godot_rid {
uint8_t _dont_touch_that[8];
typedef struct {
uint8_t _dont_touch_that[GODOT_RID_SIZE];
} godot_rid;
#endif
#include "../godot.h"
#include "gdnative.h"
void GDAPI godot_rid_new(godot_rid *r_dest);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_string.cpp */
/* string.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_string.h"
#include "string.h"
#include "string_db.h"
#include "ustring.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_string.h */
/* string.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -37,13 +37,16 @@ extern "C" {
#include <stdint.h>
#include <wchar.h>
#define GODOT_STRING_SIZE 8
#ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED
typedef struct godot_string {
uint8_t _dont_touch_that[8];
#define GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_STRING_SIZE];
} godot_string;
#endif
#include "../godot.h"
#include "gdnative.h"
void GDAPI godot_string_new(godot_string *r_dest);
void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_transform.cpp */
/* transform.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_transform.h"
#include "transform.h"
#include "core/variant.h"
#include "core/math/transform.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_transform.h */
/* transform.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,17 +36,19 @@ extern "C" {
#include <stdint.h>
#define GODOT_TRANSFORM_SIZE 48
#ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED
typedef struct godot_transform {
uint8_t _dont_touch_that[48];
typedef struct {
uint8_t _dont_touch_that[GODOT_TRANSFORM_SIZE];
} godot_transform;
#endif
#include "../godot.h"
#include "godot_basis.h"
#include "godot_variant.h"
#include "godot_vector3.h"
#include "basis.h"
#include "gdnative.h"
#include "variant.h"
#include "vector3.h"
void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin);
void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_transform2d.cpp */
/* transform2d.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_transform2d.h"
#include "transform2d.h"
#include "core/variant.h"
#include "core/math/math_2d.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_transform2d.h */
/* transform2d.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,16 +36,18 @@ extern "C" {
#include <stdint.h>
#define GODOT_TRANSFORM2D_SIZE 24
#ifndef GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED
typedef struct godot_transform2d {
uint8_t _dont_touch_that[24];
typedef struct {
uint8_t _dont_touch_that[GODOT_TRANSFORM2D_SIZE];
} godot_transform2d;
#endif
#include "../godot.h"
#include "godot_variant.h"
#include "godot_vector2.h"
#include "gdnative.h"
#include "variant.h"
#include "vector2.h"
void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos);
void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_variant.cpp */
/* variant.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_variant.h"
#include "variant.h"
#include "core/variant.h"
#ifdef __cplusplus

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_variant.h */
/* variant.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,9 +36,12 @@ extern "C" {
#include <stdint.h>
#define GODOT_VARIANT_SIZE 24
#ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED
typedef struct godot_variant {
uint8_t _dont_touch_that[24];
#define GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED
typedef struct {
uint8_t _dont_touch_that[GODOT_VARIANT_SIZE];
} godot_variant;
#endif
@ -96,25 +99,25 @@ typedef struct godot_variant_call_error {
godot_variant_type expected;
} godot_variant_call_error;
#include "godot_array.h"
#include "godot_basis.h"
#include "godot_color.h"
#include "godot_dictionary.h"
#include "godot_node_path.h"
#include "godot_plane.h"
#include "godot_pool_arrays.h"
#include "godot_quat.h"
#include "godot_rect2.h"
#include "godot_rect3.h"
#include "godot_rid.h"
#include "godot_string.h"
#include "godot_transform.h"
#include "godot_transform2d.h"
#include "godot_variant.h"
#include "godot_vector2.h"
#include "godot_vector3.h"
#include "array.h"
#include "basis.h"
#include "color.h"
#include "dictionary.h"
#include "node_path.h"
#include "plane.h"
#include "pool_arrays.h"
#include "quat.h"
#include "rect2.h"
#include "rect3.h"
#include "rid.h"
#include "string.h"
#include "transform.h"
#include "transform2d.h"
#include "variant.h"
#include "vector2.h"
#include "vector3.h"
#include "../godot.h"
#include "gdnative.h"
godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_vector2.cpp */
/* vector2.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_vector2.h"
#include "vector2.h"
#include "core/variant.h"
#include "core/math/math_2d.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_vector2.h */
/* vector2.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,14 +36,16 @@ extern "C" {
#include <stdint.h>
#define GODOT_VECTOR2_SIZE 8
#ifndef GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED
typedef struct godot_vector2 {
uint8_t _dont_touch_that[8];
typedef struct {
uint8_t _dont_touch_that[GODOT_VECTOR2_SIZE];
} godot_vector2;
#endif
#include "../godot.h"
#include "gdnative.h"
void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y);

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_vector3.cpp */
/* vector3.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -27,7 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "godot_vector3.h"
#include "vector3.h"
#include "core/variant.h"
#include "core/vector.h"

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* godot_vector3.h */
/* vector3.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -36,15 +36,17 @@ extern "C" {
#include <stdint.h>
#define GODOT_VECTOR3_SIZE 12
#ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED
#define GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED
typedef struct godot_vector3 {
uint8_t _dont_touch_that[12];
typedef struct {
uint8_t _dont_touch_that[GODOT_VECTOR3_SIZE];
} godot_vector3;
#endif
#include "../godot.h"
#include "godot_basis.h"
#include "basis.h"
#include "gdnative.h"
typedef enum {
GODOT_VECTOR3_AXIS_X,

View file

@ -33,34 +33,46 @@
#include "io/resource_loader.h"
#include "io/resource_saver.h"
GDNativeScriptLanguage *script_language_gdn = NULL;
ResourceFormatLoaderGDNativeScript *resource_loader_gdn = NULL;
ResourceFormatSaverGDNativeScript *resource_saver_gdn = NULL;
//ResourceFormatLoaderDLLibrary *resource_loader_dllib=NULL;
#include "core/os/os.h"
godot_variant cb_standard_varcall(void *handle, godot_string *p_procedure, godot_array *p_args) {
if (handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
godot_variant ret;
godot_variant_new_nil(&ret);
return ret;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
handle,
*(String *)p_procedure,
library_proc);
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_procedure) + "\" does not exists and can't be called").utf8().get_data());
godot_variant ret;
godot_variant_new_nil(&ret);
return ret;
}
godot_gdnative_procedure_fn proc;
proc = (godot_gdnative_procedure_fn)library_proc;
return proc(NULL, p_args);
}
GDNativeCallRegistry *GDNativeCallRegistry::singleton;
void register_gdnative_types() {
ClassDB::register_class<GDNativeLibrary>();
ClassDB::register_class<GDNativeScript>();
ClassDB::register_class<GDNative>();
script_language_gdn = memnew(GDNativeScriptLanguage);
ScriptServer::register_language(script_language_gdn);
resource_loader_gdn = memnew(ResourceFormatLoaderGDNativeScript);
ResourceLoader::add_resource_format_loader(resource_loader_gdn);
resource_saver_gdn = memnew(ResourceFormatSaverGDNativeScript);
ResourceSaver::add_resource_format_saver(resource_saver_gdn);
GDNativeCallRegistry::singleton = memnew(GDNativeCallRegistry);
GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall);
}
void unregister_gdnative_types() {
ScriptServer::unregister_language(script_language_gdn);
if (script_language_gdn)
memdelete(script_language_gdn);
if (resource_loader_gdn)
memdelete(resource_loader_gdn);
if (resource_saver_gdn)
memdelete(resource_saver_gdn);
memdelete(GDNativeCallRegistry::singleton);
}

View file

@ -0,0 +1,10 @@
#!/usr/bin/env python
Import('env')
mod_env = env.Clone()
mod_env.add_source_files(env.modules_sources, "*.cpp")
mod_env.Append(CPPPATH='#modules/gdnative')
mod_env.Append(CPPFLAGS=['-DGDAPI_BUILT_IN'])
Export('mod_env')

View file

@ -0,0 +1,8 @@
def can_build(platform):
return True
def configure(env):
env.use_ptrcall = True

View file

@ -0,0 +1,205 @@
/*************************************************************************/
/* godot_nativescript.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 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_nativescript.h"
#include "nativescript.h"
#include "class_db.h"
#include "error_macros.h"
#include "gdnative.h"
#include "global_constants.h"
#include "project_settings.h"
#include "variant.h"
#ifdef __cplusplus
extern "C" {
#endif
extern "C" void _native_script_hook() {
}
#define NSL NativeScriptLanguage::get_singleton()
// Script API
void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s];
NativeScriptDesc desc;
desc.create_func = p_create_func;
desc.destroy_func = p_destroy_func;
desc.is_tool = false;
desc.base = p_base;
if (classes->has(p_base)) {
desc.base_data = &(*classes)[p_base];
desc.base_native_type = desc.base_data->base_native_type;
} else {
desc.base_data = NULL;
desc.base_native_type = p_base;
}
classes->insert(p_name, desc);
}
void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s];
NativeScriptDesc desc;
desc.create_func = p_create_func;
desc.destroy_func = p_destroy_func;
desc.is_tool = true;
desc.base = p_base;
if (classes->has(p_base)) {
desc.base_data = &(*classes)[p_base];
desc.base_native_type = desc.base_data->base_native_type;
} else {
desc.base_data = NULL;
desc.base_native_type = p_base;
}
classes->insert(p_name, desc);
}
void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
if (!E) {
ERR_EXPLAIN("Attempt to register method on non-existant class!");
ERR_FAIL();
}
NativeScriptDesc::Method method;
method.method = p_method;
method.rpc_mode = p_attr.rpc_type;
method.info = MethodInfo(p_function_name);
E->get().methods.insert(p_function_name, method);
}
void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
if (!E) {
ERR_EXPLAIN("Attempt to register method on non-existant class!");
ERR_FAIL();
}
NativeScriptDesc::Property property;
property.default_value = *(Variant *)&p_attr->default_value;
property.getter = p_get_func;
property.rset_mode = p_attr->rset_type;
property.setter = p_set_func;
property.info = PropertyInfo((Variant::Type)p_attr->type,
p_path,
(PropertyHint)p_attr->hint,
*(String *)&p_attr->hint_string,
(PropertyUsageFlags)p_attr->usage);
E->get().properties.insert(p_path, property);
}
void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) {
String *s = (String *)p_gdnative_handle;
Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);
if (!E) {
ERR_EXPLAIN("Attempt to register method on non-existant class!");
ERR_FAIL();
}
List<PropertyInfo> args;
Vector<Variant> default_args;
for (int i = 0; i < p_signal->num_args; i++) {
PropertyInfo info;
godot_signal_argument arg = p_signal->args[i];
info.hint = (PropertyHint)arg.hint;
info.hint_string = *(String *)&arg.hint_string;
info.name = *(String *)&arg.name;
info.type = (Variant::Type)arg.type;
info.usage = (PropertyUsageFlags)arg.usage;
args.push_back(info);
}
for (int i = 0; i < p_signal->num_default_args; i++) {
Variant *v;
godot_signal_argument attrib = p_signal->args[i];
v = (Variant *)&attrib.default_value;
default_args.push_back(*v);
}
MethodInfo method_info;
method_info.name = *(String *)&p_signal->name;
method_info.arguments = args;
method_info.default_arguments = default_args;
NativeScriptDesc::Signal signal;
signal.signal = method_info;
E->get().signals_.insert(*(String *)&p_signal->name, signal);
}
void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) {
Object *instance = (Object *)p_instance;
if (!instance)
return NULL;
if (instance->get_script_instance() && instance->get_script_instance()->get_language() == NativeScriptLanguage::get_singleton()) {
// return ((NativeScriptInstance *)instance->get_script_instance())->get_userdata();
}
return NULL;
}
#ifdef __cplusplus
}
#endif

View file

@ -27,8 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef GODOT_C_H
#define GODOT_C_H
#ifndef GODOT_NATIVESCRIPT_H
#define GODOT_NATIVESCRIPT_H
#include <godot/gdnative.h>
#ifdef __cplusplus
extern "C" {
@ -70,203 +72,7 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#define GODOT_API_VERSION 1
////// Error
typedef enum godot_error {
GODOT_OK,
GODOT_FAILED, ///< Generic fail error
GODOT_ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
GODOT_ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet
GODOT_ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
GODOT_ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
GODOT_ERR_OUT_OF_MEMORY, ///< Out of memory
GODOT_ERR_FILE_NOT_FOUND,
GODOT_ERR_FILE_BAD_DRIVE,
GODOT_ERR_FILE_BAD_PATH,
GODOT_ERR_FILE_NO_PERMISSION, // (10)
GODOT_ERR_FILE_ALREADY_IN_USE,
GODOT_ERR_FILE_CANT_OPEN,
GODOT_ERR_FILE_CANT_WRITE,
GODOT_ERR_FILE_CANT_READ,
GODOT_ERR_FILE_UNRECOGNIZED, // (15)
GODOT_ERR_FILE_CORRUPT,
GODOT_ERR_FILE_MISSING_DEPENDENCIES,
GODOT_ERR_FILE_EOF,
GODOT_ERR_CANT_OPEN, ///< Can't open a resource/socket/file
GODOT_ERR_CANT_CREATE, // (20)
GODOT_ERR_QUERY_FAILED,
GODOT_ERR_ALREADY_IN_USE,
GODOT_ERR_LOCKED, ///< resource is locked
GODOT_ERR_TIMEOUT,
GODOT_ERR_CANT_CONNECT, // (25)
GODOT_ERR_CANT_RESOLVE,
GODOT_ERR_CONNECTION_ERROR,
GODOT_ERR_CANT_AQUIRE_RESOURCE,
GODOT_ERR_CANT_FORK,
GODOT_ERR_INVALID_DATA, ///< Data passed is invalid (30)
GODOT_ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
GODOT_ERR_ALREADY_EXISTS, ///< When adding, item already exists
GODOT_ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
GODOT_ERR_DATABASE_CANT_READ, ///< database is full
GODOT_ERR_DATABASE_CANT_WRITE, ///< database is full (35)
GODOT_ERR_COMPILATION_FAILED,
GODOT_ERR_METHOD_NOT_FOUND,
GODOT_ERR_LINK_FAILED,
GODOT_ERR_SCRIPT_FAILED,
GODOT_ERR_CYCLIC_LINK, // (40)
GODOT_ERR_INVALID_DECLARATION,
GODOT_ERR_DUPLICATE_SYMBOL,
GODOT_ERR_PARSE_ERROR,
GODOT_ERR_BUSY,
GODOT_ERR_SKIP, // (45)
GODOT_ERR_HELP, ///< user requested help!!
GODOT_ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
GODOT_ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
GODOT_ERR_WTF = GODOT_ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
} godot_error;
////// bool
typedef bool godot_bool;
#define GODOT_TRUE 1
#define GODOT_FALSE 0
/////// int
typedef int godot_int;
/////// real
typedef float godot_real;
/////// Object (forward declared)
typedef void godot_object;
/////// Brute force forward declarations for the rest
typedef struct godot_variant godot_variant;
typedef struct godot_string godot_string;
typedef struct godot_vector2 godot_vector2;
typedef struct godot_rect2 godot_rect2;
typedef struct godot_vector3 godot_vector3;
typedef struct godot_transform2d godot_transform2d;
typedef struct godot_plane godot_plane;
typedef struct godot_quat godot_quat;
typedef struct godot_rect3 godot_rect3;
typedef struct godot_basis godot_basis;
typedef struct godot_transform godot_transform;
typedef struct godot_color godot_color;
typedef struct godot_node_path godot_node_path;
typedef struct godot_rid godot_rid;
typedef struct godot_dictionary godot_dictionary;
typedef struct godot_array godot_array;
typedef struct godot_pool_byte_array godot_pool_byte_array;
typedef struct godot_pool_int_array godot_pool_int_array;
typedef struct godot_pool_real_array godot_pool_real_array;
typedef struct godot_pool_string_array godot_pool_string_array;
typedef struct godot_pool_vector2_array godot_pool_vector2_array;
typedef struct godot_pool_vector3_array godot_pool_vector3_array;
typedef struct godot_pool_color_array godot_pool_color_array;
/////// String
#include "godot/godot_string.h"
////// Vector2
#include "godot/godot_vector2.h"
////// Rect2
#include "godot/godot_rect2.h"
////// Vector3
#include "godot/godot_vector3.h"
////// Transform2D
#include "godot/godot_transform2d.h"
/////// Plane
#include "godot/godot_plane.h"
/////// Quat
#include "godot/godot_quat.h"
/////// Rect3
#include "godot/godot_rect3.h"
/////// Basis
#include "godot/godot_basis.h"
/////// Transform
#include "godot/godot_transform.h"
/////// Color
#include "godot/godot_color.h"
/////// NodePath
#include "godot/godot_node_path.h"
/////// RID
#include "godot/godot_rid.h"
/////// Dictionary
#include "godot/godot_dictionary.h"
/////// Array
#include "godot/godot_array.h"
// single API file for Pool*Array
#include "godot/godot_pool_arrays.h"
void GDAPI godot_object_destroy(godot_object *p_o);
////// Variant
#include "godot/godot_variant.h"
////// Singleton API
godot_object GDAPI *godot_global_get_singleton(char *p_name); // result shouldn't be freed
////// MethodBind API
typedef struct godot_method_bind {
uint8_t _dont_touch_that[1]; // TODO
} godot_method_bind;
godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname);
void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret);
godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error);
////// Script API
typedef struct godot_native_init_options {
godot_bool in_editor;
uint64_t core_api_hash;
uint64_t editor_api_hash;
uint64_t no_api_hash;
} godot_native_init_options;
typedef struct godot_native_terminate_options {
godot_bool in_editor;
} godot_native_terminate_options;
typedef enum godot_method_rpc_mode {
typedef enum {
GODOT_METHOD_RPC_MODE_DISABLED,
GODOT_METHOD_RPC_MODE_REMOTE,
GODOT_METHOD_RPC_MODE_SYNC,
@ -274,11 +80,7 @@ typedef enum godot_method_rpc_mode {
GODOT_METHOD_RPC_MODE_SLAVE,
} godot_method_rpc_mode;
typedef struct godot_method_attributes {
godot_method_rpc_mode rpc_type;
} godot_method_attributes;
typedef enum godot_property_hint {
typedef enum {
GODOT_PROPERTY_HINT_NONE, ///< no hint provided.
GODOT_PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional"
GODOT_PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit
@ -315,7 +117,7 @@ typedef enum godot_property_hint {
GODOT_PROPERTY_HINT_MAX,
} godot_property_hint;
typedef enum godot_property_usage_flags {
typedef enum {
GODOT_PROPERTY_USAGE_STORAGE = 1,
GODOT_PROPERTY_USAGE_EDITOR = 2,
@ -340,7 +142,7 @@ typedef enum godot_property_usage_flags {
GODOT_PROPERTY_USAGE_NOEDITOR = GODOT_PROPERTY_USAGE_STORAGE | GODOT_PROPERTY_USAGE_NETWORK,
} godot_property_usage_flags;
typedef struct godot_property_attributes {
typedef struct {
godot_method_rpc_mode rset_type;
godot_int type;
@ -350,50 +152,54 @@ typedef struct godot_property_attributes {
godot_variant default_value;
} godot_property_attributes;
typedef struct godot_instance_create_func {
typedef struct {
// instance pointer, method_data - return user data
GDCALLINGCONV void *(*create_func)(godot_object *, void *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_create_func;
typedef struct godot_instance_destroy_func {
typedef struct {
// instance pointer, method data, user data
GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_destroy_func;
void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func);
typedef struct godot_instance_method {
typedef struct {
godot_method_rpc_mode rpc_type;
} godot_method_attributes;
typedef struct {
// instance pointer, method data, user data, num args, args - return result as varaint
GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_instance_method;
void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method);
void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method);
typedef struct godot_property_set_func {
typedef struct {
// instance pointer, method data, user data, value
GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant);
GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_property_set_func;
typedef struct godot_property_get_func {
typedef struct {
// instance pointer, method data, user data, value
GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *);
void *method_data;
GDCALLINGCONV void (*free_func)(void *);
} godot_property_get_func;
void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func);
void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func);
typedef struct godot_signal_argument {
typedef struct {
godot_string name;
godot_int type;
godot_property_hint hint;
@ -402,7 +208,7 @@ typedef struct godot_signal_argument {
godot_variant default_value;
} godot_signal_argument;
typedef struct godot_signal {
typedef struct {
godot_string name;
int num_args;
godot_signal_argument *args;
@ -410,31 +216,12 @@ typedef struct godot_signal {
godot_variant *default_args;
} godot_signal;
void GDAPI godot_script_register_signal(const char *p_name, const godot_signal *p_signal);
void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal);
void GDAPI *godot_native_get_userdata(godot_object *p_instance);
// Calling convention?
typedef godot_object *(*godot_class_constructor)();
godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname);
godot_dictionary GDAPI godot_get_global_constants();
////// System Functions
//using these will help Godot track how much memory is in use in debug mode
void GDAPI *godot_alloc(int p_bytes);
void GDAPI *godot_realloc(void *p_ptr, int p_bytes);
void GDAPI godot_free(void *p_ptr);
//print using Godot's error handler list
void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
void GDAPI godot_print(const godot_string *p_message);
void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance);
#ifdef __cplusplus
}
#endif
#endif // GODOT_C_H
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,281 @@
/*************************************************************************/
/* nativescript.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 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. */
/*************************************************************************/
#ifndef NATIVE_SCRIPT_H
#define NATIVE_SCRIPT_H
#include "io/resource_loader.h"
#include "io/resource_saver.h"
#include "os/thread_safe.h"
#include "resource.h"
#include "scene/main/node.h"
#include "script_language.h"
#include "self_list.h"
#include "godot_nativescript.h"
#include "modules/gdnative/gdnative.h"
struct NativeScriptDesc {
struct Method {
godot_instance_method method;
MethodInfo info;
int rpc_mode;
};
struct Property {
godot_property_set_func setter;
godot_property_get_func getter;
PropertyInfo info;
Variant default_value;
int rset_mode;
};
struct Signal {
MethodInfo signal;
};
Map<StringName, Method> methods;
Map<StringName, Property> properties;
Map<StringName, Signal> signals_; // QtCreator doesn't like the name signals
StringName base;
StringName base_native_type;
NativeScriptDesc *base_data;
godot_instance_create_func create_func;
godot_instance_destroy_func destroy_func;
bool is_tool;
inline NativeScriptDesc()
: methods(),
properties(),
signals_(),
base(),
base_native_type() {
zeromem(&create_func, sizeof(godot_instance_create_func));
zeromem(&destroy_func, sizeof(godot_instance_destroy_func));
}
};
class NativeScript : public Script {
GDCLASS(NativeScript, Script)
#ifdef TOOLS_ENABLED
Set<PlaceHolderScriptInstance *> placeholders;
void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
#endif
friend class NativeScriptInstance;
friend class NativeScriptLanguage;
friend class NativeReloadNode;
friend class GDNativeLibrary;
Ref<GDNativeLibrary> library;
String lib_path;
String class_name;
Set<Object *> instance_owners;
protected:
static void _bind_methods();
public:
inline NativeScriptDesc *get_script_desc() const;
void set_class_name(String p_class_name);
String get_class_name() const;
void set_library(Ref<GDNativeLibrary> library);
Ref<GDNativeLibrary> get_library() const;
virtual bool can_instance() const;
virtual Ref<Script> get_base_script() const; //for script inheritance
virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so
virtual ScriptInstance *instance_create(Object *p_this);
virtual bool instance_has(const Object *p_this) const;
virtual bool has_source_code() const;
virtual String get_source_code() const;
virtual void set_source_code(const String &p_code);
virtual Error reload(bool p_keep_state = false);
virtual bool has_method(const StringName &p_method) const;
virtual MethodInfo get_method_info(const StringName &p_method) const;
virtual bool is_tool() const;
virtual String get_node_type() const;
virtual ScriptLanguage *get_language() const;
virtual bool has_script_signal(const StringName &p_signal) const;
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void update_exports(); //editor tool
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
NativeScript();
~NativeScript();
};
class NativeScriptInstance : public ScriptInstance {
friend class NativeScript;
Object *owner;
Ref<NativeScript> script;
void *userdata;
void _ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount);
public:
virtual bool set(const StringName &p_name, const Variant &p_value);
virtual bool get(const StringName &p_name, Variant &r_ret) const;
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const;
virtual void get_method_list(List<MethodInfo> *p_list) const;
virtual bool has_method(const StringName &p_method) const;
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
virtual void notification(int p_notification);
virtual Ref<Script> get_script() const;
virtual RPCMode get_rpc_mode(const StringName &p_method) const;
virtual RPCMode get_rset_mode(const StringName &p_variable) const;
virtual ScriptLanguage *get_language();
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
~NativeScriptInstance();
};
class NativeReloadNode;
class NativeScriptLanguage : public ScriptLanguage {
friend class NativeScript;
friend class NativeScriptInstance;
friend class NativeReloadNode;
private:
static NativeScriptLanguage *singleton;
void _unload_stuff();
public:
Map<String, Map<StringName, NativeScriptDesc> > library_classes;
Map<String, Ref<GDNative> > library_gdnatives;
Map<String, Set<NativeScript *> > library_script_users;
const StringName _init_call_type = "nativescript_init";
const StringName _init_call_name = "godot_nativescript_init";
NativeScriptLanguage();
~NativeScriptLanguage();
inline static NativeScriptLanguage *get_singleton() {
return singleton;
}
void _hacky_api_anchor();
virtual String get_name() const;
virtual void init();
virtual String get_type() const;
virtual String get_extension() const;
virtual Error execute_file(const String &p_path);
virtual void finish();
virtual void get_reserved_words(List<String> *p_words) const;
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
virtual void get_string_delimiters(List<String> *p_delimiters) const;
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const;
virtual Script *create_script() const;
virtual bool has_named_classes() const;
virtual int find_function(const String &p_function, const String &p_code) const;
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
virtual String debug_get_error() const;
virtual int debug_get_stack_level_count() const;
virtual int debug_get_stack_level_line(int p_level) const;
virtual String debug_get_stack_level_function(int p_level) const;
virtual String debug_get_stack_level_source(int p_level) const;
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth);
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth);
virtual void reload_all_scripts();
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
virtual void get_public_constants(List<Pair<String, Variant> > *p_constants) const;
virtual void profiling_start();
virtual void profiling_stop();
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
};
inline NativeScriptDesc *NativeScript::get_script_desc() const {
Map<StringName, NativeScriptDesc>::Element *E = NativeScriptLanguage::singleton->library_classes[lib_path].find(class_name);
return E ? &E->get() : NULL;
}
class NativeReloadNode : public Node {
GDCLASS(NativeReloadNode, Node)
public:
static void _bind_methods();
void _notification(int p_what);
};
class ResourceFormatLoaderNativeScript : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
class ResourceFormatSaverNativeScript : public ResourceFormatSaver {
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual bool recognize(const RES &p_resource) const;
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
};
#endif // GDNATIVE_H

View file

@ -0,0 +1,93 @@
/*************************************************************************/
/* register_types.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 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 "register_types.h"
#include "io/resource_loader.h"
#include "io/resource_saver.h"
#include "nativescript.h"
#include "core/os/os.h"
NativeScriptLanguage *native_script_language;
typedef void (*native_script_init_fn)(void *);
void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call nativescript init procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc);
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
native_script_init_fn fn = (native_script_init_fn)library_proc;
fn(args[0]);
}
ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL;
ResourceFormatSaverNativeScript *resource_saver_gdns = NULL;
void register_nativescript_types() {
native_script_language = memnew(NativeScriptLanguage);
ClassDB::register_class<NativeScript>();
ScriptServer::register_language(native_script_language);
GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_init_call_type, init_call_cb);
resource_saver_gdns = memnew(ResourceFormatSaverNativeScript);
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
resource_loader_gdns = memnew(ResourceFormatLoaderNativeScript);
ResourceLoader::add_resource_format_loader(resource_loader_gdns);
}
void unregister_nativescript_types() {
memdelete(resource_loader_gdns);
memdelete(resource_saver_gdns);
if (native_script_language) {
ScriptServer::unregister_language(native_script_language);
memdelete(native_script_language);
}
}

View file

@ -0,0 +1,31 @@
/*************************************************************************/
/* register_types.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 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. */
/*************************************************************************/
void register_nativescript_types();
void unregister_nativescript_types();