aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gen_lua_c_api_tags.lua
blob: 465a6c60ba3cd02cb28611710ca684fe3b46b29d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/lua
-- Copyright 2007-2022 Mitchell. See LICENSE.

local f = io.open('../modules/ansi_c/lua_tags', 'w')
-- Lua header files define API functions in a way ctags cannot detect.
-- For example: `LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);`.
-- The function name enclosed in parenthesis is causing the problem. A regex must be used to
-- capture those definitions.
local p = io.popen('ctags -o - --regex-c++="/\\(([a-zA-Z_]+)\\) +\\(/\\1/f/" ' ..
  '../src/lua/src/lua.h ../src/lua/src/lauxlib.h')
for line in p:read('*a'):gmatch('[^\n]+') do
  -- Strip comment lines and replace file and ex_cmd fields with empty info.
  if not line:find('^!') then
    local tag, _, _, ext_fields = line:match('^(%S+)\t(%S+)\t(.-);"\t?(.*)$')
    f:write(tag, '\t_\t0;"\t', ext_fields, '\n')
  end
end
p:close()
f:close()