[Swig-user] enum constants vs. functions returning an enum value
Chris Shoemaker
c.shoemaker at cox.net
Wed Aug 16 00:14:40 EDT 2006
On Mon, Aug 14, 2006 at 12:01:53PM -0400, Chris Shoemaker wrote:
> On Mon, Aug 14, 2006 at 08:51:35AM -0400, Reed Hedges wrote:
> > Chris Shoemaker wrote:
> > > 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.
> >
> > Doesn't this work? --
> >
> > (= (GNC-OWNER-EMPLOYEE) (gncOwnerGetType employee))
> >
>
> Yes, it does. I just didn't expect to have to treat enum constants as
> functions, but maybe that's the easiest way to implement the wrapper.
> I'm used to treating constants as immediate scheme objects. However,
> I wouldn't be surprised if libguile didn't provide a mechanism for
> binding symbols to immediate scheme objects.
Turns out it does: scm_c_define()
> G-wrap wraps constants
> as immediates, but it generates helper scheme code to do it.
And I was wrong about that last part. G-wrap does it right from C.
So, SWIG uses scm_c_define_gsubr() to convert the enum value to a
_function_ returning the enum value.
Is there some reason why it doesn't include:
scm_c_define("GNC-OWNER-EMPLOYEE",
scm_long2_num(gswig_const_GNC_OWNER_EMPLOYEE));
inside the scm_init_FOO_module() function? That treatment of enum
values would allow: (eq? GNC-OWNER-EMPLOYEE (gncOwnerGetType employee))
which seems more natural to me.
I've looked at the "enum SWIGTYPE" typemaps for guile, but I didn't
see any mechanism for generating code into the scm_init_FOO_module()
function. Is that even possible? Thanks.
-chris
More information about the gnucash-devel
mailing list