This figure shows the architecture of an application created with Scrupp. The whole development happens on the right side using Lua.
The behaviour of Scrupp depends on the command line arguments and the operating system. If you drop a file or directory on the Scrupp executable, it's like this file or directory is the first command line argument.
On startup, Scrupp constructs a search path. This search path is a list of paths and zip archives. If Scrupp tries to open a file, it looks for it in these paths/archives. If the file exists in multiple paths, the first one is chosen.
In order to understand the way Scrupp constructs the search path and sets the working directory the following definitions are needed:
- base directory
- The directory that contains the executable.
- working directory
- This directory is important if you want to modify files using the input and output facilities of plain Lua.
- On Linux, the SHARE_DIR defaults to
/usr/share/scrupp(defined in Main.h). If you copy the support files ("main.slua" and the directories "fonts" and "scripts") to
/usr/share/scruppthey can be found by Scrupp.
The following figure shows Scrupp's behaviour on startup, i. e. how it sets the search path and working directory. Click it for a bigger version.
The following list shows the possibilitis for running Scrupp.
- No command line arguments
$ scrupp [-- arg1 arg2 ... argN]
Scrupp tries to open the file
main.slua. The working directory of the script will be the one containing the executable. If this file is not found, Scrupp will try to open the zip archive
main.sarwhich has to contain the file
main.slua. If both files are not found, an error will be thrown. Extra arguments to the script have to be separated from the executable's name by
- A Lua file as argument
$ scrupp <Lua file> [arg1 arg2 ... argN]
Scrupp tries to execute the Lua file. The working directory will be the one containing the Lua file. It is possible to give extra arguments to the Lua file.
- A zip archive as argument
$ scrupp <zip archive> [arg1 arg2 ... argN]
The archive is prepended to the search path. The directory that contains the archive becomes the working directory. After this Scrupp tries to execute
main.sluawhich should be located inside this archive. It is possible to give extra arguments to the Lua file.
- A directory as argument
$ scrupp <directory> [arg1 arg2 ... argN]
The directory is prepended to the search path and set as the working directory. After this Scrupp tries to execute
main.sluawhich should be located inside this directory. It is possible to give extra arguments to the Lua file.
Before running a Lua file, Scrupp collects all command line
arguments in the global table
arg. The name of the
chosen Lua file, directory or archive becomes the element at index
0 in that table. Additional arguments are stored in index 1, 2 and
so on. The name of the executable goes to index -1. The script can
access these arguments by using
arg, arg, etc.
or the vararg expression '...'.
-- print the name of the script print("name of the script:", arg) -- print the number of arguments to the script print("number of arguments:", select('#', ...) ) -- print all arguments print("arguments:", ...) -- this prints the first argument print("Argument 1: ", arg or "none") -- exiting Scrupp scrupp.exit()
Just save this example code in a file called
argtest.lua and run
$ scrupp argtest.lua arg1 arg2
This can be done with every example from the manual. To get started have a look at the General Functions, save the example in a file and run this file with Scrupp.