From Acorn to LuaCodex icon

A modest toolbox example in RiscLua I

I always admired Joe Taylor's AppBasic application, which he worked on over many years, gaining a great deal of insight into how the Toolbox worked. I do not think I can emulate anything quite like that, and I have to confess that I found the Toolbox rather daunting. This is a first step in my attempt to write a Toolbox application with RiscLua.

LuaFoxMitosisOthers have trodden this path before me. I should mention !LuaFox by Michael Gerbracht and !Mitosis by Stephan Kleinert.

The aim is to have an application, to be called !Codex, which displays a sequence of pages constructed from Drawfiles. It should put an icon on the iconbar, so that clicking Select on the iconbar icon displays the next page (or displays the first page if nothing is currently displayed) and clicking Adjust displays the previous page (or displays the last page if nothing is currently displayed). The iconbar icon should have a menu with the standard options for program information, Help, and Quit. This I reckoned to be a reasonably minimal target - an application which others could use without any programming, making up their own booklets of Drawfiles.

The first thing to do is create a directory !Codex, and then to design an icon for it in files !Codex.!Sprites22 and !Codex.!Sprites11. Then add the Obey file, !Boot, that simply contains the line

iconsprites .!Sprites
For the toolbox we need a file called Messages containing
# Messages
The Drawfiles need to be somwhere, so we create a subdirectory page of !Codex to put them in. But we also need a method of putting its contents in order. So we suppose that ! contains a text file, index, which lists the Drawfiles in order. In this example the Drawfiles have the original titles A,B and C. This is what index contains:
  => {  "A", "B", "C",} 
The point is that this is executable Lua code, returning a table listing the leaf names of three Drawfiles. We also put !Codex's !Help file inside ! because it is envisaged that the page directory is really for others to personalize. They will not need to touch anything else.

The !Run file contains

set codex$dir <Obey$dir>
set codex$path <codex$dir>.page.
ifthere <codex$dir>.Modules then <codex$dir>.Modules
<codex$dir>.!RunImage <codex$dir>
The Obeyfile Modules contains
RMENSURE Toolbox 0.00 RMLOAD System:modules Toolbox.Toolbox
RMENSURE Toolbox 0.00 ERROR Need Toolbox 0.00 to run
RMENSURE Menu 0.00 RMLOAD System:modules Toolbox.Menu
RMENSURE Menu 0.00 ERROR Need Menu 0.00 to run
RMENSURE Iconbar 0.00 RMLOAD System:modules Toolbox.Iconbar
RMENSURE Iconbar 0.00 ERROR Need Iconbar 0.00 to run
RMENSURE ProgInfo 0.00 RMLOAD System:modules Toolbox.ProgInfo
RMENSURE ProgInfo 0.00 ERROR Need ProgInfo 0.00 to run
RMENSURE Window 0.00 RMLOAD System:modules Toolbox.Window
RMENSURE Window 0.00 ERROR Need Window 0.00 to run
The !RunImage file will be a Lua file

ResEdResource fileThe heart of a toolbox application is its Resource file, which one creates with the application !ResEd. resource objectsThis file has the standard name res. In our case, !Codex has just four items in its Resource file:

iconbar properties

Clicking on the Iconbar object displays its properties. Note that in the Select and Adjust button boxes the option other is chosen. In the boxes to their right are two numbers, &a0 and &a1, selected randomly as the toolbox event codes that the program should receive when Select or Adjust are clicked on the iconbar. The sprite !codex is chosen at the top, and the menu object ibarmenu at the bottom. Only these four items did I need to supply.

Iconbar and codex_win had their autocreate flags set, only Iconbar had its autoshow flag set. The window object codex_win was, of course, to be the window displaying the Drawfile pages. Nothing in particular was done to it in the Resource file apart from change its name from Window. The ProgInfo object was filled in to give appropriate information. Iconbar menu

For the Help option in ibarmenu the radio button in its click-action box was set to other, and the number &a2 assigned in the box to its right, as the toolbox event code to be delivered to the program when the help option is clicked. I have to confess that the three arbitrary codes &a0, &a1 and &a2 were chosen at random. The same cannot be said of the code &82a91 chosen for the toolbox event code returned for the Quit option. This is event code Toolbox_QuitQuit and seems to have become a standard choice, even though it is not strictly necessary. But you can see why, just on etymological grounds. That just about wraps up the Resource file for !Codex. It only remains to describe the contents of !RunImage.