[Ecls-list] Accessing C variables
dean.oconnor at ite.com.au
Wed Sep 14 01:36:42 UTC 2005
Bit long in coming, but thx alot Michael for your advice. Much appreciated.
I have made a fair bit of progress with things.
Still having a few issues, but here is an example of what worked for me.
If there is a better way, hit me with it :)
In my C++ app:
char *string_ptr = "hi there";
cl_object f_obj = ecl_make_foreign_data(make_simple_string("CSTRING"),
// then load and execute below script.
In Lisp (interpreted):
;; This is how I cld see the string "hi there".
(deref-pointer test :cstring)
To be honest, this WAS working, then I did something (?:) and now it
won't work (for now).
But when it was kicking over, I could create pointers to "int" or whatever.
The thing that threw me for a bit was that for c-strings, you had to
feed cl_make_foreign_data a pointer to the char pointer.
I was still having probs when I was testing some of the our bizard
variable/symbol names we need to use.
(i know it may seem wierd needing a symbol name like this :)
I could create and print these variables from the ecl prompt, but using
the above method in C++, these symbols did not seem to be created or
reference using deref-pointer.
Hopefully I will get to the bottom of it, but if anyone has any thoughts
on the matter, any assistance would be welcome.
Goffioul Michael wrote:
Indeed, regarding my last mail, you should use def-foreign-var to access
C variables instead of ECL-specific ecl_make_foreign_data.
Goffioul Michael wrote:
You can have a look into the /contrib/win32/ directory of the ECL source
tree. Using FFI, there are LISP functions that manipulate Windows structure.
One way to pass a C object/structure to LISP is using the ecl_make_foreign_data
>>Forgive me if this has been asked before or is obvious but I
>>any clear (to me :) information on this anywhere. Any pointers in the
>>right direction would be appreciated.
>>(I've been doing a refresher in Lisp to get this working ...
>>was in Uni .... a looooong time ago)
>>We have a C++ application (for windows/linux) and we can boot ECL and
>>run scripts just fine.
>>Our plan is use interpreted (prob not pre-compiled) Lisp scripts to
>>analyse data in the C++ apps memory and return basic decisions.
>>Basically rule scripts.
>>The C++ datastructures can be quite large, so I am trying to avoid
>>having to *copy* them into Lisp space.
>>Is there a way to point/bind to the existing C++ data
>>structures in Lisp
>>interpreter real time? So the Lisp scripts can understand and
>>read the data.
>>The C++ structures could be classes, or structs, but could be
>>more basic data-types.
More information about the ecl-devel