godot_pluginscript.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*************************************************************************/
  2. /* godot_pluginscript.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. //this is used by script languages that keep a reference counter of their own
  51. //you can make make Ref<> not die when it reaches zero, so deleting the reference
  52. //depends entirely from the script.
  53. // Note: You can set those function pointer to NULL if not needed.
  54. void (*refcount_incremented)(godot_pluginscript_instance_data *p_data);
  55. bool (*refcount_decremented)(godot_pluginscript_instance_data *p_data); // return true if it can die
  56. } godot_pluginscript_instance_desc;
  57. // --- Script ---
  58. typedef struct {
  59. godot_pluginscript_script_data *data;
  60. godot_string_name name;
  61. godot_bool is_tool;
  62. godot_string_name base;
  63. // Member lines format: {<string>: <int>}
  64. godot_dictionary member_lines;
  65. // Method info dictionary format
  66. // {
  67. // name: <string>
  68. // args: [<dict:property>]
  69. // default_args: [<variant>]
  70. // return: <dict:property>
  71. // flags: <int>
  72. // rpc_mode: <int:godot_method_rpc_mode>
  73. // }
  74. godot_array methods;
  75. // Same format than for methods
  76. godot_array signals;
  77. // Property info dictionary format
  78. // {
  79. // name: <string>
  80. // type: <int:godot_variant_type>
  81. // hint: <int:godot_property_hint>
  82. // hint_string: <string>
  83. // usage: <int:godot_property_usage_flags>
  84. // default_value: <variant>
  85. // rset_mode: <int:godot_method_rpc_mode>
  86. // }
  87. godot_array properties;
  88. } godot_pluginscript_script_manifest;
  89. typedef struct {
  90. 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);
  91. void (*finish)(godot_pluginscript_script_data *p_data);
  92. godot_pluginscript_instance_desc instance_desc;
  93. } godot_pluginscript_script_desc;
  94. // --- Language ---
  95. typedef struct {
  96. godot_string_name signature;
  97. godot_int call_count;
  98. godot_int total_time; // In microseconds
  99. godot_int self_time; // In microseconds
  100. } godot_pluginscript_profiling_data;
  101. typedef struct {
  102. const char *name;
  103. const char *type;
  104. const char *extension;
  105. const char **recognized_extensions; // NULL terminated array
  106. godot_pluginscript_language_data *(*init)();
  107. void (*finish)(godot_pluginscript_language_data *p_data);
  108. const char **reserved_words; // NULL terminated array
  109. const char **comment_delimiters; // NULL terminated array
  110. const char **string_delimiters; // NULL terminated array
  111. godot_bool has_named_classes;
  112. godot_bool supports_builtin_mode;
  113. 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);
  114. godot_bool (*validate)(godot_pluginscript_language_data *p_data, const godot_string *p_script, int *r_line_error, int *r_col_error, godot_string *r_test_error, const godot_string *p_path, godot_pool_string_array *r_functions);
  115. int (*find_function)(godot_pluginscript_language_data *p_data, const godot_string *p_function, const godot_string *p_code); // Can be NULL
  116. godot_string (*make_function)(godot_pluginscript_language_data *p_data, const godot_string *p_class, const godot_string *p_name, const godot_pool_string_array *p_args);
  117. 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);
  118. void (*auto_indent_code)(godot_pluginscript_language_data *p_data, godot_string *p_code, int p_from_line, int p_to_line);
  119. void (*add_global_constant)(godot_pluginscript_language_data *p_data, const godot_string_name *p_variable, const godot_variant *p_value);
  120. godot_string (*debug_get_error)(godot_pluginscript_language_data *p_data);
  121. int (*debug_get_stack_level_count)(godot_pluginscript_language_data *p_data);
  122. int (*debug_get_stack_level_line)(godot_pluginscript_language_data *p_data, int p_level);
  123. godot_string (*debug_get_stack_level_function)(godot_pluginscript_language_data *p_data, int p_level);
  124. godot_string (*debug_get_stack_level_source)(godot_pluginscript_language_data *p_data, int p_level);
  125. void (*debug_get_stack_level_locals)(godot_pluginscript_language_data *p_data, int p_level, godot_pool_string_array *p_locals, godot_array *p_values, int p_max_subitems, int p_max_depth);
  126. void (*debug_get_stack_level_members)(godot_pluginscript_language_data *p_data, int p_level, godot_pool_string_array *p_members, godot_array *p_values, int p_max_subitems, int p_max_depth);
  127. void (*debug_get_globals)(godot_pluginscript_language_data *p_data, godot_pool_string_array *p_locals, godot_array *p_values, int p_max_subitems, int p_max_depth);
  128. 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);
  129. // TODO: could this stuff be moved to the godot_pluginscript_language_desc ?
  130. void (*get_public_functions)(godot_pluginscript_language_data *p_data, godot_array *r_functions);
  131. void (*get_public_constants)(godot_pluginscript_language_data *p_data, godot_dictionary *r_constants);
  132. void (*profiling_start)(godot_pluginscript_language_data *p_data);
  133. void (*profiling_stop)(godot_pluginscript_language_data *p_data);
  134. int (*profiling_get_accumulated_data)(godot_pluginscript_language_data *p_data, godot_pluginscript_profiling_data *r_info, int p_info_max);
  135. int (*profiling_get_frame_data)(godot_pluginscript_language_data *p_data, godot_pluginscript_profiling_data *r_info, int p_info_max);
  136. void (*profiling_frame)(godot_pluginscript_language_data *p_data);
  137. godot_pluginscript_script_desc script_desc;
  138. } godot_pluginscript_language_desc;
  139. void GDAPI godot_pluginscript_register_language(const godot_pluginscript_language_desc *language_desc);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif // GODOT_PLUGINSCRIPT_H