[Ecls-list] embedding ecl into a game engine
Juan Jose Garcia-Ripoll
juanjose.garciaripoll at googlemail.com
Fri May 8 17:21:05 UTC 2009
On Tue, May 5, 2009 at 2:50 PM, Ilya Kliot <plushe at gmail.com> wrote:
> Here is an example that supposed to be near to final result:
Let me briefly comment your code. But before that I would give you
this general advice: do not intend to just embed ECL without learning
a bit of Common Lisp. If you do not grasp how errors are handled, how
objects are created and destroyed, etc, then your efforts will be
probably fruitless, since the library will not be very usable.
First of all you must realize what def_c_function(...) does: it
creates a new function that is available for Common Lisp. Now you
* What should the function return
* What should the function do when it finds an error
In this particular case you want a function that allocates a certain
type of object.
* Do you want the function to signal an error when it fails?
* Or do you want it to return NIL or some other value?
This is not a decision imposed by ECL, but rather a decision taken by you.
In the first case your function should signal an error. However you
might want that error object to have a type
and you might want to define a condition object and then create it
with a call to the function ERROR.
In the second case you might just want to return Cnil, which is a
rather general object, equivalent to "false" and that can be checked
You will find it much easier to build wrappers using Lisp than using
C++. Why? Because that way you will be forced to write Common Lisp and
understand what you are doing and how people might use your code.
For instance, the previous example might just be
(defun new-object (class-name name)
(let* ((s1 (symbol-name class-name))
(s2 (symbol-name name))
(o (c-inline (s1 s2) (:c-string :c-string)
nRoot* o = nEclServer::kernelServer->NewNoFail(ecl_base_string_pointer_safe(class_name),
@(return) = o? make_simple_base_string(o->GetFullName().c_str()) : Cnil;
(error "Could not create object of type ~A" class-name))
This code can be stored in a lisp file and compiled using ECL.
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28009 (Spain)
More information about the ecl-devel