blob: be7b3995cdf3b583a8dff857d84f0ed890cc53c9 (
plain)
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
|
local vm = require 'vm'
local function getClass(source, deep)
if deep > 3 then
return nil
end
local class = vm.eachField(source, function (info)
if not info.key then
return
end
local lkey = info.key:lower()
if lkey == 's|type'
or lkey == 's|__name'
or lkey == 's|name'
or lkey == 's|class' then
if info.value and info.value.type == 'string' then
return info.value[1]
end
end
end)
if class then
return class
end
return vm.eachMeta(source, function (meta)
local cl = getClass(meta, deep + 1)
if cl then
return cl
end
end)
end
return function (source)
return getClass(source, 1)
end
|