From 475cee9c0fc7b1975de1c5380178763dc2c2df38 Mon Sep 17 00:00:00 2001 From: geequlim Date: Tue, 17 Oct 2017 22:35:49 +0800 Subject: Abstract some method for script system --- core/script_language.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/script_language.h b/core/script_language.h index 5da72d0492..3d01381f3b 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -120,6 +120,9 @@ public: virtual int get_member_line(const StringName &p_member) const { return -1; } + virtual void get_constants(Map *p_constants) {} + virtual void get_members(Set *p_constants) {} + Script() {} }; @@ -130,6 +133,7 @@ public: virtual void get_property_list(List *p_properties) const = 0; virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = NULL) const = 0; + virtual Object *get_owner() { return NULL; } virtual void get_property_state(List > &state); virtual void get_method_list(List *p_list) const = 0; @@ -244,7 +248,8 @@ public: virtual String debug_get_stack_level_source(int p_level) const = 0; virtual void debug_get_stack_level_locals(int p_level, List *p_locals, List *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0; virtual void debug_get_stack_level_members(int p_level, List *p_members, List *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0; - virtual void debug_get_globals(List *p_locals, List *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0; + virtual ScriptInstance *debug_get_stack_level_instance(int p_level) { return NULL; } + virtual void debug_get_globals(List *p_globals, List *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0; virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) = 0; struct StackInfo { -- cgit v1.2.3 From ccf76798d54c7ed70813346493b7f64264181f7c Mon Sep 17 00:00:00 2001 From: geequlim Date: Tue, 17 Oct 2017 22:37:25 +0800 Subject: Send script members, contants and globals to debugger Remove remote inspector panel --- core/script_debugger_remote.cpp | 146 ++++++++++++++++++++++++++-------------- 1 file changed, 96 insertions(+), 50 deletions(-) (limited to 'core') diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index f77fb116c7..14f0cddb9c 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -35,6 +35,8 @@ #include "os/input.h" #include "os/os.h" #include "project_settings.h" +#include "scene/main/node.h" + void ScriptDebuggerRemote::_send_video_memory() { List usage; @@ -201,20 +203,39 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) List members; List member_vals; - + if (ScriptInstance *inst = p_script->debug_get_stack_level_instance(lv)) { + members.push_back("self"); + member_vals.push_back(inst->get_owner()); + } p_script->debug_get_stack_level_members(lv, &members, &member_vals); - ERR_CONTINUE(members.size() != member_vals.size()); List locals; List local_vals; - p_script->debug_get_stack_level_locals(lv, &locals, &local_vals); - ERR_CONTINUE(locals.size() != local_vals.size()); + List globals; + List globals_vals; + p_script->debug_get_globals(&globals, &globals_vals); + ERR_CONTINUE(globals.size() != globals_vals.size()); + packet_peer_stream->put_var("stack_frame_vars"); - packet_peer_stream->put_var(2 + locals.size() * 2 + members.size() * 2); + packet_peer_stream->put_var(3 + (locals.size() + members.size() + globals.size()) * 2); + + { //locals + packet_peer_stream->put_var(locals.size()); + + List::Element *E = locals.front(); + List::Element *F = local_vals.front(); + + while (E) { + _put_variable(E->get(), F->get()); + + E = E->next(); + F = F->next(); + } + } { //members packet_peer_stream->put_var(members.size()); @@ -231,11 +252,11 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) } } - { //locals - packet_peer_stream->put_var(locals.size()); + { //globals + packet_peer_stream->put_var(globals.size()); - List::Element *E = locals.front(); - List::Element *F = local_vals.front(); + List::Element *E = globals.front(); + List::Element *F = globals_vals.front(); while (E) { _put_variable(E->get(), F->get()); @@ -532,56 +553,77 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) { if (!obj) return; - List pinfo; - obj->get_property_list(&pinfo, true); + typedef Pair PropertyDesc; + List properties; - int props_to_send = 0; - for (List::Element *E = pinfo.front(); E; E = E->next()) { + if (ScriptInstance *si = obj->get_script_instance()) { + if (!si->get_script().is_null()) { - if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) { - props_to_send++; - } - } + Set members; + si->get_script()->get_members(&members); + for (Set::Element *E = members.front(); E; E = E->next()) { - packet_peer_stream->put_var("message:inspect_object"); - packet_peer_stream->put_var(props_to_send * 5 + 4); - packet_peer_stream->put_var(p_id); - packet_peer_stream->put_var(obj->get_class()); - if (obj->is_class("Resource") || obj->is_class("Node")) - packet_peer_stream->put_var(obj->call("get_path")); - else - packet_peer_stream->put_var(""); + Variant m; + if (si->get(E->get(), m)) { + PropertyInfo pi(m.get_type(), String("Members/") + E->get()); + properties.push_back(PropertyDesc(pi, m)); + } + } - packet_peer_stream->put_var(props_to_send); + Map constants; + si->get_script()->get_constants(&constants); + for (Map::Element *E = constants.front(); E; E = E->next()) { + PropertyInfo pi(E->value().get_type(), (String("Constants/") + E->key())); + properties.push_back(PropertyDesc(pi, E->value())); + } + } + } + if (Node *node = Object::cast_to(obj)) { + PropertyInfo pi(Variant::NODE_PATH, String("Node/path")); + properties.push_front(PropertyDesc(pi, node->get_path())); + } else if (Resource *res = Object::cast_to(obj)) { + if (Script *s = Object::cast_to