IA
Size: a a a
IA
IA
function Ema:next() end
function Ema:reset() end
function Ema:new(period)
local ema = {}
ema.next = self.next --link to function
ema.reset = self.reset --link to function
return ema
end
IA
VG
local Ema = {}
local methods = {}
local metatable = { __index = methods }
function methods:reset()
end
function methods:next()
end
function Ema:new()
return setmetatable({}, metatable)
end
return setmetatable(Ema, { __call = Ema.new })
VG
IA
IA
S
setmetatable(Ema, {хочу, чтобы клиентский код вот так работал:
__call = function(cls, ...)
local self = setmetatable({}, cls)
self:new(...)
return self
end
})
local ema = Ema:new(3) -- а не
local ema = Ema(3)
--как с __call
function Ema:new(a, b, c)
self = setmetatable({}, self)
self.x, self.y = a, b+c
return self
end
setmetatable(Ema, {__call = Ema.new})
IA
IA
S
Ema
теперь можно вызывать как Ema:new(a, b, c)
и как Ema(a, b, c)
с идентичным результатом.IA
H
S
local http = require"socket.http"
local response, status, headers = http.request{
url = "http://yandex.ru"
verb = "post",
body = "hello",
}
Для https — ещё и luasec, а вместо require"socket.http"
— require"ssl.https"
, но остальное там примерно такое же.H
local http = require"socket.http"
local response, status, headers = http.request{
url = "http://yandex.ru"
verb = "post",
body = "hello",
}
Для https — ещё и luasec, а вместо require"socket.http"
— require"ssl.https"
, но остальное там примерно такое же.S
H
S
H
S