diff options
author | Ruslan Mustakov <r.mustakov@gmail.com> | 2017-08-23 13:33:31 +0700 |
---|---|---|
committer | Ruslan Mustakov <r.mustakov@gmail.com> | 2017-08-30 10:38:58 +0700 |
commit | bbb4ee90ce1682295420ba343fc750af6b6c8138 (patch) | |
tree | 52817af1dfe73b737ac719ba98d1195281d822ce | |
parent | efcafab6255ea78365e519ca3a13e9bf8b2a81d4 (diff) |
Add enums in GDNative API generator
-rw-r--r-- | modules/nativescript/api_generator.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/modules/nativescript/api_generator.cpp b/modules/nativescript/api_generator.cpp index 4490197bdb..ac26c8bf8b 100644 --- a/modules/nativescript/api_generator.cpp +++ b/modules/nativescript/api_generator.cpp @@ -33,6 +33,7 @@ #include "class_db.h" #include "core/global_constants.h" +#include "core/pair.h" #include "core/project_settings.h" #include "os/file_access.h" @@ -93,6 +94,11 @@ struct SignalAPI { Map<int, Variant> default_arguments; }; +struct EnumAPI { + String name; + List<Pair<int, String> > values; +}; + struct ClassAPI { String class_name; String super_class_name; @@ -109,6 +115,7 @@ struct ClassAPI { List<PropertyAPI> properties; List<ConstantAPI> constants; List<SignalAPI> signals_; + List<EnumAPI> enums; }; /* @@ -321,6 +328,25 @@ List<ClassAPI> generate_c_api_classes() { } } + // enums + { + List<EnumAPI> enums; + List<StringName> enum_names; + ClassDB::get_enum_list(class_name, &enum_names, true); + for (List<StringName>::Element *E = enum_names.front(); E; E = E->next()) { + List<StringName> value_names; + EnumAPI enum_api; + enum_api.name = E->get(); + ClassDB::get_enum_constants(class_name, E->get(), &value_names, true); + for (List<StringName>::Element *val_e = value_names.front(); val_e; val_e = val_e->next()) { + int int_val = ClassDB::get_integer_constant(class_name, val_e->get(), NULL); + enum_api.values.push_back(Pair<int, String>(int_val, val_e->get())); + } + enum_api.values.sort_custom<PairSort<int, String> >(); + class_api.enums.push_back(enum_api); + } + } + api.push_back(class_api); } @@ -410,11 +436,24 @@ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) { source.push_back("\t\t\t\t]\n"); source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); } + source.push_back("\t\t],\n"); + + source.push_back("\t\t\"enums\": [\n"); + for (List<EnumAPI>::Element *e = api.enums.front(); e; e = e->next()) { + source.push_back("\t\t\t{\n"); + source.push_back("\t\t\t\t\"name\": \"" + e->get().name + "\",\n"); + source.push_back("\t\t\t\t\"values\": {\n"); + for (List<Pair<int, String> >::Element *val_e = e->get().values.front(); val_e; val_e = val_e->next()) { + source.push_back("\t\t\t\t\t\"" + val_e->get().second + "\": " + itos(val_e->get().first)); + source.push_back(String((val_e->next() ? "," : "")) + "\n"); + } + source.push_back("\t\t\t\t}\n"); + source.push_back(String("\t\t\t}") + (e->next() ? "," : "") + "\n"); + } source.push_back("\t\t]\n"); source.push_back(String("\t}") + (c->next() ? "," : "") + "\n"); } - source.push_back("]"); return source; |