multi_script.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*************************************************************************/
  2. /* multi_script.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef MULTI_SCRIPT_H
  30. #define MULTI_SCRIPT_H
  31. #include "script_language.h"
  32. #include "os/thread_safe.h"
  33. class MultiScript;
  34. class MultiScriptInstance : public ScriptInstance {
  35. friend class MultiScript;
  36. mutable Vector<ScriptInstance*> instances;
  37. Object *object;
  38. mutable MultiScript *owner;
  39. public:
  40. virtual bool set(const StringName& p_name, const Variant& p_value);
  41. virtual bool get(const StringName& p_name, Variant &r_ret) const;
  42. virtual void get_property_list(List<PropertyInfo> *p_properties) const;
  43. virtual void get_method_list(List<MethodInfo> *p_list) const;
  44. virtual bool has_method(const StringName& p_method) const;
  45. virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error);
  46. virtual void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount);
  47. virtual void notification(int p_notification);
  48. virtual Ref<Script> get_script() const;
  49. virtual ScriptLanguage *get_language();
  50. virtual ~MultiScriptInstance();
  51. };
  52. class MultiScript : public Script {
  53. _THREAD_SAFE_CLASS_
  54. friend class MultiScriptInstance;
  55. OBJ_TYPE( MultiScript,Script);
  56. Vector<Ref<Script> > scripts;
  57. Map<Object*,MultiScriptInstance*> instances;
  58. protected:
  59. bool _set(const StringName& p_name, const Variant& p_value);
  60. bool _get(const StringName& p_name,Variant &r_ret) const;
  61. void _get_property_list( List<PropertyInfo> *p_list) const;
  62. static void _bind_methods();
  63. public:
  64. void remove_instance(Object *p_object);
  65. virtual bool can_instance() const;
  66. virtual StringName get_instance_base_type() const;
  67. virtual ScriptInstance* instance_create(Object *p_this);
  68. virtual bool instance_has(const Object *p_this) const;
  69. virtual bool has_source_code() const;
  70. virtual String get_source_code() const;
  71. virtual void set_source_code(const String& p_code);
  72. virtual Error reload();
  73. virtual bool is_tool() const;
  74. virtual String get_node_type() const;
  75. void set_script(int p_idx,const Ref<Script>& p_script );
  76. Ref<Script> get_script(int p_idx) const;
  77. void remove_script(int p_idx);
  78. void add_script(const Ref<Script>& p_script);
  79. virtual ScriptLanguage *get_language() const;
  80. MultiScript();
  81. };
  82. class MultiScriptLanguage : public ScriptLanguage {
  83. static MultiScriptLanguage *singleton;
  84. public:
  85. static _FORCE_INLINE_ MultiScriptLanguage *get_singleton() { return singleton; }
  86. virtual String get_name() const { return "MultiScript"; }
  87. /* LANGUAGE FUNCTIONS */
  88. virtual void init() {}
  89. virtual String get_type() const { return "MultiScript"; }
  90. virtual String get_extension() const { return ""; }
  91. virtual Error execute_file(const String& p_path) { return OK; }
  92. virtual void finish() {}
  93. /* EDITOR FUNCTIONS */
  94. virtual void get_reserved_words(List<String> *p_words) const {}
  95. virtual void get_comment_delimiters(List<String> *p_delimiters) const {}
  96. virtual void get_string_delimiters(List<String> *p_delimiters) const {}
  97. virtual String get_template(const String& p_class_name, const String& p_base_class_name) const { return ""; }
  98. virtual bool validate(const String& p_script, int &r_line_error,int &r_col_error,String& r_test_error,const String& p_path="",List<String>* r_fn=NULL) const { return true; }
  99. virtual Script *create_script() const { return memnew( MultiScript ); }
  100. virtual bool has_named_classes() const { return false; }
  101. virtual int find_function(const String& p_function,const String& p_code) const { return -1; }
  102. virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const { return ""; }
  103. /* DEBUGGER FUNCTIONS */
  104. virtual String debug_get_error() const { return ""; }
  105. virtual int debug_get_stack_level_count() const { return 0; }
  106. virtual int debug_get_stack_level_line(int p_level) const { return 0; }
  107. virtual String debug_get_stack_level_function(int p_level) const { return ""; }
  108. virtual String debug_get_stack_level_source(int p_level) const { return ""; }
  109. virtual void debug_get_stack_level_locals(int p_level,List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1) {}
  110. virtual void debug_get_stack_level_members(int p_level,List<String> *p_members, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1) {}
  111. virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems=-1,int p_max_depth=-1) {}
  112. virtual String debug_parse_stack_level_expression(int p_level,const String& p_expression,int p_max_subitems=-1,int p_max_depth=-1) { return ""; }
  113. /* LOADER FUNCTIONS */
  114. virtual void get_recognized_extensions(List<String> *p_extensions) const {}
  115. virtual void get_public_functions(List<MethodInfo> *p_functions) const {}
  116. MultiScriptLanguage() { singleton=this; }
  117. virtual ~MultiScriptLanguage() {};
  118. };
  119. #endif // MULTI_SCRIPT_H