summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-04-09 19:40:54 +0200
committerGitHub <noreply@github.com>2017-04-09 19:40:54 +0200
commit0198d2e03cfb8506e4a5c0f45efc43a1ac5d8d1a (patch)
tree6013e22d457a302761679b2f8cc916a06a5cb282
parentcd9e96c83539191a69be81e74071a8edaf9d9cf1 (diff)
parentb423529481f2d4dbe2b6926b469b802dc9bb50e3 (diff)
Merge pull request #8329 from touilleMan/dlscript-godot_get_global_constants
GlobalConstants support in DLScript & api.json
-rw-r--r--modules/dlscript/api_generator.cpp18
-rw-r--r--modules/dlscript/godot.cpp14
-rw-r--r--modules/dlscript/godot.h2
3 files changed, 34 insertions, 0 deletions
diff --git a/modules/dlscript/api_generator.cpp b/modules/dlscript/api_generator.cpp
index 56e0e45608..1de3f6d520 100644
--- a/modules/dlscript/api_generator.cpp
+++ b/modules/dlscript/api_generator.cpp
@@ -4,6 +4,7 @@
#include "class_db.h"
#include "core/global_config.h"
+#include "core/global_constants.h"
#include "os/file_access.h"
// helper stuff
@@ -92,6 +93,23 @@ List<ClassAPI> generate_c_api_classes() {
List<StringName> classes;
ClassDB::get_class_list(&classes);
+ // Register global constants as a fake GlobalConstants singleton class
+ {
+ ClassAPI global_constants_api;
+ global_constants_api.class_name = L"GlobalConstants";
+ global_constants_api.api_type = ClassDB::API_CORE;
+ global_constants_api.is_singleton = true;
+ global_constants_api.is_instanciable = false;
+ const int constants_count = GlobalConstants::get_global_constant_count();
+ for (int i = 0; i < constants_count; ++i) {
+ ConstantAPI constant_api;
+ constant_api.constant_name = GlobalConstants::get_global_constant_name(i);
+ constant_api.constant_value = GlobalConstants::get_global_constant_value(i);
+ global_constants_api.constants.push_back(constant_api);
+ }
+ api.push_back(global_constants_api);
+ }
+
for (List<StringName>::Element *e = classes.front(); e != NULL; e = e->next()) {
StringName class_name = e->get();
diff --git a/modules/dlscript/godot.cpp b/modules/dlscript/godot.cpp
index 478eb86c08..623f7f0149 100644
--- a/modules/dlscript/godot.cpp
+++ b/modules/dlscript/godot.cpp
@@ -32,6 +32,7 @@
#include "class_db.h"
#include "dl_script.h"
#include "global_config.h"
+#include "global_constants.h"
#include "variant.h"
#ifdef __cplusplus
@@ -181,6 +182,19 @@ void GDAPI *godot_dlinstance_get_userdata(godot_object *p_instance) {
return NULL;
}
+godot_dictionary GDAPI godot_get_global_constants() {
+ godot_dictionary constants;
+ godot_dictionary_new(&constants);
+ Dictionary *p_constants = (Dictionary*)&constants;
+ const int constants_count = GlobalConstants::get_global_constant_count();
+ for (int i = 0; i < constants_count; ++i) {
+ const char *name = GlobalConstants::get_global_constant_name(i);
+ int value = GlobalConstants::get_global_constant_value(i);
+ (*p_constants)[name] = value;
+ }
+ return constants;
+}
+
// System functions
void GDAPI *godot_alloc(int p_bytes) {
return memalloc(p_bytes);
diff --git a/modules/dlscript/godot.h b/modules/dlscript/godot.h
index 4a977ad8cb..124a752876 100644
--- a/modules/dlscript/godot.h
+++ b/modules/dlscript/godot.h
@@ -376,6 +376,8 @@ void GDAPI godot_script_register_signal(const char *p_name, const godot_signal *
void GDAPI *godot_dlinstance_get_userdata(godot_object *p_instance);
+godot_dictionary GDAPI godot_get_global_constants();
+
////// System Functions
//using these will help Godot track how much memory is in use in debug mode