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()
|
|
12 local to_front = Swing.to_front or error()
|
|
13 local new_window = require "classpath:luan_editor/window.luan"
|
53
|
14 local Java = require "classpath:luan_editor/Java.luan"
|
37
|
15 local Logging = require "luan:logging/Logging.luan"
|
|
16 local logger = Logging.logger "editor/editor"
|
|
17
|
|
18
|
53
|
19 local port = Java.port
|
|
20 if port == nil then
|
|
21 port = 56587
|
|
22 else
|
|
23 port = to_number(port) or error("bad port: "..port)
|
|
24 end
|
37
|
25
|
|
26 Rpc.cipher_suites = nil
|
|
27 local server_socket
|
|
28 try
|
|
29 server_socket = Rpc.new_server_socket(port)
|
|
30 catch e
|
|
31 --logger.info(e.get_message())
|
|
32 if not contains( e.get_message(), "java.net.BindException" ) then
|
|
33 e.throw()
|
|
34 end
|
|
35 local host = Rpc.remote("localhost",port)
|
|
36 local args = Luan.arg
|
|
37 for _, arg in ipairs(args) do
|
|
38 local file = new_file(arg)
|
|
39 file = file.canonical().to_string()
|
|
40 host.open(file)
|
|
41 end
|
|
42 host.to_front()
|
|
43 host.close()
|
|
44 return
|
|
45 end
|
|
46 function Rpc.functions.open(file_path)
|
|
47 swing_run(function()
|
|
48 local file = new_file(file_path)
|
|
49 new_window(file)
|
|
50 end)
|
|
51 end
|
|
52 function Rpc.functions.to_front()
|
|
53 swing_run(to_front)
|
|
54 end
|
|
55
|
|
56
|
|
57 swing_run(function()
|
|
58 local args = Luan.arg
|
|
59 if #args == 0 then
|
|
60 new_window()
|
|
61 else
|
|
62 for _, arg in ipairs(args) do
|
|
63 local file = new_file(arg)
|
|
64 new_window(file)
|
|
65 end
|
|
66 end
|
|
67 end)
|
|
68
|
|
69 Rpc.serve_socket(server_socket,nil,false)
|