Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] native-code and byte-code compiler differences
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michel Quercia <michel.quercia@p...>
Subject: Re: [Caml-list] native-code and byte-code compiler differences
Le Fri, 29 Mar 2002 16:00:41 -0500 (EST)
Attila Kondacs <attila@zurich.ai.mit.edu> écrivit :

> the following is a code segment that opens a window and if 'q' is
> pressed  on the keyboard it closes it. It works with the byte code
> compiler fine but does not react to pressed keys when compiled with the
> native code compiler (using ocaml 3.04 for debian - from the unstable
> distribution).

>       if mouse_action != (fun () -> ())
>       then (if (try button_down()...
>       if key_pressed() ...
>     done;;

I don't know the reason for those different behaviors, but you shoudn't
wait for events this way because you actually burn CPU cycles for nothing
until something happens. The following code works the same way with ocamlc
and ocamlopt :

open Graphics;;
	
let map_keyboard = fun  ?(mouse_action = (fun () -> ())) charactionlist ->
  let st = ref true in
    while !st do
      match wait_next_event [Button_down; Key_pressed] with
	| {button     = true} -> mouse_action()
	| {keypressed = true; key=a} ->
	    (try List.assoc a charactionlist () with Not_found -> ());
	    if a = 'q' then st := false
	| _ -> ()
    done;;

open_graph "";;

map_keyboard
  [ ' ' , (fun () -> print_string "\n yes, it works!!"; flush stdout)];;

close_graph();;	

Regards,
-- 
Michel Quercia
57 rue abbé Grégoire, 38000 Grenoble
http://michel.quercia.free.fr (maths)
http://pauillac.inria.fr/~quercia (informatique)
mailto:michel.quercia@prepas.org
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners