Saturday, June 11, 2011

Tcl and Android

Tcl and the Android Scripting Environment


 Android when running on a phone does not permit general installation of binaries. The only significant writable filesystem is the sdcard but that is mounted with a non-exec flag to prevent anything running from the card. This means you need to install applications using the system installer which has permission to create files and directories on the data filesystem. The Android Scripting Environment is a project which provides a java shim to get compiled scripting languages installed onto the phone from where they can run script files from the sdcard. It comes with Python, Lua and some others.


I have created a Tcl interpreter package for ASE and it is currently hosted at http://www.patthoyts.tk/tclkit/android-arm This is a modified version of the ASE project to add Tcl support. You need to install the APK file and then copy the three zip files to the root of your sdcard and have ASE install the Tcl8.6b2 interpreter. This includes support for using the JSON interface to the Android interface so the various examples posted for other languages are readily translated into Tcl. See the scripts package but a sample is:

package require android
  set android [android new]
  $android vibrate
  $android getInput "Hello!" "Type something in..."
  $android webSearch "android scripting with tcl"


In the longer term it is probably more sensible to use something with better Java integration. Either Hecl or Jacl would seem good candidates. Hecl is not-quite-tcl and Jacl needs some updating. When I tested a threaded build and tried to create a thread in Tcl the executable aborted so I suspect we cannot make use of tclblend which says it requires threads.

Note that Hecl already has support for Android (see above).


SL4A Supports Tcl

escargo 2010-08-20 - Quoting from this link ([5]):


"Scripting Layer for Android (SL4A, formerly known as Android Scripting Environment or ASE) brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface that makes it easy to get things done. Scripts can be run interactively in a terminal, in the background, or via Locale. Python, Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported, and we're planning to add more."



Sample Programs:


package require Tcl 
package require android 
set android [android new] 
 
puts "auto_path: $auto_path" 
 
$android vibrate 
 
#$android getRingerVolume 
#$android showContacts 
#$android getInput "title string" "Enter something" 
#$android scanBarcode 
#$android pickContact 
#$android webSearch "android scripting tclsh" 
 
#set time [clock format [clock seconds] -format "%I %M %p on %A, %B %e %Y."] 
#$android speak $time 
 
$android makeToast "You are using Tcl [info patchlevel] on Android!!" 
 
set pkgs [$android getRunningPackages] 
 
 
flush stdout 
after 1000 {set ::forever 1} ; vwait ::forever 

No comments: