[Ecls-list] embedding ecl into a game engine

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun May 17 13:18:50 UTC 2009

On Sat, May 9, 2009 at 3:19 AM, Ilya Kliot <plushe at gmail.com> wrote:
> Anyway let me clear a picture. The starting process is an engine,
> all the objects (instances)  of the engine organized into a tree at
> runtime - like a file system, so all the time

Ok. That makes things easier: objects have names, which are strings.
This will save you a lot of coding.

> there is some object that is current for the script interpreter, like
> cwd. Each class can export some
> methods to general script interface facility, exactly as you wrote -
> some hash tree that keeps the commands
> and the args. After engine starts it loads an appropriate script dll -
> in ecl case by cl_boot and
> injects few basic functions like : new , delete, sel(like cd in fs),
> psel(like pwd), exists etc.

So far fine. You just have to code a number of functions that wrap
around the  C equivalents.

> Those functions should operate with engine functions  and data at
> runtime. I thought that
> I can achieve this by def_c_function(...).


> Are those samples, mine and one you provided, equivalent from this
> sight ?

Yes, the only difference is that I coded this in a lisp file. You can
embed C code in lisp and then compile it using ECL.

> And which function from
> externals.h corresponds to "(error "Could not create object of type
> ~A" class-name))" this statement ?

Every lisp function has a C equivalent. In this case it is
cl_error(int narg, cl_object arg1, ...) but this time there is a
simpler C equivalent FEerror(char *message, int narg, ...). It would
be something like FEerror("Could not create object of type ~A", 1,

> But I really will glad to
> help to comment or to document the externals.h because I still got no
> which functions are right to call for string conversions from c to ecl
> and vice versa. I found several, but which call when ?

The reason why this is not well documented is because most people use
the Lisp foreign function interface and not direct coding of C. But
your answer is is simple
   cl_object make_simple_base_string(char *data)
     makes a Lisp string using the text you provide
   cl_object make_base_string_copy(const char *s);
     similar, but it first copies the data
   cl_object c_string_to_object(const char *s);
     this is a completely different beast: it parses a string and
reads an arbitrary lisp object.
     For instance, c_string_to_object("1.0d0") would return a lisp float

> To provide this general proxy
> I can write some general function that will receive command and args,
> but it's not too elegant solution at my
> opinion. If I can't get command and args in "unknown-function" so may
> be I can export the engine object
> into lisp in some way ?

Well right now the first option seems to be the only one. If you want
you can modify the Lisp reader to make it more attractive. You can
customize Common Lisp so that something like @(method arg1 arg2 ...)
or {method arg1 arg2 ... } is translated into (engine-call-method
method arg1 arg2 ...) where "engine-call-method" is the function that
looks up the hash.


Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28009 (Spain)

More information about the ecl-devel mailing list