[cffi-devel] translate-from-foreign
![](https://secure.gravatar.com/avatar/d47e218b1c744e93c6d7744bd0566975.jpg?s=120&d=mm&r=g)
I'm trying to use translate-from-foreign on an enum. The enum returns :RM-TRUE which I would like to convert to T, and :RM-FALSE and :RM-WHACKED which I would like to convert to NIL. But CFFI does not seem to support translate-from- foreign for types created with DEFCENUM. Is this observation correct? (defmethod translate-from-foreign (value (type (eql 'rm-enum))) (case value (1 t) ((-1 0) nil) (otherwise (cffi:foreign-enum-keyword 'rm-enum value)))) (cffi:defcenum #.(openrm-lispify "RMenum" 'enumname) (#.(openrm-lispify "RM_WHACKED" 'enumvalue :keyword) -1) (#.(openrm-lispify "RM_FALSE" 'enumvalue :keyword) 0) (#.(openrm-lispify "RM_TRUE" 'enumvalue :keyword) 1) (#.(openrm-lispify "RM_NATIVE_OPENGL" 'enumvalue :keyword) #x010) (#.(openrm-lispify "RM_MESA_OPENGL" 'enumvalue :keyword) #x011) (#.(openrm-lispify "RM_HARDWARE" 'enumvalue :keyword) #x020) (#.(openrm-lispify "RM_SOFTWARE" 'enumvalue :keyword) #x021) ... - Luke
![](https://secure.gravatar.com/avatar/51004fb1ed7a9faec361b6dd7787fc9f.jpg?s=120&d=mm&r=g)
On Tue, 2007-05-22 at 16:35 +0000, Luke Crook wrote:
But CFFI does not seem to support translate-from- foreign for types created with DEFCENUM. Is this observation correct?
Yes. Maybe cffi-newtypes has it differently, but I have not yet looked into that as closely as the current translation interface. -- ;;; Stephen Compall ** http://scompall.nocandysw.com/blog ** Failure to imagine vast possibilities usually stems from a lack of imagination, not a lack of possibility.
![](https://secure.gravatar.com/avatar/326b108ffcc42f27628703b0c11ed239.jpg?s=120&d=mm&r=g)
On 22/05/07, Stephen Compall <s11@member.fsf.org> wrote:
On Tue, 2007-05-22 at 16:35 +0000, Luke Crook wrote:
But CFFI does not seem to support translate-from- foreign for types created with DEFCENUM. Is this observation correct?
Yes. Maybe cffi-newtypes has it differently, but I have not yet looked into that as closely as the current translation interface.
I've added a :class option to defcstruct for similar reasons. We could add such a thing to defcenum too. -- Luís Oliveira http://student.dei.uc.pt/~lmoliv/
participants (3)
-
Luke Crook
-
Luís Oliveira
-
Stephen Compall