Mercurial Hosting > luan
diff http/src/luan/modules/http/Server.luan @ 743:2c41f2aec92f
improve Rpc and implement rpc call for local webserver
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 13 Jul 2016 17:27:35 -0600 |
parents | 20051fe2a943 |
children | 5e3970ccd86a |
line wrap: on
line diff
--- a/http/src/luan/modules/http/Server.luan Tue Jul 12 17:47:30 2016 -0600 +++ b/http/src/luan/modules/http/Server.luan Wed Jul 13 17:27:35 2016 -0600 @@ -1,10 +1,17 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local try = Luan.try or error() local String = require "luan:String.luan" -local gsub = String.gsub -local matches = String.matches +local gsub = String.gsub or error() +local matches = String.matches or error() local Io = require "luan:Io.luan" local Package = require "luan:Package.luan" +local Rpc = require "luan:Rpc.luan" +local Thread = require "luan:Thread.luan" local Http = require "luan:http/Http.luan" require "luan:logging/init.luan" -- initialize logging +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "http/Server" java() local Server = require "java:org.eclipse.jetty.server.Server" @@ -97,9 +104,30 @@ M.server.start() end +function M.start_rpc() + function Rpc.functions.call(domain,fn_name,...) + return M.luan_handler.call_rpc(fn_name,...) + end + + local function run_server() + local responder = Rpc.responder() + while true do + try { + responder + catch = function(e) + logger.warn(e) + end + } + end + end + + Thread.fork(run_server) +end + function M.serve(dir) M.init(dir) M.start() + M.start_rpc() end return M