[cffi-devel] Help needed: Tcl/Tk via CFFI (OSX 10.4.6 Intel, AllegroCL)

Frank Goenninger fgoenninger at prion.de
Wed Apr 26 11:43:47 UTC 2006


Am 26.04.2006 um 09:35 schrieb James Bielman:

>
> You seem to be going to a fair bit of trouble here to reproduce what
> the CFFI :STRING type does automatically... why not something like:
>
> (defcfun ("Tcl_EvalFile" tcl-eval-file) :int
>   (interp :pointer)
>   (filename :string))
>
> (defcfun ("Tcl_Eval" tcl-eval) :int
>   (interp :pointer)
>   (script :string))
>
> instead of mucking about with low-level stuff like null terminators.
> There is also WITH-FOREIGN-STRING that encapsulates this pattern in a
> macro when you don't want to use the :STRING type.

Thx for pointing out. I took my approach straight from the example cl- 
opengl as done by - Luis, I think... ;-)

>
> Also, one technique I've found very handy when writing bindings for
> APIs that are consistent about returning error codes is to define a
> special result type and hang a translator on it, to get automatic
> error checking (untested, caveat executor):
>
> ;; Now TCL-EVAL-FILE and TCL-EVAL can return a TCL-ERROR instead of
> ;; :INT and the translator will get called on the return value.
> (defctype tcl-error :int)
>
> (defmethod translate-from-foreign (value (type (eql 'tcl-error)))
>   (unless (zerop value) ;; or whatever
>     (error "got some tcl error ~D..." value))
>   value)

Superb. Works like a charm. Thanks!

>
> Apart from any other TCL-specific issues like Yaroslav mentioned,
> perhaps the TCL output stream is buffered and needs to be flushed
> somehow?

Actually I had a typo in the source (missing paranthesis) that  
prevented the call of the Tcl function al all - so I was seeing the  
foreign ptr addresses as results ... That's why I was a bit surprised.

Now I can call Tcl_Eval and do get the message as defined via the  
puts command on the standard output stream.

>
> James
>

Thanks again!

Frank




More information about the cffi-devel mailing list