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]

Running a background thread REPL on Android


Hi all,

I tried modifying Helmut Eller's eval() on Android so that it runs on a
background thread. However, the View is no longer showing up on the main
page. Are there any known restrictions on threading running Kawa on Android?


(require 'android-defs)

(define (msg (fstring string) #!rest args)
  (android.util.Log:v "kawa-hello" (apply format fstring args)))

(define (start-repl port uiContext)
  (begin
    ; required! otherwise the getLanguage() call will fail
    (kawa.standard.Scheme:registerEnvironment)
    ; required! as Android cannot compile to java
    (set! gnu.expr.ModuleExp:alwaysCompile #f)
    ; sets the ui variable to the uiContext)
    ((interaction-environment):put "ui" uiContext)
    (let* ((server (java.net.ServerSocket port)))
      (msg "listing on ~a (~a)" port server)
      (let ((socket (server:accept)))
        (msg "connected ~a " socket)
        (let ((in (gnu.mapping.InPort (socket:getInputStream)))
              (out (gnu.mapping.OutPort (socket:getOutputStream))))
          (parameterize ((current-input-port in)
                         (current-output-port out))
            (do () (#f)
              (try-catch 
               (begin
                 (format #t "\n> " )
                 (force-output)
                 (let ((form (read)))
                   (format #t "form: ~s\n" form)
                   (format #t "~s" (eval form (interaction-environment)))))
               (e java.lang.Exception
                  (e:printStackTrace out))))))))))

(activity hello
  (on-create-view
    (begin
      ((java.lang.Thread (runnable (start-repl 4444 (this)))):run)
      (android.widget.LinearLayout (this)
        orientation: android.widget.LinearLayout:VERTICAL
        view:
          (android.widget.TextView (this)
             text: "Hello, Android REPL from Kawa Scheme!")
        view:
          (android.widget.Button (this)
             text: "Click Me!"
             on-click-listener:
                (lambda  (v)
                  ((android.widget.Toast:makeText (this)
                    "Beep Bop! You clicked me!"
android.widget.Toast:LENGTH_LONG):show))
          ))
      )))

-- 
View this message in context: http://old.nabble.com/Running-a-background-thread-REPL-on-Android-tp33193100p33193100.html
Sent from the Sourceware - kawa list mailing list archive at Nabble.com.


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