aboutsummaryrefslogtreecommitdiff
path: root/scripts/msgpack-gen.lua
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-04-10 13:00:12 -0400
committerScott Prager <splinterofchaos@gmail.com>2015-04-13 10:20:42 -0400
commit8d59e74f6ca619f9466cbb8bda107ec8bf399915 (patch)
tree1744e8a0200d89e1297a5684e1faa941534e0045 /scripts/msgpack-gen.lua
parent48c5b85fb405f6e8aaae8acf41e6076d9dd21602 (diff)
downloadrneovim-8d59e74f6ca619f9466cbb8bda107ec8bf399915.tar.gz
rneovim-8d59e74f6ca619f9466cbb8bda107ec8bf399915.tar.bz2
rneovim-8d59e74f6ca619f9466cbb8bda107ec8bf399915.zip
msgpack: coerce Ints to Windows/Buffers/Tabpages
Add conversion checking when generating msgpack handlers.
Diffstat (limited to 'scripts/msgpack-gen.lua')
-rw-r--r--scripts/msgpack-gen.lua15
1 files changed, 11 insertions, 4 deletions
diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua
index 9ff9b4cf6f..bb37ae94da 100644
--- a/scripts/msgpack-gen.lua
+++ b/scripts/msgpack-gen.lua
@@ -183,13 +183,20 @@ for i = 1, #functions do
local converted, convert_arg, param, arg
param = fn.parameters[j]
converted = 'arg_'..j
- if real_type(param[1]) ~= 'Object' then
- output:write('\n if (args.items['..(j - 1)..'].type != kObjectType'..real_type(param[1])..') {')
+ local rt = real_type(param[1])
+ if rt ~= 'Object' then
+ output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..') {')
+ output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..rt:lower()..';')
+ if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') or rt:match('^Boolean$') then
+ -- accept positive integers for Buffers, Windows and Tabpages
+ output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer > 0) {')
+ output:write('\n '..converted..' = (unsigned)args.items['..(j - 1)..'].data.integer;')
+ end
+ output:write('\n } else {')
output:write('\n snprintf(error->msg, sizeof(error->msg), "Wrong type for argument '..j..', expecting '..param[1]..'");')
output:write('\n error->set = true;')
output:write('\n goto cleanup;')
- output:write('\n }')
- output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..real_type(param[1]):lower()..';\n')
+ output:write('\n }\n')
else
output:write('\n '..converted..' = args.items['..(j - 1)..'];\n')
end