Mercurial Hosting > luan
diff core/src/luan/modules/Rpc.luan @ 610:b4f3dbe1c6e3
add Rpc and change Hosting to use Rpc
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Dec 2015 00:13:13 -0700 |
parents | |
children | ca169567ce07 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/src/luan/modules/Rpc.luan Fri Dec 11 00:13:13 2015 -0700 @@ -0,0 +1,38 @@ +java() +local RpcLuan = require "java:luan.modules.RpcLuan" +local Luan = require "luan:Luan" +local error = Luan.error +local set_metatable = Luan.set_metatable or error() +local Io = require "luan:Io" +local Thread = require "luan:Thread" + + +local M = {} + +M.call = RpcLuan.call -- Rpc.call(socket,fn_name,...) +M.respond = RpcLuan.respond -- Rpc.respond(socket,fns) + +function M.remote(socket_uri) + local mt = {} + function mt.__index(_,key) + return function(...) + local socket = Io.uri(socket_uri) + return M.call(socket,key,...) + end + end + local t = {} + set_metatable(t,mt) + return t +end + +--[[ +function M.serve(port,fns) + local server = Io.socket_server(port) + while true do + local socket = server() + Thread.fork(function() M.respond(socket,fns) end) + end +end +]] + +return M