comparison src/luan_editor/editor.luan @ 59:824f6d74b1d4

use launcher
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 04 Jun 2025 18:21:45 -0600
parents 6059b4e22d47
children 7f5b3824f4d4
comparison
equal deleted inserted replaced
58:7e2d6426c155 59:824f6d74b1d4
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local ipairs = Luan.ipairs or error() 3 local ipairs = Luan.ipairs or error()
4 local stringify = Luan.stringify or error()
4 local String = require "luan:String.luan" 5 local String = require "luan:String.luan"
5 local contains = String.contains or error()
6 local to_number = String.to_number or error() 6 local to_number = String.to_number or error()
7 local Io = require "luan:Io.luan" 7 local Io = require "luan:Io.luan"
8 local new_file = Io.schemes.file or error() 8 local new_file = Io.schemes.file or error()
9 local Rpc = require "luan:Rpc.luan" 9 local Launcher = require "luan:swing/Launcher.luan"
10 local Swing = require "luan:swing/Swing.luan"
11 local swing_run = Swing.run or error()
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()
16 local Java = require "classpath:luan_editor/Java.luan" 10 local Java = require "classpath:luan_editor/Java.luan"
17 local Logging = require "luan:logging/Logging.luan" 11 local Logging = require "luan:logging/Logging.luan"
18 local logger = Logging.logger "editor/editor" 12 local logger = Logging.logger "editor/editor"
19 13
20 14
21 local port = Java.port 15 local function open(args)
22 if port == nil then 16 local Window = require "classpath:luan_editor/Window.luan"
23 port = 56587 17 local new_window = Window.new_window or error()
24 else
25 port = to_number(port) or error("bad port: "..port)
26 end
27 18
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
39 local file_paths = {}
40 for _, arg in ipairs(args) do
41 local file = new_file(arg)
42 file = file.canonical().to_string()
43 file_paths[#file_paths+1] = file
44 end
45 host.open_windows(file_paths)
46 host.close()
47 return
48 end
49
50 Rpc.functions.open_windows = open_windows
51
52 swing_run(function()
53 local args = Luan.arg
54 if #args == 0 then 19 if #args == 0 then
55 new_window() 20 new_window()
56 else 21 else
57 for _, arg in ipairs(args) do 22 for _, arg in ipairs(args) do
58 local file = new_file(arg) 23 local file = new_file(arg)
59 new_window(file) 24 new_window(file)
60 end 25 end
61 end 26 end
62 end) 27 end
63 28
64 Rpc.serve_socket(server_socket,nil,function(socket,fns) 29 local function reopen(args)
65 swing_run_later(Rpc.new_server_fn(socket,fns)) 30 local Window = require "classpath:luan_editor/Window.luan"
66 end) 31 local open_windows = Window.open_windows or error()
32
33 open_windows(args)
34 end
35
36 local port = Java.port
37 if port ~= nil then
38 Launcher.port = to_number(port) or error("bad port: "..port)
39 end
40
41 local args = {nil}
42 for _, arg in ipairs(Luan.arg) do
43 local file = new_file(arg)
44 file = file.canonical().to_string()
45 args[#args+1] = file
46 end
47
48 Launcher.launch(open,reopen,args)