summaryrefslogtreecommitdiff
path: root/script-beta/src/core/hover/table.lua
blob: 9ed86692e154489e35d8a087539a0e139d7439df (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
35
local vm = require 'vm'

local function checkClass(source)
end

return function (source)
    local fields = {}
    local class
    vm.eachField(source, function (info)
        if info.key == 's|type' or info.key == 's|__name' or info.key == 's|name' then
            if info.value and info.value.type == 'string' then
                class = info.value[1]
            end
        end
        local type = vm.getType(info.source)
        fields[#fields+1] = ('%s'):format(type)
    end)
    local fieldsBuf
    if #fields == 0 then
        fieldsBuf = '{}'
    else
        local lines = {}
        lines[#lines+1] = '{'
        for _, field in ipairs(fields) do
            lines[#lines+1] = '    ' .. field
        end
        lines[#lines+1] = '}'
        fieldsBuf = table.concat(lines, '\n')
    end
    if class then
        return ('%s %s'):format(class, fieldsBuf)
    else
        return fieldsBuf
    end
end