Architecture
This figure shows the architecture of an application created with Scrupp. The whole development happens on the right side using Lua.
Command Line Interface
At the beginning, Scrupp tries to run a Lua file which is chosen depending on the command line arguments.
- No command line arguments
$ scrupp
In this case Scrupp tries to open the file
main.lua
in the directory where the Scrupp executable is located. This directory will also be the working directory of the script. However, it is not possible to give extra arguments to the Lua file, yet. - A Lua file as argument
$ scrupp -e <Lua file> arg1 arg2 ...
Scrupp adds the directory that contains the Lua file to the search path. Every attempt to open a file (images, sounds, music, fonts, other Lua files) will result in a search for it in this directory. In case the file is not found there it will be searched in the directory of the executable. After that the Lua file is executed. Now it is possible to give extra arguments to the Lua file.
- A directory as argument
$ scrupp <directory> arg1 arg2 ...
The directory is added to the search path and set as the working directory. Every file access results in a search in this directory at first. Only if it is not found there the file will be searched in the directory of the executable. Then Scrupp tries to execute
main.lua
which should be located inside this directory. Now it is possible to give extra arguments to the Lua file. - A zip archive as argument
$ scrupp <zip archive> arg1 arg2 ...
The archive is added to the search path. The directory containing the archive becomes the working directory. Every file access results in a search in this archive at first. The directory of the executable is searched after that. Then Scrupp tries to execute
main.lua
which should be located inside this archive. It is possible to give extra arguments to the Lua file.
Script Arguments
Before running the 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. Any arguments before this name (name of the executable, the
options) go to negative indices. The script can access these
arguments by using arg[1], arg[2],
etc. or the vararg
expression '...'.
-- print the name of the script print("name of the script:", arg[0]) -- 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[1] or "none") -- exiting Scrupp game.exit()
Just save this example code in a file called
argtest.lua
and run
$ scrupp -e 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.