summaryrefslogtreecommitdiff
path: root/server/src/vm/function.lua
blob: 2546539878f210a78ce05aac0ed0cce97a3be133 (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
local env = require 'vm.env'
local createDots = require 'vm.dots'

local mt = {}
mt.__index = mt
mt.type = 'function'
mt._returnDots = false

function mt:getUri()
    return self.source.uri
end

function mt:saveLocal(name, loc)
    self.locals[name] = loc
end

function mt:setReturn(index, value)
    self.returns[index] = value
end

function mt:returnDots(index, value)
    self.returns[index] = value
    self._returnDots = true
end

return function (source)
    if not source then
        error('Function must has a source')
    end
    local self = setmetatable({
        source = source,
        locals = {},
        returns = {},
    }, mt)
    return self
end