godot_pluginscript.h 9.1 KB

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