lloyd / yajl

A fast streaming JSON parsing library in C.
http://lloyd.github.com/yajl
ISC License
2.15k stars 435 forks source link

usability: introduce callback function types #193

Open ototo opened 7 years ago

ototo commented 7 years ago

To let users of yajl writing code that is cleaner, a set of callback function types is introduced by this patch.

Old (before this patch) way of using callbacks:

// Callback definition
static int my_parse_null(void *raw_ctx)
{
    ProjectSpecificType *ctx = (ProjectSpecificType *) raw_ctx;

    // the code that is using ctx follows...
}

// ...

// Setting the callback
yajl_callbacks cb;
cb.yajl_null = my_parse_null;

New (with this patch applied) way of using callbacks

// Callback definition
static int my_parse_null(ProjectSpecificType *ctx)
{
    // the code that is using ctx follows...
}

// ...

// Setting the callback
yajl_callbacks cb;
cb.yajl_null = (yajl_null_t) my_parse_null;

Both (the old and the new) ways of using callbacks are supported with no changes to the existing code needed.

Signed-off-by: Serge Broslavsky serge.broslavsky@linaro.org