view src/luan_editor/editor.luan @ 37:b7ff52d45b9a default tip

copy from luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 21 Apr 2025 13:07:29 -0600
parents
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local String = require "luan:String.luan"
local contains = String.contains or error()
local Io = require "luan:Io.luan"
local new_file = Io.schemes.file or error()
local Rpc = require "luan:Rpc.luan"
local Swing = require "luan:swing/Swing.luan"
local swing_run = Swing.run or error()
local to_front = Swing.to_front or error()
local new_window = require "classpath:luan_editor/window.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "editor/editor"


local port = 56587

Rpc.cipher_suites = nil
local server_socket
try
	server_socket = Rpc.new_server_socket(port)
catch e
	--logger.info(e.get_message())
	if not contains( e.get_message(), "java.net.BindException" ) then
		e.throw()
	end
	local host = Rpc.remote("localhost",port)
	local args = Luan.arg
	for _, arg in ipairs(args) do
		local file = new_file(arg)
		file = file.canonical().to_string()
		host.open(file)
	end
	host.to_front()
	host.close()
	return
end
function Rpc.functions.open(file_path)
	swing_run(function()
		local file = new_file(file_path)
		new_window(file)
	end)
end
function Rpc.functions.to_front()
	swing_run(to_front)
end


swing_run(function()
	local args = Luan.arg
	if #args == 0 then
		new_window()
	else
		for _, arg in ipairs(args) do
			local file = new_file(arg)
			new_window(file)
		end
	end
end)

Rpc.serve_socket(server_socket,nil,false)