Skip to content

thenumbernine/c-h-parser-lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Donate via Stripe

C Header Parser in Lua

This is a C header parser. No C function bodies allowed.

c-h-parser.lua

This file parses C headers into an AST.

How to process a single file:

local CHParser = require 'c-h-parser'
local chparser = CHParser(code)

How to process multiple files:

local CHParser = require 'c-h-parser'
local chparser = CHParser()
chparser(file1data)
chparser(file2data)
...

The resulting chparser object contains the following:

  • .declTypes = list of types declared.
  • .anonEnumValues = list of enum values that weren't stored in named enum types.
  • .symbolsInOrder = list of symbols declared.

Dependencies

This uses my parser library.

Hisotry and Motivation:

Before this I using my C-preprocessor in Lua to generate my LuaJIT binding code from C headers of various libraries / include files. This was fine, but sometimes I would need ot organize the results by hand. Especially when using my proxying the LuaJIT table that tends to overflow. In that case I'd have to separate by hand the requires, the types, the enums, the symbols, and the uncompiled macros.

Act 2, I made a Lua+FFI emulation in JS. The oldest proof-of-concept of this implemented Lua's FFI module in pure lua. From this I had a ffi.cdef parser in Lua just lying around.

This target use of this project is to wedge in between the preprocessor and the LuaJIT bindings. Especially for the purpose of writing those libwrappers.

Final stage is probably going to be moving the make.lua, generate.lua, include-list.lua out of preproc and into a half-started repo of the same purpose: include-lua. Then it would be include-lua -> c-header-lua -> preproc-lua (rename that one to c-preproc maybe?).

Extra points if I convert preproc to use parser-lua, as I'm writing this C header parser to use parser-lua.

Extra double points if I use include-lua for its original purpose. That is make it so it either includes a binding header or generates one live. I could couple this with the current lua-ffi-bindings folder that is already searching for the binding headers per-os/arch/etc, to make it so if the file isn't found the it just goes to the include-lua for automatic generation if the header is accessible.

About

C header parser in Lua

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

 
 
 

Contributors