view core/src/luan/modules/Rpc.luan @ 693:ca169567ce07

module URIs must now include ".luan"
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 Apr 2016 15:54:11 -0600
parents b4f3dbe1c6e3
children 2c41f2aec92f
line wrap: on
line source

java()
local RpcLuan = require "java:luan.modules.RpcLuan"
local Luan = require "luan:Luan.luan"
local error = Luan.error
local set_metatable = Luan.set_metatable or error()
local Io = require "luan:Io.luan"
local Thread = require "luan:Thread.luan"


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