Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Objects, dynamic cast, Obj.magic abuse and dragons
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-02-26 (12:14)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Objects, dynamic cast, Obj.magic abuse and dragons
On Tue, Feb 26, 2008 at 12:35:10PM +0100, Berke Durak wrote:
> The problem is that the main game loop gets the current location by taking 
> the container of the hero... which is a physical.  However, it needs to 
> call the place-specific method "go".

I only briefly read over this, but maybe the thing you want is an
object memo.  There's a specialized one in lablgtk called GUtil.memo,
but the basic source for it could be adapted:

  class ['a] memo () = object
    constraint 'a = #widget
    val tbl = Hashtbl.create 7
    method add (obj : 'a) =
      Hashtbl.add tbl obj#get_id obj
    method find (obj : widget) = Hashtbl.find tbl obj#get_id
    method remove (obj : widget) = Hashtbl.remove tbl obj#get_id

There's an example of using this if you search down for 'memo' on this


Richard Jones
Red Hat