Mittwoch, 10. Oktober 2012

Using Processing.js with Amber


"The Processing language was originally created at MIT as part of the Media lab and Aesthetics and Computation group. They needed a way to bridge the gap between software developers, artists, data visualizers, etc., and to do so in a way that allowed new programmers (or non-programmers) to do complex visual work easily. Processing was built using Java, and can be thought of as a simplified Java, with a simplified Java API for drawing and graphics." (source)

Since it is possible to write Processing code with pure JavaScript, it should be possible to use Amber with Processing.
And so it is - with some little tricks.
First, Processing should get initialized in the html page like this

A Processing instance will be created, it can get accessed via Amber in this way:

processing := <Processing.instances[0]>.

After fetching this instance, it can be used like any other Smalltalk Object:

processing background: 224.

processing line: centerX y: centerY dX: myDX dY: myDY.

I converted the clock-example to Amber, you can find it in the Example-section of my Amber Git repo. And maybe soon in the "official" Amber-Examples.

You can try it out here.

Mittwoch, 27. Juni 2012

Android-Binding for GNU Smalltalk ready!

Essentially it's no big thing - just a few lines of Smalltalk-code: i created a GNU Smalltalk star Package including the "Android" class that gives access to the full Android API via SL4A.
Usage is simple. First file in the package with:

PackageLoader fileInPackage: 'Android'.

Then you can use it like this:

| android |
android := Android new.
android makeToast: 'Hello World!'.

A more complex example, using some dialogs, is included in the smalltalk_for_android.apk (you can use the QR-Code below to install the apk - but remember that you need to install sl4a before. See my previous blog-post).
To get an idea what is possible, see the the API reference. I think it is a wonderful perspective to write full blown Android apps with Smalltalk.
Coding Smalltalk on a phone or tablet is fun - the sl4a editor is a big help because it contains an api reference. If you want to hack more complex scripts, you can remote control your phone or emulator, just follow this instructions. Only one difference: you need to set the environment-variable AP_HANDSHAKE to some arbitrary value.
With this setup you can execute your script with "gst myscript.st" or just call the api via the gst console.
Sourcecode etc. is available on github.


Mittwoch, 13. Juni 2012

GNU Smalltalk on Android

I crosscompiled GNU Smalltalk 3.2.4 with the Android NDK (r8).
Because interaction with GST on Android was complicated (couldn't read stdout/ stderr reliable), i decided to use the Android Scripting Framework.
So if you want to try it, first you need to install SL4A. You should install the sl4a_r5.apk (not r4!)
After installing SL4A, you can download and install smalltall_for_android.apk. Remember to allow installation from untrusted sources.
I tested "smalltalk for android" with an android virtual device running Android 2.3.3. The Screenshot was made on my Samsung Galaxy S3.
Currently there is no binding for the SL4A API - you can execute Smalltalk code, but there is no interaction with the Android API.
So, if anyone would like to help implementing the JSON-RPC bridge to SL4A - that would be really great.
The Source is on github.

Samstag, 21. Januar 2012

Domain-Verification mit Schlund Technologies für Google Apps

Ich habe ein Google Apps Konto für eine Non-Profit Organisation eingerichtet. Die Domain, die ich mit dem Konto nutzen möchte habe ich bei Schlund Technologies gekauft.
Um nun die Domain mit dem Google Apps Konto nutzen zu können, muss diese verifiziert werden - das war aber in meinem Fall eine echte Herausforderung. Dieser Spezialfall scheint auch nicht dokumentiert zu sein.
Es gibt verschiedene Möglichkeiten der Verifikation, so kann man z.B. auf der Homepage der Domäne spezielle HTML-Tags einfügen oder auf dem Server eine präparierte Datei ablegen. Das Vorhandensein dieser Informationen impliziert, dass man Eigentümer der Domäne ist.
Das funktioniert nur leider nicht, wenn man nur die Domain hat und keinen zugehörigen Webspace (den will man ja gerade mit Google Apps verwalten).
Die andere Variante ist, bei der Domänenkonfiguration einen TXT-Record mit einem speziellen Wert anzulegen. Google fragt den TXT-Record beim Nameserver ab und kann so das Eigentum an der Domäne verifzieren. Die Konfiguration des speziellen TXT-Records ist bei Google Apps für einige Domain-Provider beschrieben - leider nicht für Schlund.
Nach mehrstündigem rumprobieren und diversen Forensuchen konnte ich das Problem lösen: Bei Schlundtech kann für den neuen TXT-Record ein Name angegeben werden. Hier muss "@" eingetragen werden.
Interessanterweise konnte ich den TXT-Record speichern und die Google-Verifikation erfolgreich zum Abschluß führen. Beim nächsten Aufruf der Domain-Konfigurationsmaske bei Schlund war das @-Zeichen wieder verschwunden.

Donnerstag, 5. Januar 2012

Ambrhino

Today i'd like to announce my newest Project "Ambrhino". Ambrhino integrates Amber Smalltalk with the Java Virtual Machine.
Ambrhino can act as a Server to serve Amber and persist changes to the filesystem (you could use it instead of node.js).
It can also act as a runtime to execute Amber-Programs.
Ambrhino is written in Java and uses JSR223 to execute Javascript with the Mozilla Rhino Engine
An interesting feature is, that you can directly call Java classes from a compiled Amber Smalltalk, e.g.:


buttonPrintit := .
buttonPanel add: buttonPrintit.


A really cool feature is that it seems to be possible to add Smalltalk BlockClosures as ActionListeners to (Swing-) Buttons like this:



buttonDoit addActionListener: [ 
self eval: (textArea javaObject getSelectedText).
].

The main goal of this project is not to use Amber to write Swing-Applications - it feels somehow weird to use a Webbased-IDE to create a native Swing Application ...
Someday i want to use it to create Android-Applications with Amber - i could start an Ambrhino-Server on the Android-Emulator to create/ compile/ package programs. The Android-API will be called with the Android Scripting Framework (ASF)
But to get familiar with the (sometimes strange looking) Smalltalk-Java-Javascript-Mixture, i made a little Swing-Application - a simple Workspace to execute Smalltalk-Code.

To try it out you may fork the project on Github or just download the ambrhino.zip unpack it and start the workspace.bat file.

Like in other Smalltalk-Workspaces you can select text and execute it by pressing  "do it" or "print it".

To get an idea of what is possible you can copy this gist to the workspace and execute it. It fetches via HTTP-GET content from a Webserver and displays it on a JTextPane. Not really useful - but somehow cool.

Ideas, Hints, Help and rants are very welcome!