Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crystal-lang/clang.cr
libclang bindings for crystal (including automatic C bindings generator)
https://github.com/crystal-lang/clang.cr
Last synced: 7 days ago
JSON representation
libclang bindings for crystal (including automatic C bindings generator)
- Host: GitHub
- URL: https://github.com/crystal-lang/clang.cr
- Owner: crystal-lang
- License: other
- Created: 2017-09-23T10:25:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T07:57:14.000Z (7 months ago)
- Last Synced: 2024-10-21T22:12:29.462Z (13 days ago)
- Language: Crystal
- Homepage:
- Size: 75.2 KB
- Stars: 47
- Watchers: 13
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - clang.cr - Libclang bindings (C bindings)
- awesome-crystal - clang.cr - Libclang bindings (C bindings)
README
# libclang bindings for Crystal
Usage:
```crystal
require "clang"index = Clang::Index.new
files = [
#Clang::UnsavedFile.new("input.c", "#include \n"),
Clang::UnsavedFile.new("input.c", "#include \n"),
]
tu = Clang::TranslationUnit.from_source(index, files, [
"-I/usr/include",
"-I/usr/lib/llvm-5.0/include",
])tu.cursor.visit_children do |cursor|
p cursorClang::ChildVisitResult::Continue
end
```## Samples
See the `samples` folder for some example usages:
- `samples/debug.cr` will print the AST of C or C++ headers as they are parsed;
- `samples/c2cr.cr` will automatically generate Crystal bindings for a C header.For example:
```sh
$ shards build --release$ bin/c2cr -I/usr/lib/llvm-5.0/include llvm-c/Core.h \
--remove-enum-prefix=LLVM --remove-enum-suffix > llvm-c/Core.cr$ bin/c2cr -I/usr/lib/llvm-5.0/include clang-c/Index.h \
--remove-enum-prefix > clang-c/Index.cr$ bin/c2cr gtk-2.0/gtk/gtkenums.h --remove-enum-prefix > gtk/enums.cr
```## Reference
- [C interface to Clang](http://clang.llvm.org/doxygen/group__CINDEX.html)
## License
Distributed under the Apache 2.0 license.