diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-10-12 17:33:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-10-12 17:33:32 +0800 |
commit | 12efa3035f85df148b23e54e051b0769572d1589 (patch) | |
tree | 08f16d7317068e6410086dcf88c16041413e9ce1 | |
parent | 87dd78bf46c4ff0d02f851acd927e3d3f521392c (diff) | |
download | lua-language-server-12efa3035f85df148b23e54e051b0769572d1589.zip |
先打印一下标准输入
-rw-r--r-- | bin/process.dll | bin | 0 -> 15872 bytes | |||
-rw-r--r-- | build/extension/.gitignore | 4 | ||||
-rw-r--r-- | main.lua | 14 | ||||
-rw-r--r-- | src/ffi/sleep.lua | 8 | ||||
-rw-r--r-- | src/ffi/unicode.lua | 49 | ||||
-rw-r--r-- | src/global_protect.lua (renamed from test/global_protect.lua) | 0 | ||||
-rw-r--r-- | src/service/init.lua | 36 | ||||
-rw-r--r-- | test/main.lua | 10 |
8 files changed, 110 insertions, 11 deletions
diff --git a/bin/process.dll b/bin/process.dll Binary files differnew file mode 100644 index 00000000..ff0fc1d3 --- /dev/null +++ b/bin/process.dll diff --git a/build/extension/.gitignore b/build/extension/.gitignore new file mode 100644 index 00000000..bf962da1 --- /dev/null +++ b/build/extension/.gitignore @@ -0,0 +1,4 @@ +out +node_modules +client/server +.vscode-test
\ No newline at end of file @@ -1,7 +1,15 @@ -require 'filelist' +require 'filesystem' ROOT = fs.current_path() -package.path = package.path .. ';' .. (ROOT / 'src' / '?.lua'):string() - .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() +package.path = (ROOT / 'src' / '?.lua'):string() + .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() local log = require 'log' log.init(ROOT, ROOT / 'log' / 'test.log') +log.info('Lua 语言服务启动,路径为:', ROOT) + +require 'utility' +require 'global_protect' +local service = require 'service' +local session = service() + +session:listen() diff --git a/src/ffi/sleep.lua b/src/ffi/sleep.lua new file mode 100644 index 00000000..5c4be639 --- /dev/null +++ b/src/ffi/sleep.lua @@ -0,0 +1,8 @@ +local ffi = require 'ffi' +ffi.cdef[[ + void Sleep(unsigned long dwMilliseconds); +]] + +return function (time) + ffi.C.Sleep(time) +end diff --git a/src/ffi/unicode.lua b/src/ffi/unicode.lua new file mode 100644 index 00000000..734b4679 --- /dev/null +++ b/src/ffi/unicode.lua @@ -0,0 +1,49 @@ +local ffi = require 'ffi' +ffi.cdef[[ + int MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, const char* lpMultiByteStr, int cbMultiByte, wchar_t* lpWideCharStr, int cchWideChar); + int WideCharToMultiByte(unsigned int CodePage, unsigned long dwFlags, const wchar_t* lpWideCharStr, int cchWideChar, char* lpMultiByteStr, int cchMultiByte, const char* lpDefaultChar, int* pfUsedDefaultChar); +]] + +local CP_UTF8 = 65001 +local CP_ACP = 0 + +local function u2w(input) + local wlen = ffi.C.MultiByteToWideChar(CP_UTF8, 0, input, #input, nil, 0) + local wstr = ffi.new('wchar_t[?]', wlen+1) + ffi.C.MultiByteToWideChar(CP_UTF8, 0, input, #input, wstr, wlen) + return wstr, wlen +end + +local function a2w(input) + local wlen = ffi.C.MultiByteToWideChar(CP_ACP, 0, input, #input, nil, 0) + local wstr = ffi.new('wchar_t[?]', wlen+1) + ffi.C.MultiByteToWideChar(CP_ACP, 0, input, #input, wstr, wlen) + return wstr, wlen +end + +local function w2u(wstr, wlen) + local len = ffi.C.WideCharToMultiByte(CP_UTF8, 0, wstr, wlen, nil, 0, nil, nil) + local str = ffi.new('char[?]', len+1) + ffi.C.WideCharToMultiByte(CP_UTF8, 0, wstr, wlen, str, len, nil, nil) + return ffi.string(str) +end + +local function w2a(wstr, wlen) + local len = ffi.C.WideCharToMultiByte(CP_ACP, 0, wstr, wlen, nil, 0, nil, nil) + local str = ffi.new('char[?]', len) + ffi.C.WideCharToMultiByte(CP_ACP, 0, wstr, wlen, str, len, nil, nil) + return ffi.string(str) +end + +return { + u2w = u2w, + a2w = a2w, + w2u = w2u, + w2a = w2a, + u2a = function (input) + return w2a(u2w(input)) + end, + a2u = function (input) + return w2u(a2w(input)) + end, +} diff --git a/test/global_protect.lua b/src/global_protect.lua index 6c736ea6..6c736ea6 100644 --- a/test/global_protect.lua +++ b/src/global_protect.lua diff --git a/src/service/init.lua b/src/service/init.lua index 91e0a4d4..53e6e4b3 100644 --- a/src/service/init.lua +++ b/src/service/init.lua @@ -1,5 +1,35 @@ -local api = { - definition = require 'service.definition' +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 api +return function () + local session = setmetatable({}, mt) + return session +end diff --git a/test/main.lua b/test/main.lua index 34cd003a..972a1068 100644 --- a/test/main.lua +++ b/test/main.lua @@ -1,11 +1,11 @@ require 'filesystem' ROOT = fs.current_path() -package.path = package.path .. ';' .. (ROOT / 'src' / '?.lua'):string() - .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() - .. ';' .. (ROOT / 'test' / '?.lua'):string() - .. ';' .. (ROOT / 'test' / '?' / 'init.lua'):string() +package.path = (ROOT / 'src' / '?.lua'):string() + .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() + .. ';' .. (ROOT / 'test' / '?.lua'):string() + .. ';' .. (ROOT / 'test' / '?' / 'init.lua'):string() -local log = require 'log' +log = require 'log' log.init(ROOT, ROOT / 'log' / 'test.log') log.debug('测试开始') |