From f2dcd16fc72e2f10c9504897bacf5c4c2ecff516 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 20 Oct 2021 19:36:15 +0800 Subject: +lua libs --- .../Libraries/json4lua/examples/jsonrpc.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Resources/DefaultContent/Libraries/json4lua/examples/jsonrpc.lua (limited to 'Resources/DefaultContent/Libraries/json4lua/examples/jsonrpc.lua') diff --git a/Resources/DefaultContent/Libraries/json4lua/examples/jsonrpc.lua b/Resources/DefaultContent/Libraries/json4lua/examples/jsonrpc.lua new file mode 100644 index 0000000..f265b8a --- /dev/null +++ b/Resources/DefaultContent/Libraries/json4lua/examples/jsonrpc.lua @@ -0,0 +1,21 @@ +-- +-- jsonrpc.lua +-- Installed in a CGILua webserver environment (with necessary CGI Lua 5.0 patch) +-- +require ('json.rpcserver') + +-- The Lua class that is to serve JSON RPC requests +local myServer = { + echo = function (msg) return msg end, + average = function(...) + local total=0 + local count=0 + for i=1, table.getn(arg) do + total = total + arg[i] + count = count + 1 + end + return { average= total/count, sum = total, n=count } + end +} + +json.rpcserver.serve(myServer) \ No newline at end of file -- cgit v1.1-26-g67d0