freenode/#ecl - IRC Chatlog
Search
5:02:31
loke`
I have some C code that I want to embed using C-PROGN or C-INLINE. This code will return a string.
5:03:20
loke`
How do I do that? I tried creating an array and declaring that as :C-STRING and passing it as an argument to C-PROGN, but that didn't work at all.
7:31:08
loke`
jackdaniel: I solved the problem in a way that didn't need transferring a string. But I'm still curious as to how it can be done. It's not clear from the manual.
7:39:03
loke`
jackdaniel: It's a small function that constructs a string based on some input parameters (numbers)
7:39:23
loke`
So I can either pass in a buffer and let the functiopn constrcut it, or I can allocate memory in the function itself.
7:39:57
loke`
All I need is a way to communicate the string to the caller (in this particular case, the string is constant-size)
7:40:46
jackdaniel
i.e this should work just fine: (defun foobar (xxx) (let ((str (ffi:c-inline (xxx) (:string) :string "funname(#0)" :one-liner t))) (format t "look! a string: ~a" str))
7:41:06
jackdaniel
(keep in mind, that if you type it in the repl you need to compile foobar with #'compile)
7:42:02
loke`
jackdaniel: OK, so if the string is a static buffer, that would work. But what if I need to dyamically allocate the string?
7:51:38
jackdaniel
see https://github.com/ivmai/bdwgc ("Dynamic libraries are completely supported only under…")