Slogan has a built-in package manager to ease distribution of software. Any Slogan project can be converted into a package by
adding two files to the project's root folder – init.sn
and build
. Init.sn
is a Slogan script
called by the Slogan runtime for loading the package. It contains all initialization code for the package. Build
should be an executable script that is used to compile the package. It can also contain code to install any dependencies the
package needs to work properly. The code that needs to run each time the package is loaded must be in the file src/core.sn
.
To make ourselves familiar with the process of creating packages, let us work through an example. The project from which we create the package is called "simple" and its directory structure is as shown below:
simple/
-> init.sn
-> build
-> src/
--> core.sn
The script src/core.sn
implements the entire functionality of the package:
// src/core.sn
function hello() "hello simple world!"
Init.sn
call the init_package
function which will find the correct path
to core.sn
and load it:
// init.sn
init_package("simple")
The build
script compiles init.sn
into object code:
#!/bin/bash
slogan -c init
Make sure that the build
script is executable:
$ chmod +x build
You may also write the build script in Slogan. In that case the name of the script must be build.sn
.
The Slogan interpreter will evaluate this while building the package, so it need not be made executable. If you choose to write
the build script in Slogan, its contents should be:
// build.sn
compile("init")
To test the package, we should first install it using the Slogan package manager:
$ slogan -i "simple,local,/mypackages/simple"
You should replace the path /mypackages/simple
with the actual path to your package.
Now that the package is installed, we can load and use it:
load_package("simple")
hello()
// hello simple world
Once a package is developed and tested, it can be distributed as a compressed file or hosted on a network server.
See the reference on the install_package
function to learn more about remote
distribution options.