[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] Re: add lua-scripting to leafnode2

On Thu, 19 Jun 2008 21:43:33 +0200 clemens fischer wrote:

> C. Albrecht (in private mail):

> i'm planning to add lua-scripting support to leafnode2.

> > How about a scripting language other than lua, one that's more well
> > known, like perl?
> >
> > Or, better yet, how about a sufficiently generic interface such that
> > if you add lua, I could add perl for myself and Joe could ad python
> > for himself?

well, all the code comes in three files: script-lua.c, script-lua.h and
script.h. the first two contain lua specific code. script.h contains
a very lean magic implementing just that: depending on which type of
scripting is requested, the necessary header files are included or
macros defined. for example, if no scripting is desired, script.h
contains dummy definitions for the stubs in fetchnews. the compilers
preprocessor substitutes them with nothing, which effectively compiles
fetchnews "proper", ie. without any scripting.

currently only the original ln2 file called "store.c" is instrumented
with calls like: "script_err = script_init_article()", "script_err =
script_add_headers(head)" etc. thus anybody wanting to implement python-
or perl-scripting just needs to add, eg. script-{perl,python}.{c,h} and
implement "script_init_article()" et.al.  the instrumentation calls only
have to be changed for new features, but not (necessarily) for certain
script-language interfaces.

> > I would like perl, because then one could conceivably integrate
> > SpamAssassin processing into leafnode2.

then you have the following alternatives:  model the interface to SA in
lua or add perl-scripting.

the reason i chose lua were:

> i picked lua as the language for the extensions because (a) matthias
> mentioned it in a private mail, (b) it is quite easy to implement, (c)
> users can easily add a lua-sockets module and use it for persistent
> connections to their favourite filter-engine, and (d) it is nice and
> easy to program in. you might want to check <url:http://www.lua.org>
> for further information on the language.

the scripting addon will be as lightweight and generic as possible.
lua comes in the form of a library. the entire compiler + interpreter
+ builtin-libs + utility-libs is 155648 bytes of size. these numbers
are from the mappings of a live elinks-browser on freebsd-current, they
may vary for other platforms. lua compiles, embeds and acts the same on
every supported platform.

i cannot imagine perl or python to sum up to less then 200kB, but
nonetheless i don't want to be in the way.  if you want another language
and can embed it, please help yourself.  i would strongly suggest
waiting for the completion of the lua-scripting though.

as interfacing to lua and from lua to C isn't very difficult, it might
well turn out to be an easier task once the interface has stabilized.

lua has lexical scoping, provides closures, does automatic memory
management, handles multiple return values etc. it might suit most
peoples programming styles, there are readymade modules to connect
sockets and it is supported by SWIG[1]. also, lua is considered to be a
fast scripting language. i think one gets the most out of using lua for
this effort.

[1] <url:http://www.swig.org/>

regards, clemens

leafnode-list mailing list