1
0
mirror of https://github.com/lxsang/antd-lua-plugin synced 2024-12-28 02:18:21 +01:00
antd-lua-plugin/APIs/std.lua

123 lines
2.4 KiB
Lua
Raw Normal View History

2018-09-19 15:08:49 +02:00
std = modules.std()
bytes = modules.bytes()
array = modules.array()
function std.html()
2018-10-05 19:02:35 +02:00
std._html(HTTP_REQUEST.id)
2018-09-19 15:08:49 +02:00
end
function std.text()
2018-10-05 19:02:35 +02:00
std._text(HTTP_REQUEST.id)
2018-09-19 15:08:49 +02:00
end
function std.status(code, msg)
2018-10-05 19:02:35 +02:00
std._status(HTTP_REQUEST.id, code, msg)
2018-09-19 15:08:49 +02:00
end
function std.custom_header(k,v)
--print(k..":"..v)
std.t(k..": "..v)
end
function std.header_flush()
std.t("")
end
--_redirect
function std.redirect(s)
2018-10-05 19:02:35 +02:00
std._redirect(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.json()
2018-10-05 19:02:35 +02:00
std._json(HTTP_REQUEST.id)
2018-09-19 15:08:49 +02:00
end
function std.jpeg()
2018-10-05 19:02:35 +02:00
std._jpeg(HTTP_REQUEST.id)
2018-09-19 15:08:49 +02:00
end
function std.header(s)
2018-10-05 19:02:35 +02:00
std._header(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.octstream(s)
2018-10-05 19:02:35 +02:00
std._octstream(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.textstream()
2018-10-05 19:02:35 +02:00
std._textstream(HTTP_REQUEST.id)
2018-09-19 15:08:49 +02:00
end
function std.ti(v)
2018-10-05 19:02:35 +02:00
std._ti(HTTP_REQUEST.id,v)
2018-09-19 15:08:49 +02:00
end
function std.t(s)
2018-10-05 19:02:35 +02:00
std._t(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.f(v)
2018-10-05 19:02:35 +02:00
std._f(HTTP_REQUEST.id,v)
2018-09-19 15:08:49 +02:00
end
function std.fb(v)
2018-10-05 19:02:35 +02:00
std._fb(HTTP_REQUEST.id,v)
2018-09-19 15:08:49 +02:00
end
function std.setCookie(t,v,p)
p = p or ""
2018-10-05 19:02:35 +02:00
std._setCookie(HTTP_REQUEST.id,t,v,p)
2018-09-19 15:08:49 +02:00
end
function std.cjson(v, p)
std.setCookie("application/json; charset=utf-8",v)
end
function std.chtml(v)
std.setCookie("text/html; charset=utf-8",v)
end
function std.ctext(v)
std.setCookie("text/plain; charset=utf-8",v)
end
--_upload
--_route
function std.unknow(s)
2018-10-05 19:02:35 +02:00
std._unknow(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.readOnly(t) -- bugging
local proxy = {}
local mt = { -- create metatable
__index = t,
__newindex = function (t,k,v)
error("attempt to update a read-only table", 2)
end
}
setmetatable(proxy, mt)
return proxy
end
-- web socket
std.ws = {}
function std.ws.header()
2018-10-05 19:02:35 +02:00
local h = std.ws_header(HTTP_REQUEST.id)
2018-09-19 15:08:49 +02:00
if(h) then
return h --std.readOnly(h)
else
return nil
end
end
function std.ws.read(h)
2018-10-05 19:02:35 +02:00
return std.ws_read(HTTP_REQUEST.id,h)
2018-09-19 15:08:49 +02:00
end
function std.ws.swrite(s)
2018-10-05 19:02:35 +02:00
std.ws_t(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.ws.fwrite(s)
2018-10-05 19:02:35 +02:00
std.ws_f(HTTP_REQUEST.id,s)
2018-09-19 15:08:49 +02:00
end
function std.ws.write_bytes(arr)
2018-10-05 19:02:35 +02:00
std.ws_b(HTTP_REQUEST.id,arr)
2018-09-19 15:08:49 +02:00
end
function std.ws.enable()
2018-10-07 16:13:55 +02:00
return HTTP_REQUEST ~= nil and HTTP_REQUEST.request["__web_socket__"] == "1"
2018-09-19 15:08:49 +02:00
end
function std.ws.close(code)
2018-10-05 19:02:35 +02:00
std.ws_close(HTTP_REQUEST.id,code)
2018-09-19 15:08:49 +02:00
end
function std.basename(str)
local name = string.gsub(std.trim(str,"/"), "(.*/)(.*)", "%2")
return name
end
function std.is_file(f)
return std.is_dir(f) == false
end
std.ws.TEXT = 1
std.ws.BIN = 2
std.ws.CLOSE = 8