Utility to create lbstanza wrappers from C headers
Project description
This project contains some python tools for making wrappers around C libraries in stanza. The idea is to convert the C syntax into something that stanza can read and process.
These tools are based on pycparser.
Setup
- ::
pip install lbstanza-wrappers
Examples
Extract an Enumerated Type in C:
Example Header: libtidy
/** A Tidy configuration option can have one of these data types. */
typedef enum
{
TidyString, /**< String */
TidyInteger, /**< Integer or enumeration */
TidyBoolean /**< Boolean */
} TidyOptionType;
First pass this though the C PREPROCESSOR so that we get rid of symbols and things that the pycparser can’t handle:
gcc -E -std=c99 ./tidy-html5/include/tidyenum.h > header.h
Then we can run the tool:
convert2stanza.py --input header.h enums --out-dir ./temp --pkg-prefix "tidy/Enums"
This will create a file ./temp/TidyOptionType.stanza (among others) containing:
defpackage tidy/Enums/TidyOptionType : import core public deftype TidyOptionType public deftype TidyString <: TidyOptionType public deftype TidyInteger <: TidyOptionType public deftype TidyBoolean <: TidyOptionType public defn to-int (v:TidyOptionType) -> Int: match(v) : (x:TidyString) : 0 (x:TidyInteger) : 1 (x:TidyBoolean) : 2 public defn TidyOptionType (v:Int) -> TidyOptionType : switch {v == _}: 0 : new TidyString 1 : new TidyInteger 2 : new TidyBoolean else: throw(Exception("Invalid Exception Value")) public lostanza defn TidyOptionType (v:int) -> ref<TidyOptionType> : return TidyOptionType(new Int{v}) defmethod print (o:OutputStream, v:TidyOptionType) : match(v) : (x:TidyString) : print(o, "TidyString") (x:TidyInteger) : print(o, "TidyInteger") (x:TidyBoolean) : print(o, "TidyBoolean")
See lbstanza-tidy
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lbstanza-wrappers-0.3.0.tar.gz
(23.5 kB
view hashes)
Built Distribution
Close
Hashes for lbstanza_wrappers-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f69711aaa140fd391ba54212a4ca84c9d8defb8e8e7bfec2614743218bde4201 |
|
MD5 | 80a821b4dff491ca174f27384b2f8de5 |
|
BLAKE2b-256 | 61142006ae6c3cd3163dc7822682d65e3752de748d315c0ca21c539f9b89ad16 |