Skip to main content

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.2.1.tar.gz (24.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page