Module Definition

class halmd.utility.module(new)

Define new module.

Parameters:new (function) – module constructor
Returns:module table


local module = require("halmd.utility.module")

local M = module(function(args)
    -- create and return instance

return M

This function provides a lazy module loader, which may be used to load submodules on demand. For a namespace, one defines a loader module:

-- halmd/mdsim/potentials/init.lua

local module = require("halmd.utility.module")

return module.loader("halmd.mdsim.potentials")

The loader module then loads submodules upon use:

local potentials = require("halmd.mdsim.potentials")

-- This loads the lennard_jones module.
local lennard_jones = potentials.lennard_jones

If a submodule cannot be loaded, the loader raises an error.

Parameters:name (string) – fully qualified name of module
Returns:module table with metatable containing module loader