×
Namespaces

Variants
Actions

Ruby Technical Overview

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: hamishwillee (10 May 2011)
Last edited: hamishwillee (21 Oct 2011)
Trails.png About Ruby on Symbian
 > Ruby in a Nutshell > Ruby Technical Overview > Ruby Q&As

Ruby logo.gif
This tutorial provides a more detailed technical overview of how to work with Ruby on the Symbian platform. It 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.pngNote: Symbian Ruby runs on devices 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.

There is more information on the process in the Getting Started with Ruby trail.

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.

Ruby on the Symbian platform

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 are many online tutorials (including this one on ruby-lang.org), 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/.

Licence icon cc-by-sa 3.0-88x31.png© 2010 Symbian Foundation Limited. This document is licensed under the Creative Commons Attribution-Share Alike 2.0 license. See http://creativecommons.org/licenses/by-sa/2.0/legalcode for the full terms of the license.
Note that this content was originally hosted on the Symbian Foundation developer wiki.


Trails.png About Ruby on Symbian
 > Ruby in a Nutshell > Ruby Technical Overview > Ruby Q&As

This page was last modified on 21 October 2011, at 08:16.
57 page views in the last 30 days.