endOf* now consumes string and displays in separate message box

svn: r3897
This commit is contained in:
Matthias Felleisen 2006-07-31 02:52:25 +00:00
parent ac9b34f3b2
commit 380d1cc92a
6 changed files with 96 additions and 91 deletions

View File

@ -2,7 +2,7 @@
(module World-native-methods mzscheme
(require (lib "support.scm" "htdch" "draw") (lib "unitsig.ss"))
(provide endOfTime-native endOfWorld-native bigBangO-double-native)
(provide endOfTime-java.lang.String-native endOfWorld-java.lang.String-native bigBangO-double-native)
(define void-or-true #t)
(define (imperative world@t+1 world@t) world@t+1)

View File

@ -25,8 +25,8 @@ public abstract class World {
// --------------------------------------------------------
public native boolean endOfTime();
public native World endOfWorld();
public native boolean endOfTime(String s);
public native World endOfWorld(String s);
public abstract World onTick();
public abstract World onKeyEvent(String ke);
public abstract boolean draw();

View File

@ -3,6 +3,7 @@
(require (lib "draw.ss" "htdp")
(lib "posn.ss" "lang")
(lib "class.ss")
(lib "mred.ss" "mred")
(lib "unit.ss") (lib "unitsig.ss")
(lib "String.ss" "profj" "libs" "java" "lang")
(lib "Throwable.ss" "profj" "libs""java""lang")
@ -11,8 +12,8 @@
(provide world-native@ world-native^ canvas-native@ canvas-native^ support^)
(define-signature world-native^
(endOfTime-native
endOfWorld-native
(endOfTime-java.lang.String-native
endOfWorld-java.lang.String-native
bigBangO-double-native))
(define-signature canvas-native^
@ -32,9 +33,12 @@
(define-signature support^ (void-or-true imperative))
(define canvas-native@
(unit/sig canvas-native^
(import support^)
;Raises an error if string is null
;check-string: string string string -> boolean
(define (check-string value method argument)
(when (null? value)
(raise-error (format "Method ~a expects a non-null String for ~a argument, given null" method argument)))
#t)
;raises a Java exception with the specified error message
;raise-error: String -> void
@ -45,6 +49,10 @@
(send exn RuntimeException-constructor-java.lang.String str))
(current-continuation-marks))))
(define canvas-native@
(unit/sig canvas-native^
(import support^)
(define-syntax (wrap-start-check stx)
(syntax-case stx ()
[(_ body ...)
@ -72,13 +80,6 @@
(raise-error
(format "Method ~a expects an int >= 0 for ~a argument, given ~a" method argument value))))
;Raises an error if string is null
;check-string: string string string -> boolean
(define (check-string value method argument)
(when (null? value)
(raise-error (format "Method ~a expects a non-null String for ~a argument, given null" method argument)))
#t)
(define (to-lower-case s)
(letrec ((lower
(lambda (s)
@ -198,13 +199,17 @@
(on-event world (lambda () (send world onKeyEvent-java.lang.String ke*)))))
void-or-true)
(define (endOfTime-native this accs gets privates)
(define (endOfTime-java.lang.String-native this accs gets privates s)
(define theCanvas ((hash-table-get accs 'theCanvas) this))
(define _ (check-string s "endOfTime(String)" "first"))
(message-box "end of time" (send s get-mzscheme-string))
(send theCanvas stop)
#t)
(define (endOfWorld-native this accs gets privates)
(define (endOfWorld-java.lang.String-native this accs gets privates s)
(define theCanvas ((hash-table-get accs 'theCanvas) this))
(define _ (check-string s "endOfWorld(String)" "first"))
(message-box "end of world" (send s get-mzscheme-string))
(send theCanvas stop)
this)))
)

View File

@ -2,7 +2,7 @@
(module World-native-methods mzscheme
(require (lib "support.scm" "htdch" "draw") (lib "unitsig.ss"))
(provide endOfTime-native endOfWorld-native bigBangO-double-native)
(provide endOfTime-java.lang.String-native endOfWorld-java.lang.String-native bigBangO-double-native)
(define void-or-true void)
(define (imperative world@t+1 world@t) world@t)

View File

@ -26,8 +26,8 @@ public abstract class World {
// --------------------------------------------------------
public native boolean endOfTime();
public native World endOfWorld();
public native boolean endOfTime(String s);
public native World endOfWorld(String s);
public abstract void onTick();
public abstract void onKeyEvent(String ke);
public abstract void draw();

View File

@ -14,8 +14,8 @@ import geometry.*;
| Canvas theCanvas |------>| Canvas |
+-----------------------------------+ +---------------------------------------+
| boolean bigBang(int,int,double) | +---------------------------------------+
| boolean endOfTime() | | boolean show() |
| World endOfWorld() | | boolean close() |
| boolean endOfTime(String) | | boolean show() |
| World endOfWorld(String) | | boolean close() |
| | | boolean drawCircle(Posn,int,Color) |
| | | boolean drawDisk(Posn,int,Color) |
| abstract World onTick() | | boolean drawRect(Posn,int,int,Color) |
@ -51,13 +51,13 @@ produces <code>true</code>.
</p>
</li>
<li><code>endOfTime</code>, stops the clock and, if it succeeds, produces
<li><code>endOfTime</code>, displays the given message, stops the clock and, if it succeeds, produces
<code>true</code>. After the end of time, events no longer trigger calls
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
remains visible.
</li>
<li><code>endOfWorld</code>, stops the clock and, if it succeeds, produces the
<li><code>endOfWorld</code>, displays the given message, stops the clock and, if it succeeds, produces the
last <code>World</code>. After the end of the world, events no longer trigger calls
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
remains visible.