godot_pluginscript.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*************************************************************************/
  2. /* godot_pluginscript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GODOT_PLUGINSCRIPT_H
  31. #define GODOT_PLUGINSCRIPT_H
  32. #include <gdnative/gdnative.h>
  33. #include <nativescript/godot_nativescript.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. typedef void godot_pluginscript_instance_data;
  38. typedef void godot_pluginscript_script_data;
  39. typedef void godot_pluginscript_language_data;
  40. // --- Instance ---
  41. typedef struct {
  42. godot_pluginscript_instance_data *(*init)(godot_pluginscript_script_data *p_data, godot_object *p_owner);
  43. void (*finish)(godot_pluginscript_instance_data *p_data);
  44. godot_bool (*set_prop)(godot_pluginscript_instance_data *p_data, const godot_string_name *p_name, const godot_variant *p_value);
  45. godot_bool (*get_prop)(godot_pluginscript_instance_data *p_data, const godot_string_name *p_name, godot_variant *r_ret);
  46. godot_variant (*call_method)(godot_pluginscript_instance_data *p_data,
  47. const godot_string_name *p_method, const godot_variant **p_args,
  48. int p_argcount, godot_variant_call_error *r_error);
  49. void (*notification)(godot_pluginscript_instance_data *p_data, int p_notification);
  50. godot_string (*to_string)(godot_pluginscript_instance_data *p_data, godot_bool *r_valid);
  51. //this is used by script languages that keep a reference counter of their own
  52. //you can make make Ref<> not die when it reaches zero, so deleting the reference
  53. //depends entirely from the script.
  54. // Note: You can set those function pointer to nullptr if not needed.
  55. void (*refcount_incremented)(godot_pluginscript_instance_data *p_data);
  56. bool (*refcount_decremented)(godot_pluginscript_instance_data *p_data); // return true if it can die
  57. } godot_pluginscript_instance_desc;
  58. // --- Script ---
  59. typedef struct {
  60. godot_pluginscript_script_data *data;
  61. godot_string_name name;
  62. godot_bool is_tool;
  63. godot_string_name base;
  64. godot_string icon_path;
  65. // Member lines format: {<string>: <int>}
  66. godot_dictionary member_lines;
  67. // Method info dictionary format
  68. // {
  69. // name: <string>
  70. // args: [<dict:property>]
  71. // default_args: [<variant>]
  72. // return: <dict:property>
  73. // flags: <int>
  74. // rpc_mode: <int:godot_method_rpc_mode>
  75. // }
  76. godot_array methods;
  77. // Same format than for methods
  78. godot_array signals;
  79. // Property info dictionary format
  80. // {
  81. // name: <string>
  82. // type: <int:godot_variant_type>
  83. // hint: <int:godot_property_hint>
  84. // hint_string: <string>
  85. // usage: <int:godot_property_usage_flags>
  86. // default_value: <variant>
  87. // rset_mode: <int:godot_method_rpc_mode>
  88. // }
  89. godot_array properties;
  90. } godot_pluginscript_script_manifest;
  91. typedef struct {
  92. godot_pluginscript_script_manifest (*init)(godot_pluginscript_language_data *p_data, const godot_string *p_path, const godot_string *p_source, godot_error *r_error);
  93. void (*finish)(godot_pluginscript_script_data *p_data);
  94. godot_pluginscript_instance_desc instance_desc;
  95. } godot_pluginscript_script_desc;
  96. // --- Language ---
  97. typedef struct {
  98. godot_string_name signature;
  99. godot_int call_count;
  100. godot_int total_time; // In microseconds
  101. godot_int self_time; // In microseconds
  102. } godot_pluginscript_profiling_data;
  103. typedef struct {
  104. const char *name;
  105. const char *type;
  106. const char *extension;
  107. const char **recognized_extensions; // nullptr terminated array
  108. godot_pluginscript_language_data *(*init)();
  109. void (*finish)(godot_pluginscript_language_data *p_data);
  110. const char **reserved_words; // nullptr terminated array
  111. const char **comment_delimiters; // nullptr terminated array
  112. const char **string_delimiters; // nullptr terminated array
  113. godot_bool has_named_classes;
  114. godot_bool supports_builtin_mode;
  115. godot_bool can_inherit_from_file;
  116. godot_string (*get_template_source_code)(godot_pluginscript_language_data *p_data, const godot_string *p_class_name, const godot_string *p_base_class_name);
  117. godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, const godot_string *p_path, godot_packed_string_array *r_functions, godot_array *r_errors); // errors = Array of Dictionary with "line", "column", "message" keys
  118. int (*find_function)(godot_pluginscript_language_data *p_data, const godot_string *p_function, const godot_string *p_code); // Can be nullptr
  119. godot_string (*make_function)(godot_pluginscript_language_data *p_data, const godot_string *p_class, const godot_string *p_name, const godot_packed_string_array *p_args);
  120. godot_error (*complete_code)(godot_pluginscript_language_data *p_data, const godot_string *p_code, const godot_string *p_path, godot_object *p_owner, godot_array *r_options, godot_bool *r_force, godot_string *r_call_hint);
  121. void (*auto_indent_code)(godot_pluginscript_language_data *p_data, godot_string *p_code, int p_from_line, int p_to_line);
  122. void (*add_global_constant)(godot_pluginscript_language_data *p_data, const godot_string_name *p_variable, const godot_variant *p_value);
  123. godot_string (*debug_get_error)(godot_pluginscript_language_data *p_data);
  124. int (*debug_get_stack_level_count)(godot_pluginscript_language_data *p_data);
  125. int (*debug_get_stack_level_line)(godot_pluginscript_language_data *p_data, int p_level);
  126. godot_string (*debug_get_stack_level_function)(godot_pluginscript_language_data *p_data, int p_level);
  127. godot_string (*debug_get_stack_level_source)(godot_pluginscript_language_data *p_data, int p_level);
  128. void (*debug_get_stack_level_locals)(godot_pluginscript_language_data *p_data, int p_level, godot_packed_string_array *p_locals, godot_array *p_values, int p_max_subitems, int p_max_depth);
  129. void (*debug_get_stack_level_members)(godot_pluginscript_language_data *p_data, int p_level, godot_packed_string_array *p_members, godot_array *p_values, int p_max_subitems, int p_max_depth);
  130. void (*debug_get_globals)(godot_pluginscript_language_data *p_data, godot_packed_string_array *p_locals, godot_array *p_values, int p_max_subitems, int p_max_depth);
  131. godot_string (*debug_parse_stack_level_expression)(godot_pluginscript_language_data *p_data, int p_level, const godot_string *p_expression, int p_max_subitems, int p_max_depth);
  132. // TODO: could this stuff be moved to the godot_pluginscript_language_desc ?
  133. void (*get_public_functions)(godot_pluginscript_language_data *p_data, godot_array *r_functions);
  134. void (*get_public_constants)(godot_pluginscript_language_data *p_data, godot_dictionary *r_constants);
  135. void (*profiling_start)(godot_pluginscript_language_data *p_data);
  136. void (*profiling_stop)(godot_pluginscript_language_data *p_data);
  137. int (*profiling_get_accumulated_data)(godot_pluginscript_language_data *p_data, godot_pluginscript_profiling_data *r_info, int p_info_max);
  138. int (*profiling_get_frame_data)(godot_pluginscript_language_data *p_data, godot_pluginscript_profiling_data *r_info, int p_info_max);
  139. void (*profiling_frame)(godot_pluginscript_language_data *p_data);
  140. godot_pluginscript_script_desc script_desc;
  141. } godot_pluginscript_language_desc;
  142. void GDAPI godot_pluginscript_register_language(const godot_pluginscript_language_desc *language_desc);
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif // GODOT_PLUGINSCRIPT_H