From paultarvydas at gmail.com Fri Dec 7 14:05:12 2018 From: paultarvydas at gmail.com (paul tarvydas) Date: Fri, 7 Dec 2018 09:05:12 -0500 Subject: Question re. Call-by-value for foreign structs Message-ID: <9CFB4BC1-108E-4545-ACEB-54279615B534@gmail.com> Using CFFI, do I need to specify translation methods when performing call-by-value to C? I am assuming (possibly incorrectly?) that cffi:defcstruct will create the translations for a C struct for me, then pass that struct by value to a Go foreign routine. Specifically, I am trying to call routines in Go from Lisp using a Lisp string. A Go string is a C struct { pointer-to-string , integer-length-of-string } Simple test code is in https://github.com/guitarvydas/lisp-go/blob/master/string-example/lisp-client.lisp. (see function "my-log", run "make" which should build and run the example, causing a NO-APPLICABLE-METHOD-ERROR). thanks pt From luismbo at gmail.com Fri Dec 7 17:11:10 2018 From: luismbo at gmail.com (=?UTF-8?Q?Lu=C3=ADs_Oliveira?=) Date: Fri, 7 Dec 2018 17:11:10 +0000 Subject: Question re. Call-by-value for foreign structs In-Reply-To: <9CFB4BC1-108E-4545-ACEB-54279615B534@gmail.com> References: <9CFB4BC1-108E-4545-ACEB-54279615B534@gmail.com> Message-ID: Have a look at https://common-lisp.net/project/cffi/manual/html_node/Foreign-Structure-Types.html, in particular: "By default, convert-from-foreign (and also mem-ref ) will make a plist with slot names as keys, and convert-to-foreign will translate such a plist to a foreign structure." By default, you'd invoke my-log like this: (my-log (list :str "Foo" :count 4)). That section should give you pointers on how to do something both more convenient and efficient, in case it matters. HTH, Luís On Fri, Dec 7, 2018 at 2:12 PM paul tarvydas wrote: > Using CFFI, do I need to specify translation methods when performing > call-by-value to C? > > I am assuming (possibly incorrectly?) that cffi:defcstruct will create the > translations for a C struct for me, then pass that struct by value to a Go > foreign routine. > > Specifically, I am trying to call routines in Go from Lisp using a Lisp > string. > > A Go string is a C struct { pointer-to-string , integer-length-of-string } > > Simple test code is in > https://github.com/guitarvydas/lisp-go/blob/master/string-example/lisp-client.lisp > . > > (see function "my-log", run "make" which should build and run the example, > causing a NO-APPLICABLE-METHOD-ERROR). > > thanks > pt > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: