Skip to content
Nate Bogdanowicz edited this page Jul 26, 2017 · 1 revision

Ideas

This section is for brainstorming and developing ideas that might make their way into NiceLib.

Plugin/Hook System for Signatures

Currently signatures (for mid-level wrappers) are handled in one giant function (_cffi_wrapper) with lots of stacked if/elif statements. We could perhaps simplify this and make it more user-extensible by creating a system to register different arg signatures.

Imagine an arg-sig parser function which takes the arg's sig-string (possibly already slightly preprocessed), and either returns an ArgSigHandler or None (if there's no match). The registered parsers are run one-by-one on a given arg's sig-string until one of them matches. We could memoize these parser functions as well.

We would need some way of giving the functions (or maybe the ArgSigHandler instances?) access to the settings (e.g. buflen) for the given signature. Maybe through a settings argument which encapsulates all such settings. You might then also want a way to register new settings, but that may be overkill. You may also pass in the name and/or type of the arg.

An ArgSigHandler would be responsible for converting inputs for use by cffi and converting outputs for user consumption. One of the trickier problems would be handling grouped arguments, e.g. 'buf' paired with 'len'. We could define an optional ArgSigHandler method which gets passed the entire list of ArgSigHandlers after it is created, and call this method for each handler in order.

"Development Mode"

The ability to enable stricter errors or warnings for use in developing bindings. Could be used e.g. for function signatures that don't match any functions in the header. You may want to suppress errors/warnings like this for end-users if e.g. they may be using an older version of the library that's missing a function. They'd still obviously get an error if they tried to use the function, but it might be nice to avoid errors at import-time.

Clone this wiki locally