summaryrefslogtreecommitdiff
path: root/script/proto/proto.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/proto/proto.lua')
-rw-r--r--script/proto/proto.lua21
1 files changed, 20 insertions, 1 deletions
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 944268c2..fe0277ef 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -68,7 +68,7 @@ function m.notify(name, params)
end
function m.awaitRequest(name, params)
- local id = reqCounter()
+ local id = reqCounter()
local buf = jsonrpc.encode {
id = id,
method = name,
@@ -85,6 +85,25 @@ function m.awaitRequest(name, params)
return result
end
+function m.request(name, params, callback)
+ local id = reqCounter()
+ local buf = jsonrpc.encode {
+ id = id,
+ method = name,
+ params = params,
+ }
+ --log.debug('Request', name, #buf)
+ io.stdout:write(buf)
+ m.waiting[id] = function (result, error)
+ if error then
+ log.warn(('Response of [%s] error [%d]: %s'):format(name, error.code, error.message))
+ end
+ if callback then
+ callback(result)
+ end
+ end
+end
+
function m.doMethod(proto)
local method, optional = m.getMethodName(proto)
local abil = m.ability[method]