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]

Macros for Android


Hello fellow Schemers!

I've tried to write a macro that deals with the boilerplate around
Android's AsyncTask, but failed. Thus I'd like to ask for advice
here.
As a quick description, an AsyncTask is used by sub-classing and
implementing two methods, doInBackground and onProgressUpdate.
I'd very much like to have a macro that does roughly the following:

(do-in-background
        ((here are forms)
         (that are inserted into the doInBackground method))
        ((these forms are)
         (inserted into onProgressUpdate)))

i.e. a macro that takes two parameters that are then inserted directly
into skeleton code. As the two methods doInBackground and
onProgressUpdate take one parameter each, I want to capture these, so I
need to provide two more parameters, one for each name. Also, the
AsyncTask takes parameters when starting, which I want to provide as
well.

I came up with the following (unhygienic) macro:

(defmacro do-in-background (dib-param dib opu-param opu params)
  `(let* ((async-task :: <android.os.AsyncTask> 
 		      (object (<android.os.AsyncTask>)
 			      ((doInBackground ,dib-param :: <java.lang.Object[]>) :: <java.lang.Object>
 			       ,@dib)
 			      ((onProgressUpdate ,opu-param :: <java.lang.Object[]>)
 			       ,@opu))))
     (<android.os.AsyncTask>:execute async-task (<java.lang.Object[]> ,@params))))

I've tried to test it with (require 'syntax-utils) (expand ...), but it
seems EXPAND doesn't like OBJECT very much, I keep seeing #!null instead
of the object.

Test code:

(do-in-background
        param
        ((publishProgress (java.lang.Object[] "test")))
        param
        ((<android.util.Log>:d "Test" (param 0)))
        '())

should expand to code that simply prints "test" to the android log.

Compiling produces the following errors:

test.scm:227:9: no declaration seen for <android.util.Log>:d
test.scm:223:7: no declaration seen for <android.os.AsyncTask>:execute

which is weird, as both of these work very well when used outside the
macro.

I'd be glad about any help.

Peter


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