guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OOP in Guile<->C Interfaces?


From: Robert A. Uhl
Subject: OOP in Guile<->C Interfaces?
Date: Fri, 19 Oct 2001 19:14:45 -0600
User-agent: Mutt/1.2.5i

Is there any plan to object-orient the smob functions?  I'll describe
my problem, and describe why I think OO smobs would be useful.

I am writing a programme using gtk+ and its class structure.  I've a
hierarchy which (partially) works like this:

TravMapobject:
  TravGalaxy
  TravSector
  TravPlanetaryObject
    TravBelt
    TravPlanet

You get the idea.  Ideally, I'd like to be able to have guile (not
travlib) flag as many errors as possible, e.g. calling
(trav-mapobject-get-name 4.7).  Unfortunately, smob registering only
allows for registering a basic type; there's no way to let the guile
runtime know that a TravGalaxy is also a TravMapobject.

There are three solutions which I can see.  The first would be some
form of unholy goops/C/what-have-you mixture.  The second is to create
only a single smob, scm_mapobject_type, and use it for everything,
using the appropriate TRAV_IS_GALAXY(), TRAV_IS_PLANET() functions in
the guile wrapper code.  This is what I am going to do.  It's not that
ugly, and the overhead is fairly slight.  But it does mean writing
More Lines of Code(tm), which ideally a library should help guard
against.

The third would be some way for guile to understand a hierarchy of
smobs.  I believe that a) this would enhance writing OO interfaces to
guile and b) this might possibly enhance guile itself.  If the
mechanism were extended to all types, it might thus be made easier to
understand the different numeric types without nasty hairy evil code.

There is a fourth way, but it is ugly.  The superclasses would need to
know about their subclasses, and explicitly check for them.  This is
atrocious because it break extensability.

Ideas?  Am I spouting nonsense?

-- 
Robert Uhl <address@hidden>

Every man, woman, and responsible child has a natural, fundamental,
and inalienable human, individual, civil, and Constitutional right
(within the limits of the Non-Aggression Principle) to obtain, own,
and carry, openly or concealed, any weapon--handgun, shotgun, rifle,
machinegun, anything--any time, anywhere, without asking anyone's
permission.                                       --L. Neil Smith




reply via email to

[Prev in Thread] Current Thread [Next in Thread]