ljclang

FORK: A LuaJIT-based interface to libclang
git clone https://git.neptards.moe/neptards/ljclang.git
Log | Files | Refs

createheader.lua (1229B)


      1 #!/usr/bin/env luajit
      2 
      3 local io = require("io")
      4 local os = require("os")
      5 
      6 local dir = arg[1]
      7 
      8 if (dir == nil) then
      9     print("Usage: ", arg[0], " /usr/path/to/clang-c/ > ljclang_Index_h.lua")
     10     os.exit(1)
     11 end
     12 
     13 local function loadandstrip(filename)
     14     local f, errmsg = io.open(dir.."/"..filename)
     15     if (f==nil) then
     16         print("Error opening file: ", errmsg)
     17         os.exit(2)
     18     end
     19 
     20     local str = f:read("*a")
     21     f:close()
     22 
     23     -- Remove...
     24     return str:gsub("#ifdef __.-#endif\n", "")  -- #ifdef __cplusplus/__have_feature ... #endif
     25               :gsub("#define.-[^\\]\n", "")  -- multi-line #defines
     26               :gsub("/%*%*.-%*/", "")  -- comments, but keep headers with license ref
     27               :gsub("#[^\n]-\n", "")  -- single-line preprocessor directives
     28               :gsub("CINDEX_LINKAGE","")
     29               :gsub("CINDEX_DEPRECATED","")
     30               :gsub("time_t", "// time_t")  -- clang_getFileTime declaration
     31               :gsub(" *\n+", "\n")
     32 end
     33 
     34 local cxstring_h = loadandstrip("CXString.h")
     35 local cxcompdb_h = loadandstrip("CXCompilationDatabase.h")
     36 local index_h = loadandstrip("Index.h")
     37 
     38 print("require('ffi').cdef[==========[\n",
     39       cxstring_h, cxcompdb_h, index_h, "]==========]")