-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrimelua_debug.lua
executable file
·203 lines (168 loc) · 5.47 KB
/
rimelua_debug.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#! /usr/bin/env lua
--
-- debug.lua
-- Copyright (C) 2020 Shewer Lu <[email protected]>
--
-- Distributed under terms of the MIT license.
--
require 'muti_reverse.metatable'
local function objlist(obj,elm,seg, ... )
local _type= type(obj)
if _type == "string" then
yield(Candidate("debug",seg.start,seg._end, obj ,_type ) )
elseif _type == "number" then
yield(Candidate("debug",seg.start,seg._end, obj ,_type) )
elseif _type == "function" then
yield(Candidate("debug",seg.start,seg._end, tostring(obj) ,_type) )
--local ptab={ pcall(obj, ... ) }
--for i,v in ipairs(ptab) do
--yield(Candidate("debug",seg.start,seg._end, string.format("%s : %s",i,v) ,"table"))
--end
elseif _type == "table" or _obj:is_a(Object) then
for k,v in pairs(obj) do
if elm=="" or k:match("^" .. elm) then
yield(Candidate("debug",seg.start,seg._end, string.format("%s : %s",k,v) ,_type))
end
end
end
end
--
local function match_sort(tab,str)
--local tmp=metatable()
print("str " , str)
--for k,v in pairs(tab) do print(k,v) end
--metatable(tab)
local tmp= table.map_hash(tab )
--for _,elm in ipairs(tmp) do print("-----" , elm[1],elm[2] ) end
tmp:sort(function(v1,v2) return v1[1]< v2[1] end ) --tab to list { {k,v},{k,v}....}
print( "str s " .. tostring(tmp) )
local tmp2= metatable()
for _,elm in ipairs(tmp) do
if tostring(elm[1]):match("^" .. str) then
tmp2:insert(1,elm) -- insert form head
else
tmp2:insert(elm) -- insert from tail
end
end
--print("------------------------return")
--tmp2:each(function(elm) print(elm[1],elm[2]) end )
--print("------------------------return")
return tmp2
end
local function tab_conv(str,reg) -- ok
local V = reg or _G
local indexw=""
local Vtmp
for w in str:gmatch( "[%w_]*") do
Vtmp = V[tonumber(w) or w ]
local _type=type(Vtmp)
if _type == "nil" or _type ~= "table" then break end
V=Vtmp
end
return Vtmp
end
local function type_conv(str) --- ok
local tmp= tonumber(str)
if tmp then return tmp end
tmp= str:match("[\'\"](.*)[\'\"]")
if tmp then return tmp end
tmp= tab_conv(str)
return tmp
end
local function argv_conv(str) -- ok
str= str or "" -- nil or "" empty
local tab=metatable()
--for w in str:gmatch("[%w._\"]*") do
for w in str:gmatch("[^,]*") do -- "%s -- %s " for string.format()
tab:insert( type_conv(w) )
end
return tab:unpack()
end
local function conv(str)
-- split var and argv
local V=_G
local v= str:match("([%a_][%w_+.]*)%(.*%)?") -- a3234.oeoeu.oeuoeu.oeuoeu( argv)
local arg= str:match("[%a_][%w+_]*(%(.*%))")
return type_conv(v) , argv_conv(arg)
end
local function exec(func, ...)
if type(func) == "function" then
return func(...)
end
end
-- return match data of list
local function rime_lua_debug(_input,seg,env)
--yield(Candidate("debug", seg.start, seg._end,_input , "dubug:"))
local index=1
local _L =metatable()
while true do
local name,value=debug.getlocal(2,index)
if not name then break end
_L[name]=value
index=index +1
end
--env.preedit= init_data(env)
local tab= metatable() -- init list
local t , input = _input:match("^([GLF])(.*)$" ) -- splite Goble|Local string
if not t then return end -- not match
local _tabb = input:split("(") -- split tab , argv
local obj_str, argv_str = table.unpack( input:split("(") )
local inp_tab = ( argv_str and argv_str:split(",") ) or {}
local V= (t =="L" and _L) or _G
local lev = 0
local usesdata
local match_obj=nil
for obj in obj_str:gmatch("[%w_+]*") do
lev=lev+1
print( "----------lev: ",lev , V,obj)
if type(V) == "userdata" then
-- bypass match_sort 目前無法處理 userdata
else
tab=match_sort(V,obj) -- 預排清單
end
match_obj=V[tonumber(obj) or obj ] --- numberstr to string or key string
if match_obj then
local _type = type(match_obj)
if _type == "number" then
tab:insert(1,{match_obj,_type}) -- 插仆 數值
elseif _type == "boolean" then
print("---------match string--------")
tab:insert(1,{match_obj,_type }) -- 插入 字串值
elseif _type == "string" then
print("---------match string--------")
tab:insert(1,{match_obj,_type }) -- 插入 字串值
elseif _type == "function" then
print("---------match string--------")
elseif _type== "table" then
V= match_obj -- V 變更下一層 如果 還有 子字串
elseif match_obj.is_a and match_obj:is_a(Object) then
V= match_obj -- V 變更下一層 如果 還有 子字串
elseif _type == "userdata" then
userdata= match_obj -- 試著 如果 userdata data_get userdata 會有值
if type(userdata)== "number" then
tab:insert(1,{userdata,_type }) -- 插入 字串值
elseif type(userdata) == "boolean" then
tab:insert(1,{userdata,_type }) -- 插入 字串值
elseif type(userdata) == "string" then
tab:insert(1,{userdata,_type}) -- 插仆 數值
elseif type(userdata)== "function" then
tab:insert(1,{userdata,_type}) -- 插仆 數值
elseif type(userdata)== "userdata" then
tab:insert(1,{match_obj,userdata or _type})
V=userdata
else
end
end
else
if type(V) == "userdata" then -- 如果查表查不到 且 表為userdada 不要 break
else
break
end
end
end
--tab:each(function(elm) print(elm[1],elm[2]) end )
return tab
end
--localdata={env={zz=4,zc=5,abcd=3,abdd=2,acda=1,cc=7},tee={aa=3,bb=3,cc=5 }}
return rime_lua_debug
--return debug("Ltee.abb.eb",1,{},localdata)