Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
  end

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

  http://www.ocaml-tutorial.org/introduction_to_gtk

Rich.

-- 
Richard Jones
Red Hat