diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gendispatch.lua | 18 | ||||
-rw-r--r-- | scripts/geneval.lua | 21 |
2 files changed, 30 insertions, 9 deletions
diff --git a/scripts/gendispatch.lua b/scripts/gendispatch.lua index 54bfdab45b..ce1d8be222 100644 --- a/scripts/gendispatch.lua +++ b/scripts/gendispatch.lua @@ -41,18 +41,20 @@ c_proto = Ct( ) grammar = Ct((c_proto + c_comment + c_preproc + ws) ^ 1) --- we need at least 2 arguments since the last one is the output file -assert(#arg >= 1) +-- we need at least 3 arguments since the last two are output files +assert(#arg >= 2) functions = {} -- names of all headers relative to the source root (for inclusion in the -- generated file) headers = {} --- output file(dispatch function + metadata serialized with msgpack) -outputf = arg[#arg] +-- output c file(dispatch function + metadata serialized with msgpack) +outputf = arg[#arg-1] +-- output mpack file (metadata) +mpack_outputf = arg[#arg] -- read each input file, parse and append to the api metadata -for i = 1, #arg - 1 do +for i = 1, #arg - 2 do local full_path = arg[i] local parts = {} for part in string.gmatch(full_path, '[^/]+') do @@ -165,7 +167,7 @@ for i = 1, #functions do local fn = functions[i] local args = {} - output:write('static Object handle_'..fn.name..'(uint64_t channel_id, uint64_t request_id, Array args, Error *error)') + output:write('Object handle_'..fn.name..'(uint64_t channel_id, uint64_t request_id, Array args, Error *error)') output:write('\n{') output:write('\n Object ret = NIL;') -- Declare/initialize variables that will hold converted arguments @@ -311,3 +313,7 @@ MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name, ]]) output:close() + +mpack_output = io.open(mpack_outputf, 'wb') +mpack_output:write(packed) +mpack_output:close() diff --git a/scripts/geneval.lua b/scripts/geneval.lua index c9533d7908..396e7b81db 100644 --- a/scripts/geneval.lua +++ b/scripts/geneval.lua @@ -1,5 +1,8 @@ +mpack = require('mpack') + local nvimsrcdir = arg[1] local autodir = arg[2] +local metadata_file = arg[3] if nvimsrcdir == '--help' then print([[ @@ -18,9 +21,20 @@ local funcsfname = autodir .. '/funcs.generated.h' local funcspipe = io.open(funcsfname .. '.hsh', 'w') -local funcs = require('eval') +local funcs = require('eval').funcs + +local metadata = mpack.unpack(io.open(arg[3], 'rb'):read("*all")) + +for i,fun in ipairs(metadata) do + funcs['api_'..fun.name] = { + args=#fun.parameters, + func='api_wrapper', + data='handle_'..fun.name, + } +end + -for name, def in pairs(funcs.funcs) do +for name, def in pairs(funcs) do args = def.args or 0 if type(args) == 'number' then args = {args, args} @@ -28,7 +42,8 @@ for name, def in pairs(funcs.funcs) do args[2] = 'MAX_FUNC_ARGS' end func = def.func or ('f_' .. name) - local val = ('{ %s, %s, &%s }'):format(args[1], args[2], func) + data = def.data or "NULL" + local val = ('{ %s, %s, &%s, %s }'):format(args[1], args[2], func, data) funcspipe:write(name .. '\n' .. val .. '\n') end funcspipe:close() |