summaryrefslogtreecommitdiff
path: root/script-beta/vm/getInfer.lua
blob: 7eb65df4784e180dd2fe3b094507099a8f9fc3d3 (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
local vm      = require 'vm.vm'
local guide   = require 'parser.guide'

NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end })

--- 是否包含某种类型
function vm.hasType(source, type)
    local infers = vm.getInfers(source)
    for i = 1, #infers do
        local infer = infers[i]
        if infer.type == type then
            return true
        end
    end
    return false
end

function vm.getType(source)
    local infers = vm.getInfers(source)
    return guide.viewInfer(infers)
end

--- 获取对象的值
--- 会尝试穿透函数调用
function vm.getInfers(source)
    if not source then
        return
    end
    return guide.requestInfer(source, vm.interface)
end