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

Revision 15283, 3.9 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 13:31:51 GMT
2From: John Harper <john@dcs.warwick.ac.uk>
3To: "Mikolaj J. Habryn" <dichro-mail-766da09@rcpt.to>
4Subject: Re: embedding librep
5
6Mikolaj J. Habryn writes:
7|  Hmm - I'm having trouble reaching sourceforge at the moment, but
8|I'll dig through the archives and subscribe as soon as that changes.
9
10well, there's not much there, but there may be a few useful messages..
11
12|
13|  It appears that rep_load_environment does the actual execution of
14|the code - I presume that what I want to do is register lambda
15|expressions inside there (calling back into the C-code to do so), and
16|then return into inner_main.
17
18rep_load_environment is usually just used to do initialisation, in the
19case of rep.c it's the whole program, but that's not usual. Sawmill
20main.c is probably a better example, it's inner_main does the
21following:
22
23static repv
24inner_main (repv arg)
25{
26    repv res = rep_load_environment(rep_string_dup ("sawmill"));
27    if (res != rep_NULL)
28    {
29        /* final initialisation.. */
30        if(rep_SYM(Qbatch_mode)->value == Qnil)
31            manage_windows ();
32
33        /* then jump into the event loop.. */
34        if(rep_SYM(Qbatch_mode)->value == Qnil)
35            res = Frecursive_edit ();
36    }
37    return res;
38}
39
40this is called after all exported lisp functions have been registered.
41manage_windows is a function to adopt all existing top-level windows,
42Frecursive_edit is rep's built-in event loop (you use
43rep_register_input_fd to register a function to be called when data
44arrives on a particular fd, e.g. sawmill's X connection)
45
46after this function exits, so will sawmill
47
48|
49|  How do I make a C function visible to the lisp code, to register the
50|hooks with, and so that the hooks can get extra information if they
51|need it?
52
53by convention a lisp function `foo-bar' is represented by a C function
54Ffoo_bar and a subroutine data object Sfoo_bar. These are defined using
55the DEFUN macro:
56
57DEFUN ("foo-bar", Ffoo_bar, Sfoo_bar, (repv arg1), rep_Subr1)
58{
59        /* signal an error if `arg1' isn't a cons */
60        rep_DECLARE (1, arg1, rep_CONSP (arg1));
61
62        ... do something with arg
63
64        return some-result-repv;
65}
66
67(repv arg1) is the actual argument list for the function, rep_Subr1
68defines the type of the subroutine object, in this case a function
69receiving a single argument, there's rep_Subr[1-5] and rep_SubrN which
70takes a single parameter, the _list_ of arguments given to the function
71
72to register this function with the interpreter it's necessary to then
73call:
74        rep_ADD_SUBR (Sfoo_bar);
75
76in an initialisation function somewhere.
77
78|
79|  How do I actually call the hooks, once they've been registered with
80|the C code?
81
82DEFUN-declared functions can be called as normal C functions. To create
83a hook, you need to define a symbol, i.e.:
84
85DEFSYM (foo_bar, "foo-bar");
86
87this sets up storage for a symbol `foo-bar', and creates a `repv Qfoo_bar'
88variable. You then need to call
89
90        rep_INTERN (foo_bar);
91
92in an initialisation function to initialise `Qfoo_bar'. If the symbol
93needs dynamic scope (i.e. it's used to represent a hook), then you do:
94
95        rep_INTERN_SPECIAL (foo_bar);
96
97you can then do for example:
98
99        Fset (Qfoo_bar, Qnil);
100
101to initialise it to nil, though that's not actually required for hooks.
102
103To invoke a hook, use Fcall_hook, i.e.
104
105        Fcall_hook (Qfoo_bar, ARG-LIST, TYPE)
106
107ARG-LIST is the list of argument values to pass to the hook, e.g. to
108pass a single value use `rep_LIST_1 (VALUE)'. TYPE is a symbol defining
109how to interpret the values returned by functions, usually just use
110Qnil to force all functions in the hook to be called.
111
112If you just want to call a single lisp function, you can use
113rep_call_lispN, for example:
114
115        rep_call_lisp1 (Fsymbol_value (Qfoo_bar, Qt), VALUE);
116
117when you do anything that may execute lisp code, you need to careful
118about garbage collection. Basically, you must have told the interpreter
119about any lisp values you're going to use after the called lisp code
120finishes executing.
121
122        John
123
Note: See TracBrowser for help on using the repository browser.