2017-05-13 11:55:04 +00:00
|
|
|
#include "GodotGlobal.hpp"
|
|
|
|
|
|
|
|
#include "String.hpp"
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
2017-07-24 12:23:09 +00:00
|
|
|
void *_RegisterState::nativescript_handle;
|
2018-02-23 13:08:36 +00:00
|
|
|
const godot_gdnative_core_api_struct *api = nullptr;
|
|
|
|
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = nullptr;
|
2017-07-24 12:23:09 +00:00
|
|
|
|
2017-05-13 11:55:04 +00:00
|
|
|
void Godot::print(const String& message)
|
|
|
|
{
|
2017-10-20 23:42:10 +00:00
|
|
|
godot::api->godot_print((godot_string *) &message);
|
2017-05-13 11:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Godot::print_warning(const String& description, const String& function, const String& file, int line)
|
|
|
|
{
|
2017-11-23 11:50:05 +00:00
|
|
|
int len;
|
|
|
|
|
2017-11-24 22:54:35 +00:00
|
|
|
char * c_desc = description.alloc_c_string();
|
|
|
|
char * c_func = function.alloc_c_string();
|
|
|
|
char * c_file = file.alloc_c_string();
|
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
if (c_desc != nullptr && c_func !=nullptr && c_file != nullptr) {
|
2017-11-24 22:54:35 +00:00
|
|
|
godot::api->godot_print_warning(c_desc, c_func, c_file, line);
|
|
|
|
};
|
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
if (c_desc != nullptr) godot::api->godot_free(c_desc);
|
|
|
|
if (c_func != nullptr) godot::api->godot_free(c_func);
|
|
|
|
if (c_file != nullptr) godot::api->godot_free(c_file);
|
2017-05-13 11:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Godot::print_error(const String& description, const String& function, const String& file, int line)
|
|
|
|
{
|
2017-11-23 11:50:05 +00:00
|
|
|
int len;
|
|
|
|
|
2017-11-24 22:54:35 +00:00
|
|
|
char * c_desc = description.alloc_c_string();
|
|
|
|
char * c_func = function.alloc_c_string();
|
|
|
|
char * c_file = file.alloc_c_string();
|
2017-11-23 11:50:05 +00:00
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
if (c_desc != nullptr && c_func !=nullptr && c_file != nullptr) {
|
2017-11-24 22:54:35 +00:00
|
|
|
godot::api->godot_print_error(c_desc, c_func, c_file, line);
|
|
|
|
};
|
2017-11-23 11:50:05 +00:00
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
if (c_desc != nullptr) godot::api->godot_free(c_desc);
|
|
|
|
if (c_func != nullptr) godot::api->godot_free(c_func);
|
|
|
|
if (c_file != nullptr) godot::api->godot_free(c_file);
|
2017-05-13 11:55:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 16:57:52 +00:00
|
|
|
void Godot::gdnative_init(godot_gdnative_init_options *options)
|
2017-07-24 12:23:09 +00:00
|
|
|
{
|
2017-10-20 23:42:10 +00:00
|
|
|
godot::api = options->api_struct;
|
2017-11-23 11:50:05 +00:00
|
|
|
|
|
|
|
// now find our extensions
|
|
|
|
for (int i = 0; i < godot::api->num_extensions; i++) {
|
|
|
|
switch (godot::api->extensions[i]->type) {
|
|
|
|
case GDNATIVE_EXT_NATIVESCRIPT: {
|
|
|
|
godot::nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)godot::api->extensions[i];
|
|
|
|
}; break;
|
|
|
|
default: break;
|
|
|
|
};
|
|
|
|
};
|
2017-07-24 12:23:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 16:57:52 +00:00
|
|
|
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options)
|
2017-07-24 12:23:09 +00:00
|
|
|
{
|
2018-01-11 16:57:52 +00:00
|
|
|
// reserved for future use.
|
2017-07-24 12:23:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 16:57:52 +00:00
|
|
|
void Godot::nativescript_init(void *handle)
|
2017-07-24 12:23:09 +00:00
|
|
|
{
|
|
|
|
godot::_RegisterState::nativescript_handle = handle;
|
|
|
|
}
|
2018-01-11 16:57:52 +00:00
|
|
|
|
|
|
|
};
|