lua-import

An import function to require modules with relative pattern

$ luarocks install lua-import

The lua-import module provides a function. The function takes single string argument same as require, but the argument can be a relative path to the required module. The return value is the module referred by the path argument.

-- Add below line to init.lua or entry point of your project

require('import')

-- will import same as require
local m = import('spec.unit.fixture_one')

-- will import same as require with filepath separator
local m = import('spec/unit/fixture_one')

-- will import relative to current directory
local m = import('./fixture_one')

-- will import relative to current directory without filepath separator
local m = import('fixture_one')

-- will import relative to current directory with init.lua
local m = import('./fixture_two')

-- will import relative to current directory with init.lua withouth ./
local m = import('fixture_two/two_dot_one')

-- will import relative to parent directory
local m = import('../fixture_three')

-- will import relative to parent 2 up directories
local m = import('../../import')

Versions

0.1.0-1256 days ago55 downloads

Dependencies

busted >= 2.2.0-1
lua >= 5.1

Labels

Manifests