endOf* now consumes string and displays in separate message box
svn: r3897
This commit is contained in:
parent
ac9b34f3b2
commit
380d1cc92a
|
@ -2,7 +2,7 @@
|
||||||
(module World-native-methods mzscheme
|
(module World-native-methods mzscheme
|
||||||
(require (lib "support.scm" "htdch" "draw") (lib "unitsig.ss"))
|
(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 void-or-true #t)
|
||||||
(define (imperative world@t+1 world@t) world@t+1)
|
(define (imperative world@t+1 world@t) world@t+1)
|
||||||
|
|
|
@ -25,8 +25,8 @@ public abstract class World {
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
||||||
public native boolean endOfTime();
|
public native boolean endOfTime(String s);
|
||||||
public native World endOfWorld();
|
public native World endOfWorld(String s);
|
||||||
public abstract World onTick();
|
public abstract World onTick();
|
||||||
public abstract World onKeyEvent(String ke);
|
public abstract World onKeyEvent(String ke);
|
||||||
public abstract boolean draw();
|
public abstract boolean draw();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
(require (lib "draw.ss" "htdp")
|
(require (lib "draw.ss" "htdp")
|
||||||
(lib "posn.ss" "lang")
|
(lib "posn.ss" "lang")
|
||||||
(lib "class.ss")
|
(lib "class.ss")
|
||||||
|
(lib "mred.ss" "mred")
|
||||||
(lib "unit.ss") (lib "unitsig.ss")
|
(lib "unit.ss") (lib "unitsig.ss")
|
||||||
(lib "String.ss" "profj" "libs" "java" "lang")
|
(lib "String.ss" "profj" "libs" "java" "lang")
|
||||||
(lib "Throwable.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^)
|
(provide world-native@ world-native^ canvas-native@ canvas-native^ support^)
|
||||||
|
|
||||||
(define-signature world-native^
|
(define-signature world-native^
|
||||||
(endOfTime-native
|
(endOfTime-java.lang.String-native
|
||||||
endOfWorld-native
|
endOfWorld-java.lang.String-native
|
||||||
bigBangO-double-native))
|
bigBangO-double-native))
|
||||||
|
|
||||||
(define-signature canvas-native^
|
(define-signature canvas-native^
|
||||||
|
@ -32,9 +33,12 @@
|
||||||
|
|
||||||
(define-signature support^ (void-or-true imperative))
|
(define-signature support^ (void-or-true imperative))
|
||||||
|
|
||||||
(define canvas-native@
|
;Raises an error if string is null
|
||||||
(unit/sig canvas-native^
|
;check-string: string string string -> boolean
|
||||||
(import support^)
|
(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
|
;raises a Java exception with the specified error message
|
||||||
;raise-error: String -> void
|
;raise-error: String -> void
|
||||||
|
@ -45,6 +49,10 @@
|
||||||
(send exn RuntimeException-constructor-java.lang.String str))
|
(send exn RuntimeException-constructor-java.lang.String str))
|
||||||
(current-continuation-marks))))
|
(current-continuation-marks))))
|
||||||
|
|
||||||
|
(define canvas-native@
|
||||||
|
(unit/sig canvas-native^
|
||||||
|
(import support^)
|
||||||
|
|
||||||
(define-syntax (wrap-start-check stx)
|
(define-syntax (wrap-start-check stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ body ...)
|
[(_ body ...)
|
||||||
|
@ -72,13 +80,6 @@
|
||||||
(raise-error
|
(raise-error
|
||||||
(format "Method ~a expects an int >= 0 for ~a argument, given ~a" method argument value))))
|
(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)
|
(define (to-lower-case s)
|
||||||
(letrec ((lower
|
(letrec ((lower
|
||||||
(lambda (s)
|
(lambda (s)
|
||||||
|
@ -198,13 +199,17 @@
|
||||||
(on-event world (lambda () (send world onKeyEvent-java.lang.String ke*)))))
|
(on-event world (lambda () (send world onKeyEvent-java.lang.String ke*)))))
|
||||||
void-or-true)
|
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 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)
|
(send theCanvas stop)
|
||||||
#t)
|
#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 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)
|
(send theCanvas stop)
|
||||||
this)))
|
this)))
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
(module World-native-methods mzscheme
|
(module World-native-methods mzscheme
|
||||||
(require (lib "support.scm" "htdch" "draw") (lib "unitsig.ss"))
|
(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 void-or-true void)
|
||||||
(define (imperative world@t+1 world@t) world@t)
|
(define (imperative world@t+1 world@t) world@t)
|
||||||
|
|
|
@ -26,8 +26,8 @@ public abstract class World {
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
||||||
public native boolean endOfTime();
|
public native boolean endOfTime(String s);
|
||||||
public native World endOfWorld();
|
public native World endOfWorld(String s);
|
||||||
public abstract void onTick();
|
public abstract void onTick();
|
||||||
public abstract void onKeyEvent(String ke);
|
public abstract void onKeyEvent(String ke);
|
||||||
public abstract void draw();
|
public abstract void draw();
|
||||||
|
|
|
@ -14,8 +14,8 @@ import geometry.*;
|
||||||
| Canvas theCanvas |------>| Canvas |
|
| Canvas theCanvas |------>| Canvas |
|
||||||
+-----------------------------------+ +---------------------------------------+
|
+-----------------------------------+ +---------------------------------------+
|
||||||
| boolean bigBang(int,int,double) | +---------------------------------------+
|
| boolean bigBang(int,int,double) | +---------------------------------------+
|
||||||
| boolean endOfTime() | | boolean show() |
|
| boolean endOfTime(String) | | boolean show() |
|
||||||
| World endOfWorld() | | boolean close() |
|
| World endOfWorld(String) | | boolean close() |
|
||||||
| | | boolean drawCircle(Posn,int,Color) |
|
| | | boolean drawCircle(Posn,int,Color) |
|
||||||
| | | boolean drawDisk(Posn,int,Color) |
|
| | | boolean drawDisk(Posn,int,Color) |
|
||||||
| abstract World onTick() | | boolean drawRect(Posn,int,int,Color) |
|
| abstract World onTick() | | boolean drawRect(Posn,int,int,Color) |
|
||||||
|
@ -51,13 +51,13 @@ produces <code>true</code>.
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</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
|
<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
|
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
|
||||||
remains visible.
|
remains visible.
|
||||||
</li>
|
</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
|
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
|
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
|
||||||
remains visible.
|
remains visible.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user