[Swig-user] enum constants vs. functions returning an enum value

Chris Shoemaker c.shoemaker at cox.net
Wed Aug 16 23:46:37 EDT 2006

On Wed, Aug 16, 2006 at 10:08:44PM -0500, John Lenz wrote:
> On 08/16/06 20:19, Chris Shoemaker wrote:
> > Assuming this behavior makes as much sense to other people as it does
> > to me, I think the idea of using a static variable and a
> > scm_c_define() is a good change.  And we can wait for a formal release
> > by using the short-term solution above.  The only thing I wonder about
> > is... wouldn't that be a not-backward-compatible change to swig?
> > 
> I mentioned I would enable this by a feature (read about features
> http://www.swig.org/Doc1.3/Customization.html#features the section about
> Feature Flags).  By default, the feature would be off (the old
> behavior), but you could either globally turn on the feature for every
> enum, or mark individual enums in the .i file you wanted to use the new
> behavior.

Ah, I see.

> So if no scmstub is given, I will have it export
> scm_c_eval_string("(set! %s (%s))");
> into the init section (from code).  Thus, we use (set!) either in the
> scmstub or in the init.
> I do it this way so the old behavior of exporting it as a function stays
> the default, and so I don't need to change any of the wrapping... just
> some extra output if the flag is defined.
> so the slightly modified code would look like (notice the test for the
> feature on this node (the n variable).
> if (Getflag(n, "feature:enumasvar") {
>   if (scmstub) {
>    Printf(scmtext, "(set! %s (%s))\n", name, name);
>   } else {
>    Printf(f_init, "scm_c_eval_string(\"(set! %s (%s))\");\n", name, name);
>   }
> }

Wow, it seems so simple.  Yeah, I think this is a good feature.  BTW,
do you have a feel for how many projects use SWIG for the guile


More information about the gnucash-devel mailing list