This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Question regarding modules and applets in Kawa


Sorry, another module-related question, this time related to applets.

The following code works as expected when compiled as a standalone
application:

In moduletest.scm:
(begin
  
  (module-export get-x set-x!)
  (define x 6)
 (define (get-x) 

    x)
 (define (set-x! in-x)
   (set! x in-x)))

In main.scm:
(require "moduletest.scm")
(display (get-x))

When run, I get:
6

However, If I put the code from main.scm into an applet, as follows:
(require "moduletest.scm")
(define (init) <void>
  (let ((applet :: <java.applet.Applet> (this)))
    (invoke applet 'addMouseListener
            (object (<java.awt.event.MouseAdapter>)
              ((mousePressed (e :: <java.awt.event.MouseEvent>)) <void>
               ;(set-x! 8)
               (format #t "x: ~a~%~!" (get-x)))))))
(define (start) <void> (format #t "called start.~%~!"))
(define (stop) <void> (format #t "called stop.~%~!"))
(define (destroy) <void> (format #t "called destroy.~%~!"))

then when I click in the applet I get:
Exception in thread "AWT-EventQueue-1" [...]/moduletest.scm:4:5: unbound
location x
    at gnu.mapping.Location.get(Location.java:67)
    at moduletest.getX(moduletest.scm:4)
    at applettest2$0.mousePressed(applettest.scm:8)
    at java.awt.Component.processMouseEvent(Component.java:5599)
[...]

Strangely, if I uncomment the "(set-x! 8)" in the applet code, then x is
assigned the value 8, and the value is displayed. Even stranger, if I
comment out the "(define x 6)" in moduletest.scm, it still works.

So it seems that "(define x 6)" isn't being called when I require
"moduletest.scm" from an applet, but setting the variable also dynamically
creates it. 

Is there any way to get this code to work the same way for both applicants
and applets? I'd like to use the same codebase for either local or web-based
deployment, just changing the wrapper... Or should I just avoid applets?

thanks,
Alex


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]