pluginscript_script.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*************************************************************************/
  2. /* pluginscript_script.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 PLUGINSCRIPT_SCRIPT_H
  31. #define PLUGINSCRIPT_SCRIPT_H
  32. // Godot imports
  33. #include "core/script_language.h"
  34. // PluginScript imports
  35. #include "pluginscript_language.h"
  36. #include <pluginscript/godot_pluginscript.h>
  37. class PluginScript : public Script {
  38. GDCLASS(PluginScript, Script);
  39. friend class PluginScriptInstance;
  40. friend class PluginScriptLanguage;
  41. private:
  42. godot_pluginscript_script_data *_data;
  43. const godot_pluginscript_script_desc *_desc;
  44. PluginScriptLanguage *_language;
  45. bool _tool;
  46. bool _valid;
  47. Ref<Script> _ref_base_parent;
  48. StringName _native_parent;
  49. SelfList<PluginScript> _script_list;
  50. Map<StringName, int> _member_lines;
  51. Map<StringName, Variant> _properties_default_values;
  52. Map<StringName, PropertyInfo> _properties_info;
  53. Map<StringName, MethodInfo> _signals_info;
  54. Map<StringName, MethodInfo> _methods_info;
  55. Map<StringName, MultiplayerAPI::RPCMode> _variables_rset_mode;
  56. Map<StringName, MultiplayerAPI::RPCMode> _methods_rpc_mode;
  57. Set<Object *> _instances;
  58. //exported members
  59. String _source;
  60. String _path;
  61. StringName _name;
  62. protected:
  63. static void _bind_methods();
  64. PluginScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Variant::CallError &r_error);
  65. Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
  66. #ifdef TOOLS_ENABLED
  67. Set<PlaceHolderScriptInstance *> placeholders;
  68. //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
  69. virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
  70. #endif
  71. public:
  72. virtual bool can_instance() const;
  73. virtual Ref<Script> get_base_script() const; //for script inheritance
  74. virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so
  75. virtual ScriptInstance *instance_create(Object *p_this);
  76. virtual bool instance_has(const Object *p_this) const;
  77. virtual bool has_source_code() const;
  78. virtual String get_source_code() const;
  79. virtual void set_source_code(const String &p_code);
  80. virtual Error reload(bool p_keep_state = false);
  81. // TODO: load_source_code only allow utf-8 file, should handle bytecode as well ?
  82. virtual Error load_source_code(const String &p_path);
  83. virtual bool has_method(const StringName &p_method) const;
  84. virtual MethodInfo get_method_info(const StringName &p_method) const;
  85. bool has_property(const StringName &p_method) const;
  86. PropertyInfo get_property_info(const StringName &p_property) const;
  87. bool is_tool() const { return _tool; }
  88. bool is_valid() const { return true; }
  89. virtual ScriptLanguage *get_language() const;
  90. virtual bool has_script_signal(const StringName &p_signal) const;
  91. virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
  92. virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
  93. virtual void update_exports();
  94. virtual void get_script_method_list(List<MethodInfo> *r_methods) const;
  95. virtual void get_script_property_list(List<PropertyInfo> *r_properties) const;
  96. virtual int get_member_line(const StringName &p_member) const;
  97. MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const;
  98. MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const;
  99. PluginScript();
  100. void init(PluginScriptLanguage *language);
  101. virtual ~PluginScript();
  102. };
  103. #endif // PLUGINSCRIPT_SCRIPT_H