source: trunk/third/librep/doc/embed-1 @ 15283

Revision 15283, 2.5 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15282, which included commits to RCS files with non-trunk default branches.
Line 
1Date: Mon, 14 Feb 2000 11:49:27 GMT
2From: John Harper <john@dcs.warwick.ac.uk>
3To: "Mikolaj J. Habryn" <dichro-mail-682f458@rcpt.to>
4Subject: Re: embedding librep
5
6Mikolaj J. Habryn writes:
7|  Hi John - do you have any simple examples of using librep in an
8|inferior role? I need a scripting interface for a program that I'm
9|writing, and I'd much rather re-use somebody else's code :) Is there
10|anything other than sawmill (or presumably jade) that I could squint
11|at and try to understand?
12
13the simplest (and only other) example is rep.c in librep/src, it's not
14commented so here's a slightly simplified annotated version (from cvs
15librep)
16
17#include <rep.h>
18
19static repv
20inner_main (repv arg)
21{
22        -- this boots the lisp environment, then loads the rep.jl[c] script
23
24    return rep_load_environment (rep_string_dup ("rep"));
25}
26
27int
28main(int argc, char **argv)
29{
30    char *prog_name = *argv++;
31    argc--;
32
33        -- this initialises the lisp data structures
34
35    rep_init (prog_name, &argc, &argv, 0, 0);
36
37    if (rep_get_option ("--version", 0))
38    {
39        printf ("rep version %s\n", REP_VERSION);
40        return 0;
41    }
42
43        -- this function is complex, it creates an execution context
44           then calls inner_main from within this new context. It's
45           needed because new librep does continuations and (soft)
46           threading
47
48    rep_call_with_barrier (inner_main, Qnil, rep_TRUE, 0, 0, 0);
49
50        -- this function just checks if an error occurred, if so it
51           will print some descriptive message, and returns a suitable
52           exit code
53
54    return rep_top_level_exit ();
55}
56
57
58But this is only half the story (or less). The main thing you'd have to
59understand is the C representation of Lisp data types. The header file
60rep_lisp.h defines this, and is reasonably well commented. For each
61data type there will be at least two macros rep_FOOP (x) which tests
62if a repv (a lisp pointer) is of type FOO, and rep_FOO (x) which casts
63the lisp pointer to the correct C pointer.
64
65So, e.g. for pairs, there's rep_CONSP and rep_CONS. There's also
66accessor macros rep_CAR (x) and rep_CDR (x) for this type.
67
68Another thing is that if a repv == rep_NULL, then an error occurred
69somewhere, and control should be unwound back to the top-level
70
71Garbage collection also complicates things, I posted a message to
72librep-list explaining the mechanics of this, it will be in the
73archives on sourceforge..
74
75I've been meaning to document all this, but it's quite an undertaking :-)
76
77If you decide to use rep, I'm happy to answer as many questions as you
78have, or just post them to librep-list@lists.sourceforge.net
79
80        John
81
82
Note: See TracBrowser for help on using the repository browser.