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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lbstanza-wrappers-0.3.0.tar.gz.
File metadata
- Download URL: lbstanza-wrappers-0.3.0.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5a2dc174b26cc87ed555df634a2708c7958c4b9fab35557b46f3740e005074e
|
|
| MD5 |
9f9dbb6a069c08975f2aeda982b60580
|
|
| BLAKE2b-256 |
2b2fac7d64da14c9f7c761b23a78e77b284c5be7184dd11b2861d3a7da49a41d
|
File details
Details for the file lbstanza_wrappers-0.3.0-py3-none-any.whl.
File metadata
- Download URL: lbstanza_wrappers-0.3.0-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f69711aaa140fd391ba54212a4ca84c9d8defb8e8e7bfec2614743218bde4201
|
|
| MD5 |
80a821b4dff491ca174f27384b2f8de5
|
|
| BLAKE2b-256 |
61142006ae6c3cd3163dc7822682d65e3752de748d315c0ca21c539f9b89ad16
|