summaryrefslogtreecommitdiff
path: root/server/src/emmy/funcType.lua
blob: 2c073fe245a1ffe46c222b7558d32047e3ab91d3 (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
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
local listMgr = require 'vm.list'

---@class EmmyFunctionType
local mt = {}
mt.__index = mt
mt.type = 'emmy.functionType'

function mt:getType()
    return 'function'
end

function mt:getName()
    return 'function'
end

function mt:getSource()
    return listMgr.get(self.source)
end

function mt:setValue(value)
    self.value = value
end

function mt:getValue()
    return self.value
end

function mt:addParam(name, type)
    self._params[#self._params+1] = { name, type }
end

function mt:addReturn(type)
    self._returns[#self._returns+1] = type
end

function mt:eachParam(callback)
    for _, data in ipairs(self._params) do
        callback(data[1], data[2])
    end
end

function mt:eachReturn(callback)
    for _, rtn in ipairs(self._returns) do
        callback(rtn)
    end
end

function mt:bindFunction(func)
    if func then
        self._bindFunction = func
    else
        return self._bindFunction
    end
end

return function (manager, source)
    local self = setmetatable({
        source = source.id,
        _params = {},
        _returns = {},
        _manager = manager,
    }, mt)
    return self
end