On Wed, Feb 26, 2014 at 6:13 PM, Ron Wilson <ronw.m...@gmail.com> wrote:

> I haven't had a chance to look at your scripting engine, but I would have
> thought that the scripting bindings would have been implemented with
> "primitives" written in C that map the scripting engine's data model to C's
> data model.
>

It's basically a JS-like data model (derived initially, in fact, from the
same JSON code which runs fossil's JSON API), but provides a facility for
clients to plug their own types into it (in a type-safe way - you don't
have to blindly guess the type of the underlying void pointer!). libfossil
uses that to bind, e.g., the Db and Db.Stmt classes.


> PS: An example of what I mean: Years ago, I wrote bindings for a scripting
> engine to use a library that had a C API. I wrote a set of primitives like
> the following:
>
> int x_Send(Context *cx)
> {
>     int port;
>     int len;
>     char buf[1024];
>
>     port = e_GetInt(cx, 0); // get int parameter at index 0
>     len = e_GetString(cx, 1, sizeof(buf), buf); // get string at 1
>

Conceptually, that's not much different from what a script-bound callback
looks like. Here's a short/simple example:

http://fossil.wanderinghorse.net/repos/libfossil/index.cgi/artifact/7d4c2ee11081393cf907ad8a61151a65f17bc3da?ln=862-887



>         e_ReturnInt(0); // set an int return value
>

in mine that is done via an assignment to a (cwal_value**) passed in by the
caller (the scripting engine). If the callback does not set it, it's
treated like a void return, otherwise the engine takes care of making sure
the value provided it is moved into the calling scope so that it doesn't
get GC'd when the function's scope ends. Developing the whole GC model was
the initial inspiration behind th1ish - i wanted to experiment with a
hypothetical ownership tracking model i had been considering for several
years. Fossil's th1 finally gave me the catalyst to try it out (which is
where the name th1ish comes from). If you're into that type of thing (it
looks like you are), the main docs have a chapter (look near the end) which
goes into more detail about how gc works in th1ish:

https://docs.google.com/document/d/1PDi7lwufondH4GGRunh1kFSOYkrl1xqL9cXea8mVCLk/view

or in a somewhat more rambling form here:

http://fossil.wanderinghorse.net/repos/cwal/index.cgi/wiki?name=cwal_gc

Anyway...

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to