aboutsummaryrefslogtreecommitdiff
path: root/scripts/msgpack-gen.lua
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-09-07 20:40:07 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-09-12 13:25:28 -0300
commit2f566c83d9eee4a8097c9a18eb58dcef6adf894e (patch)
treea2e5ce0f973daab14237b66e8c023fe381a34e10 /scripts/msgpack-gen.lua
parentd5a60d17fbca33ca96124288e69937a276d3abda (diff)
downloadrneovim-2f566c83d9eee4a8097c9a18eb58dcef6adf894e.tar.gz
rneovim-2f566c83d9eee4a8097c9a18eb58dcef6adf894e.tar.bz2
rneovim-2f566c83d9eee4a8097c9a18eb58dcef6adf894e.zip
api/msgpack-rpc: Parse type information from api/private/defs.h
Enhance msgpack-gen.lua to extract custom api type codes from the ObjectType enum in api/private/defs.h. The type information is made available from the api metadata and clients can use to correctly serialize/deserialize these types using msgpack EXT type.
Diffstat (limited to 'scripts/msgpack-gen.lua')
-rw-r--r--scripts/msgpack-gen.lua25
1 files changed, 22 insertions, 3 deletions
diff --git a/scripts/msgpack-gen.lua b/scripts/msgpack-gen.lua
index 36fe07896b..7da52432d6 100644
--- a/scripts/msgpack-gen.lua
+++ b/scripts/msgpack-gen.lua
@@ -38,9 +38,28 @@ assert(#arg >= 1)
-- api metadata
api = {
functions = {},
- -- Helpers for object-oriented languages
- classes = {'Buffer', 'Window', 'Tabpage'}
+ types = {}
}
+
+-- Extract type codes from api/private/defs.h. The codes are values between
+-- comment markers in the ObjectType enum
+local typedefs_header = arg[1]
+local input = io.open(typedefs_header, 'rb')
+local reading_types = false
+while true do
+ local line = input:read('*l'):gsub("^%s*(.-)%s*$", "%1")
+ if reading_types then
+ if line == '// end custom types' then
+ break
+ end
+ local type_name = line:gsub("^kObjectType(.-),$", "%1")
+ api.types[#api.types + 1] = type_name
+ else
+ reading_types = line == '// start custom types'
+ end
+end
+input:close()
+
-- names of all headers relative to the source root(for inclusion in the
-- generated file)
headers = {}
@@ -48,7 +67,7 @@ headers = {}
outputf = arg[#arg]
-- read each input file, parse and append to the api metadata
-for i = 1, #arg - 1 do
+for i = 2, #arg - 1 do
local full_path = arg[i]
local parts = {}
for part in string.gmatch(full_path, '[^/]+') do