From 5e59916e84933b0b05fda8ed76cf5f24fa3f48b6 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 1 Jan 2016 14:37:20 +0300 Subject: eval: Use generated hash to look up function list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problems: - Disables cross-compiling (alternative: keeps two hash implementations which need to be synchronized with each other). - Puts code-specific name literals into CMakeLists.txt. - Workaround for lua’s absence of bidirectional pipe communication is rather ugly. --- scripts/geneval.lua | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/geneval.lua b/scripts/geneval.lua index 1f8a14d27b..c9533d7908 100644 --- a/scripts/geneval.lua +++ b/scripts/geneval.lua @@ -15,28 +15,20 @@ end package.path = nvimsrcdir .. '/?.lua;' .. package.path local funcsfname = autodir .. '/funcs.generated.h' -local funcsfile = io.open(funcsfname, 'w') + +local funcspipe = io.open(funcsfname .. '.hsh', 'w') local funcs = require('eval') -local sorted_funcs = {} for name, def in pairs(funcs.funcs) do - def.name = name - def.args = def.args or 0 - if type(def.args) == 'number' then - def.args = {def.args, def.args} - elseif #def.args == 1 then - def.args[2] = 'MAX_FUNC_ARGS' + args = def.args or 0 + if type(args) == 'number' then + args = {args, args} + elseif #args == 1 then + args[2] = 'MAX_FUNC_ARGS' end - def.func = def.func or ('f_' .. def.name) - sorted_funcs[#sorted_funcs + 1] = def -end -table.sort(sorted_funcs, function(a, b) return a.name < b.name end) - -funcsfile:write('static const VimLFuncDef functions[] = {\n') -for _, def in ipairs(sorted_funcs) do - funcsfile:write((' { "%s", %s, %s, &%s },\n'):format( - def.name, def.args[1], def.args[2], def.func - )) + func = def.func or ('f_' .. name) + local val = ('{ %s, %s, &%s }'):format(args[1], args[2], func) + funcspipe:write(name .. '\n' .. val .. '\n') end -funcsfile:write('};\n') +funcspipe:close() -- cgit