Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eval: Move VimL functions list to a lua file
Removes all kinds of problems with sorting, provides a ready-to-use function list representation for genvimvim.lua, does not require specifying function name twice (VimL function name (string) + f_ function name).
- Loading branch information
Showing
5 changed files
with
379 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
local nvimsrcdir = arg[1] | ||
local autodir = arg[2] | ||
|
||
if nvimsrcdir == '--help' then | ||
print([[ | ||
Usage: | ||
lua geneval.lua src/nvim build/src/nvim/auto | ||
Will generate build/src/nvim/auto/funcs.generated.h with definition of functions | ||
static const array. | ||
]]) | ||
os.exit(0) | ||
end | ||
|
||
package.path = nvimsrcdir .. '/?.lua;' .. package.path | ||
|
||
local funcsfname = autodir .. '/funcs.generated.h' | ||
local funcsfile = io.open(funcsfname, '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' | ||
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 | ||
)) | ||
end | ||
funcsfile:write('};\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.