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
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.
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.