Ruby Technical Overview
From Symbian Developer Community
This tutorial introduces the basics you need in order to write and run Ruby scripts on Symbian devices. This tutorial will not teach you to write Ruby or much about the Symbian platform.
Contents |
What is Ruby?
Ruby is a dynamic programming language with a complex but expressive grammar and a core class library with a rich and powerful API. Ruby draws inspiration from Lisp, Smalltalk and Perl, but uses a grammar that is easy for C and Java programmers to learn. The little code snippet below, for example, shows how easy it is to iterate objects in Ruby:
a = [3, 2, 1] # This is an array literal
a.each { |x| print x + 1 } # Prints "432"
Ruby is a pure object-oriented language, but it is also suitable for procedural and functional programming styles. It includes powerful meta-programming capabilities and can be used to create domain-specific languages or DSLs (e.g., Ruby on Rails – a very successful application of Ruby to Web domain).
The creator of Ruby, Yukihiro Matsumoto (known as Matz to the English-speaking Ruby community) summarised the guiding philosophy behind the design of Ruby in an oft-quoted remark of his: Ruby is designed to make programmers happy. [1]
What Is Symbian Ruby?
Symbian Ruby brings the Ruby programming language to the Symbian platform under the terms of the Ruby License Agreement. It is a port of the official Ruby code base and should run most of the existing Ruby scripts (the only potential problem, beside the platform-specific restrictions described below, could be that it is based on the development release 1.9, which presents some incompatibilities with the official production release 1.8). Symbian Ruby source code is hosted at the official Ruby central repository, so it is always in synch with the latest Ruby Core releases.
Owing to architectural restrictions on the Symbian platform, some core Ruby functionality related to the POSIX signals (including killing of Ruby threads) and RubyGems (language-specific packaging and deployment mechanism) are not supported at this stage.
| Note Symbian Ruby is compatible with the Symbian^1 (it runs on all S60 phones with Symbian OS version 9.1 and later). |
Besides the standard Ruby extensions, the following Symbian platform-specific functionalities are supported at time of writing:
- Camera (both still images and video recording)
- Location-based services (geo-position acquisition)
- Basic telephony functions (signal strength and battery state)
Currently, there are no GUI bindings or extensions for Symbian Ruby, so you can only create console applications with Ruby scripts. It may be possible to integrate the Ruby interpreter into the native Symbian UI application, however.
Symbian Ruby is a much younger project than PyS60, Java or Flash, and should be considered as a development release; it is not really aimed at commercial app deployment just yet. The focus for Symbian Ruby so far has revolved around porting a stable runtime with compliance with the Ruby Core specification. Further integration with the Symbian OS (including UI bindings) is something that will develop as Symbian Ruby evolves (with help from the both the Ruby and Symbian developer communities).
Installing Symbian Ruby
You can download the latest Symbian Ruby binaries from http://rubyforge.org/projects/symbian/. They are packaged as a standard Symbian installation file Ruby.sisx.
To install it on the phone, you need to install some Symbian POSIX ( P.I.P.S.) components (this even applies to S60 3rd Edition Feature Pack 2 phones, which have some core P.I.P.S. components in the ROM). The complete P.I.P.S. environment is distributed as a part of Open C/C++ Plug-ins for S60 3rd Edition. As a minimum, you must have the pips_nokia_x_x_SS.sis file installed on the phone. (Information about how to locate this file after the installation of plug-ins can be found in the README.txt file inside the downloaded archive.)
After that, you can install the Ruby.sisx file. Be aware that just after an official release of Ruby Core, installation files for Symbian Platform are likely to stay unsigned (self-signed) for some time, owing to procedural delays. In this case, you should change the Software Installation option from Signed Only to All (Phone Menu | Settings | Applications | Application manager). A warning will pop up during the installation, which you should accept with the Continue button.
After installation, you can put Ruby scripts on the phone and run them easily with the basic GUI interactive shell that is included in Symbian Ruby binaries distribution as the RubyFrontend.sisx installation file. This shell also redirects all standard I/O streams to its main window, so it is not necessary to install any additional P.I.P.S. components to support STDIO console functionality.
Standard Ruby libraries can be copied manually from any PC Ruby distribution to \Data\Ruby\Lib folder (default library search path) in the internal phone memory or on the memory card.
Advanced users could also run Ruby scripts with a command line if necessary:
ruby <script> [arg1, [arg2, […]]],
where script is a full path to Ruby script, and arg1, arg2, … are optional script arguments. In this case, if the script is calling STDIO functions, you should install one more P.I.P.S. component, stdioserver_s60_x_x_SS.SIS, from the same OpenC/C++ plug-in mentioned.
Unfortunately, the standard application manager for S60 phones cannot start the application with a command line, and a data-content recognizer for Ruby scripts is not yet available. So, to run Ruby scripts from a command line, you will need an additional application, for example, the alternative text shell eshell, which is available on some Symbian devices in ROM. (There is no standalone installation file for eshell in the public domain however.) A remote PC console (such as HyperTerminal for Windows) could also be used for this purpose with Telnet daemon for Symbian.
Where Can I Find Example Code?
You will find a number of useful code snippets tested on Symbian Ruby 1.9 here: http://symbian.rubyforge.org/svn/trunk/sample/
This one-line picture-taker demonstrates the ease with which additional libraries can be called:
# Takes a picture using phone camera and saves it to the default image location,
# C:\Data\Images\ECamExtImage<X>.jpg where X is a number.
require 'ECamera'
ECamera::snap_still_image
Building Symbian Ruby From Source Code
Currently, Ruby interpreter for Symbian Platform is implemented as a standalone open-environment (OE) console application. It has target type EXEXP (a Symbian executable with export symbol table) to provide the functionality necessary to support dynamic Ruby extensions.
To integrate Ruby interpreter into a native Symbian application there are two options:
- Ruby interpreter is started as a new process with Symbian OS native service and all interaction with it is implemented via P.I.P.S. backend using client-server communication paradigm.
- Ruby interpreter is started as a new process with P.I.P.S. popen3() function call and all communication with it is carried out via P.I.P.S. pipes.
To build Symbian Ruby from source code, you should first install the Symbian^ 1 SDK (or the S60 5th Edition, or S60 3rd Edition Feature Pack 2 SDK with OpenC/C++ plug-ins). To configure the source-code repository, you should install Ruby for Windows (version 1.8 or 1.9) and the following command line tools should be available somewhere on the executables search path:
- Sed (Stream Editor) for Windows
- Subversion (SVN) client for Windows.
You can download the latest source code for Symbian Ruby as a nightly snapshot of Ruby Subversion repository or check it out directly from the repository with SVN client:
svn co http://svn.ruby-lang.org/repos/ruby/trunk ruby
You should configure the source code for the build by running the Configure command from the Symbian folder and following the instructions from the README.SYMBIAN file.
By default, Symbian Ruby source code is configured for dynamic extensions support. In this case, all standard Ruby extensions supported on Symbian Platform are built as DLLs and linked with the Ruby Core export library. Because Ruby does not support binary compatibility between releases (the release version string is embedded in the name of the installation folders for dynamic extensions), there is no reason to put the frozen export-definition file rubyu.def under version control. It means that it requires two passes during the building of Ruby Core binaries (build-freeze-build) before the export library, (to build dynamic extensions), will be created.
Symbian Native Extensions
There are two types of native Ruby extensions:
- Standard Ruby library components that, for some reason (such as performance), are partially or completely implemented as platform-specific shared libraries
- Extensions that implement very platform-specific functions that are not available on other supported platforms.
The source code for extensions of the first type is hosted at the central Ruby repository, and the extensions are built and packaged together with Ruby Core binaries. At the time of writing, the following native extensions of this type had been ported to Symbian platform:
- Big Decimal (variable precision library)
- Digest (message digest libraries framework)
- OpenSSL
- Socket (with some restrictions due to the current P.I.P.S. version)
- String I/O
- ZLib
The source code for native extensions of the second type can be found at a separate repository, which is hosted, together with pre-built Symbian binaries, at a RubyForge project. The following extensions of this type are available at time of writing:
- ECamera (phone’s built-in camera support)
- ELocation (location-based services)
- ETelephony (basic telephony stack functions).
The process of creating new Ruby native extension library is well documented and can be found, for example, in the README.EXT file at the central Ruby repository. One part of this process, however, is not applicable to the Symbian Platform – creating the master makefile with extconf.rb Ruby script. It means that you must create the component definition file (bld.inf) and all project-definition files (.mmp) manually (you could use any existing Symbian native extension, such as ECamera, as a template).
Security
It is important to consider Symbian platform security architecture when creating Symbian native extensions.
Ruby Core and all extension libraries run in the memory space of the same process, so they must have the same platform security capabilities assigned at a build phase. At time of writing, Symbian Ruby Core has the following capabilities (although it needs none): LocalServices, NetworkServices, ReadUserData, UserEnvironment, WriteUserData, which make it possible to distribute unsigned (self-signed) packaged binaries if necessary. If the extension library does not need higher capabilities, it can be implemented as a simple DLL (ETelephony extension is an example of this use case.) If higher capabilities are needed, the extension should be implemented as an independent Symbian executable with required capabilities and a client API DLL. This will run in the memory space of the Ruby process with the standard capabilities set out above. It will communicate with the extension itself using any IPC mechanism available on the Symbian platform. (ELocation extension can be used as an example in this case.)
The packaging of the native extensions also raises security issues. Ruby Core searches for required components in the predefined public folders, while Symbian platform security architecture puts all shared binaries in the \sys\bin folder, which is not accessible without AllFiles (phone manufacturer granted) capability. To satisfy both requirements, Ruby dynamic extension binaries should be installed to both locations. (The file installed to the predefined public folder could even be a simple empty stub with the extension’s file name.)
Roadmap
What’s next from Symbian Ruby? The highest priority tasks at the moment are:
- Full functional compliance with Ruby Core specification (depends mostly on P.I.P.S. to provide missing POSIX functions)
- Provide Ruby bindings to the core Symbian OS services (including GUI) to make possible the development of native-looking Symbian applications with Ruby language.
Summary
This tutorial introduces Ruby on the Symbian platform, outlining the basics you need in order to write and run Ruby scripts on Symbian devices.
Further Information
If you want to learn more about Ruby language, there is a hands-on online tutorial at http://tryruby.hobix.com/, and some very good books are available on the subject:
[1] David Flanagan and Yukihiro Matsumoto (2008) The Ruby Programming Language
[2] Dave Thomas (with Chad Fowler and Andy Hunt) (2006) Programming Ruby: The Pragmatic Programmers’ Guide, Second Edition
[3] Hal Fulton (2006) The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition
If you want to get in touch with the wider Ruby community, please visit http://www.ruby-lang.org/en/community/.
If you have a feedback or a bug report, follow these links to the issue-tracking systems: http://redmine.ruby-lang.org/, http://rubyforge.org/projects/symbian/.
If you want to get involved in the Symbian Ruby project, we are waiting for you at http://rubyforge.org/projects/symbian/.
Sign in to comment…





