view core/src/luan/modules/Rpc.luan @ 647:8e8c30b72e9b

move methods from LuanState to Luan
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Mar 2016 20:39:14 -0600
parents b4f3dbe1c6e3
children ca169567ce07
line wrap: on
line source

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