enum constants vs. functions returning an enum value

Chris Shoemaker c.shoemaker at cox.net
Sun Aug 13 16:06:57 EDT 2006

[cc'ing gnucash-devel for reference]

Hi SWIG-List,

  I'm wrapping for guile:

typedef enum { 
} GncOwnerType;

GncOwnerType gncOwnerGetType (const GncOwner *owner);

Both the enum constants and the function are correctly wrapped, but in
a way that seems inconsistent.  The enum constants are mapped to
zero-arg functions that return the enum value (called "thunks" in
guile).  E.g.  "GNC-OWNER-EMPLOYEE" evaluates to #<primitive-procedure

However, the wrapper for gncOwnerGetType() returns the enum value
immediately, not a thunk.  E.g. "(gncOwnerGetType employee)" evaluates
to 1.

This means that the return value of the wrapper for the function that
returns an enum value is not comparable to the enum values.  Is there
some good reason for this?  It would seem more convenient if either A)
the enum constants were mapped to symbols bound to the enum
values (Is this technically difficult?) or B) the wrapped function
returned a thunk equal to the thunk for the enum constant.

If I can't change this behavior I guess my options are A) write a
typemap(out) for the enum type that returns thunks, just like the enum
constants, or B) replace all occurances of the constant with the
evaluation of the constant function in my guile code.

Any comments?  BTW, the SWIG documentation is surprisingly good!  :)


More information about the gnucash-devel mailing list