router.add_method("use_safe_encode", () => { return { message:"This is a safe encoded message.", function:function () {}, // This will be serialized as 'function' }; });
router.add_method("throws", () => { thrownewError("This is an error from the server."); });
while (true) { server.process_rpc(router); }
Lua Example
local____lualib = require("lualib_bundle") localError = ____lualib.Error localRangeError = ____lualib.RangeError localReferenceError = ____lualib.ReferenceError localSyntaxError = ____lualib.SyntaxError localTypeError = ____lualib.TypeError localURIError = ____lualib.URIError local__TS__New = ____lualib.__TS__New local____exports = {} local____pelican = require("pelican") localjsonrpc = ____pelican.jsonrpc local____users = require("server.users") localadd_users = ____users.add_users PELICAN = {logger_level = "error"} localserver = jsonrpc.JsonRpcServer.new({port = 1234, host = "localhost"}) localrouter = jsonrpc.JsonRpcRouter.new() add_users(nil, router) router:add_method( "ping", function(props) return ("Pong, " .. props.message) .. "!" end ) router:add_method( "use_safe_encode", function() return { message = "This is a safe encoded message.", ["function"] = function(self) end } end ) router:add_method( "throws", function() error( __TS__New(Error, "This is an error from the server."), 0 ) end ) whiletruedo server:process_rpc(router) end return____exports
The
jsonrpc
module provides a JSON-RPC server and router for handling JSON-RPC requests.TypeScript Example
Lua Example
No Self