37
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local ipairs = Luan.ipairs or error()
|
|
4 local String = require "luan:String.luan"
|
|
5 local contains = String.contains or error()
|
53
|
6 local to_number = String.to_number or error()
|
37
|
7 local Io = require "luan:Io.luan"
|
|
8 local new_file = Io.schemes.file or error()
|
|
9 local Rpc = require "luan:Rpc.luan"
|
|
10 local Swing = require "luan:swing/Swing.luan"
|
|
11 local swing_run = Swing.run or error()
|
56
|
12 local swing_run_later = Swing.run_later or error()
|
|
13 local Window = require "classpath:luan_editor/Window.luan"
|
|
14 local new_window = Window.new_window or error()
|
|
15 local open_windows = Window.open_windows or error()
|
53
|
16 local Java = require "classpath:luan_editor/Java.luan"
|
37
|
17 local Logging = require "luan:logging/Logging.luan"
|
|
18 local logger = Logging.logger "editor/editor"
|
|
19
|
|
20
|
53
|
21 local port = Java.port
|
|
22 if port == nil then
|
|
23 port = 56587
|
|
24 else
|
|
25 port = to_number(port) or error("bad port: "..port)
|
|
26 end
|
37
|
27
|
|
28 Rpc.cipher_suites = nil
|
|
29 local server_socket
|
|
30 try
|
|
31 server_socket = Rpc.new_server_socket(port)
|
|
32 catch e
|
|
33 --logger.info(e.get_message())
|
|
34 if not contains( e.get_message(), "java.net.BindException" ) then
|
|
35 e.throw()
|
|
36 end
|
|
37 local host = Rpc.remote("localhost",port)
|
|
38 local args = Luan.arg
|
56
|
39 local file_paths = {}
|
37
|
40 for _, arg in ipairs(args) do
|
|
41 local file = new_file(arg)
|
|
42 file = file.canonical().to_string()
|
56
|
43 file_paths[#file_paths+1] = file
|
37
|
44 end
|
56
|
45 host.open_windows(file_paths)
|
37
|
46 host.close()
|
|
47 return
|
|
48 end
|
|
49
|
56
|
50 Rpc.functions.open_windows = open_windows
|
37
|
51
|
|
52 swing_run(function()
|
|
53 local args = Luan.arg
|
|
54 if #args == 0 then
|
|
55 new_window()
|
|
56 else
|
|
57 for _, arg in ipairs(args) do
|
|
58 local file = new_file(arg)
|
|
59 new_window(file)
|
|
60 end
|
|
61 end
|
|
62 end)
|
|
63
|
56
|
64 Rpc.serve_socket(server_socket,nil,function(socket,fns)
|
|
65 swing_run_later(Rpc.new_server_fn(socket,fns))
|
|
66 end)
|