Running LuaGRAPH

 LuaGRAPH scripts

LuaGRAPH scripts are standard Lua scripts and may utilise all the features provided by Lua and it's companion libraries. You start a LuaGRAPH script simply from the command line:


However, in order to make use of LuaGRAPH it must be loaded into the Lua universe. This can be done by using Lua's -l commandline option:

$ lua -l graph -l OTHER SCRIPTFILE

or using the Lua require function.

This line starts the Lua interpreter and loads LuaGRAPH and other modules specified via the -l command line option before the user script SCRIPTFILE is loaded and executed.

The user script has now access to all the LuaGRAPH definitions via the global table graph.

You can also specify lua as the interpreter to use inside the Lua script, which then allows you to directly execute the script.

#!/usr/bin/env lua

Note, that this line is NOT standard Lua code and must only appear in the first line of your script.

Loading module "graph"

A more flexible way is to load the  LuaGRAPH library from within your Lua script:

-- Load the LuaGRAPH module
require "graph"

This loads all definitions provided by LuaGRAPH into the new global namespace graph.

Since the namespaces are accessed frequently, it is recommended to access LuaGRAPH definitions using a local reference to the namespace. It also allows you to rename the namespace.

-- Load the LuaGRAPH module 
local graph = require "graph"

In the case the user defined Lua code is distributed among different script files, it is always possible to set such local references:

-- Since graph is a symbol in the global Lua namespace the 
-- following code is always valid:
local graph = graph