1+ -- Copyright (c) 2017. tangzx([email protected] )2+ --
3+ -- Licensed under the Apache License, Version 2.0 (the "License");
4+ -- you may not use this file except in compliance with the License.
5+ -- You may obtain a copy of the License at
6+ --
7+ -- http://www.apache.org/licenses/LICENSE-2.0
8+ --
9+ -- Unless required by applicable law or agreed to in writing, software
10+ -- distributed under the License is distributed on an "AS IS" BASIS,
11+ -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ -- See the License for the specific language governing permissions and
13+ -- limitations under the License.
14+
15+
16+ local toluaDebugger = {}
17+
18+ function toluaDebugger .GetValueAsText (ty , obj , depth , typeNameOverride , displayAsKey )
19+ if ty == ' userdata' then
20+ if depth <= 1 then return nil end
21+ local mt = getmetatable (obj )
22+ if mt == nil then return nil end
23+ local tableNode = toluaDebugger .RawGetValueAsText (obj , depth , nil , false )
24+ if tableNode == nil then return nil end
25+
26+ local propMap = {}
27+ while mt ~= nil do
28+ local getTab = mt [tolua .gettag ]
29+ if getTab then
30+ for property , _ in pairs (getTab ) do
31+ if not propMap [property ] then
32+ propMap [property ] = true
33+ local key = toluaDebugger .RawGetValueAsText (property , 0 , nil , true )
34+ local value = toluaDebugger .RawGetValueAsText (obj [property ], depth - 1 , nil , false )
35+ toluaDebugger .AddChildNode (tableNode , key , value )
36+ end
37+ end
38+ end
39+ mt = getmetatable (mt )
40+ end
41+ return tableNode
42+ end
43+ end
44+
45+ local xluaDebugger = {}
46+ function xluaDebugger .GetValueAsText (ty , obj , depth , typeNameOverride , displayAsKey )
47+ if ty == ' userdata' then
48+ local mt = getmetatable (obj )
49+ if mt == nil or depth <= 1 then return nil end
50+
51+ local CSType = obj :GetType ()
52+ if CSType then
53+ local tableNode = xluaDebugger .RawGetValueAsText (obj , depth , nil , false )
54+
55+ local Type = CS .System .Type
56+ local ObsoleteType = Type .GetType (' System.ObsoleteAttribute' )
57+ local BindType = Type .GetType (' System.Reflection.BindingFlags' )
58+ local bindValue = CS .System .Enum .ToObject (BindType , 4157 ) -- 60 | 4096
59+ local properties = CSType :GetProperties (bindValue )
60+ for i = 1 , properties .Length do
61+ local p = properties [i - 1 ]
62+ if CS .System .Attribute .GetCustomAttribute (p , ObsoleteType ) == nil then
63+ local property = p .Name
64+ local value = obj [property ]
65+
66+ local key = xluaDebugger .RawGetValueAsText (property , 0 , nil , true )
67+ local value = xluaDebugger .RawGetValueAsText (value , depth - 1 , nil , false )
68+ xluaDebugger .AddChildNode (tableNode , key , value )
69+ end
70+ end
71+
72+ return tableNode
73+ end
74+ end
75+ end
76+
77+
78+ local cocosLuaDebugger = {}
79+ function cocosLuaDebugger .GetValueAsText (ty , obj , depth , typeNameOverride , displayAsKey )
80+ if ty == ' userdata' then
81+ if depth <= 1 then return nil end
82+ local mt , tab = getmetatable (obj ), tolua .getpeer (obj )
83+ if mt == nil then return nil end
84+ local tableNode = cocosLuaDebugger .RawGetValueAsText (obj , depth , nil , false )
85+ if tableNode == nil then return nil end
86+
87+ local propMap = {}
88+ while mt ~= nil and tab ~= nil do
89+ for property , _ in pairs (tab ) do
90+ if not propMap [property ] then
91+ propMap [property ] = true
92+ local key = cocosLuaDebugger .RawGetValueAsText (property , 0 , nil , true )
93+ local value = cocosLuaDebugger .RawGetValueAsText (obj [property ], depth - 1 , nil , false )
94+ cocosLuaDebugger .AddChildNode (tableNode , key , value )
95+ end
96+ end
97+ mt , tab = getmetatable (mt ), tolua .getpeer (mt )
98+ end
99+ return tableNode
100+ end
101+ end
102+
103+ emmy = {}
104+
105+ if tolua then
106+ if tolua .gettag then
107+ emmy = toluaDebugger
108+ else
109+ emmy = cocosLuaDebugger
110+ end
111+ elseif xlua then
112+ emmy = xluaDebugger
113+ end
114+
115+ function emmy .Reload (fileName )
116+ local a , b , c = string.find (fileName , ' %.lua' )
117+ if a then
118+ fileName = string.sub (fileName , 1 , a - 1 )
119+ end
120+
121+ emmy .DebugLog (' Try reload : ' .. fileName , 1 )
122+ local searchers = package.searchers or package.loaders
123+ for _ , load in ipairs (searchers ) do
124+ local result = load (fileName )
125+ if type (result ) == ' function' then
126+ break
127+ end
128+ end
129+ end
130+
131+ if emmy_init then
132+ emmy_init ()
133+ end
0 commit comments