comparison 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
comparison
equal deleted inserted replaced
609:24b05963ba62 610:b4f3dbe1c6e3
1 java()
2 local RpcLuan = require "java:luan.modules.RpcLuan"
3 local Luan = require "luan:Luan"
4 local error = Luan.error
5 local set_metatable = Luan.set_metatable or error()
6 local Io = require "luan:Io"
7 local Thread = require "luan:Thread"
8
9
10 local M = {}
11
12 M.call = RpcLuan.call -- Rpc.call(socket,fn_name,...)
13 M.respond = RpcLuan.respond -- Rpc.respond(socket,fns)
14
15 function M.remote(socket_uri)
16 local mt = {}
17 function mt.__index(_,key)
18 return function(...)
19 local socket = Io.uri(socket_uri)
20 return M.call(socket,key,...)
21 end
22 end
23 local t = {}
24 set_metatable(t,mt)
25 return t
26 end
27
28 --[[
29 function M.serve(port,fns)
30 local server = Io.socket_server(port)
31 while true do
32 local socket = server()
33 Thread.fork(function() M.respond(socket,fns) end)
34 end
35 end
36 ]]
37
38 return M