summaryrefslogtreecommitdiff
path: root/src/service/init.lua
blob: 53e6e4b3b7e659015db7d5416001e7f5a0a86dcd (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
local sleep = require 'ffi.sleep'
local ext   = require 'process.ext'

local function listen(self, input, output)
    if input then
        log.info('指定输入文件,路径为:', input)
        fs.create_directories(input:parent_path())
        io.input(io.open(input:string(), 'rb'))
    else
        ext.set_filemode(io.stdin, 'b')
    end
    if output then
        log.info('指定输出文件,路径为:', output)
        fs.create_directories(output:parent_path())
        io.output(io.open(output:string(), 'wb'))
    else
        ext.set_filemode(io.stdout, 'b')
        io.stdout:setvbuf 'no'
    end

    for line in io.input():lines 'L' do
        log.debug('标准输入:\n', line)
    end
end

local mt = {
    definition = require 'service.definition',
    listen     = listen,
}
mt.__index = mt

return function ()
    local session = setmetatable({}, mt)
    return session
end