Skip to content

CetoBasilius/index

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

index.*

Overview


Lua module path shortener for require function. Any call to require will be intercepted and if normal require does not yield results, index will search in added paths for modules.

Functions


  • index.addPath(path1, path2, ...)
    • Adds path to index. Multiple paths can be added as different parameters.
  • index.setNamespace(newNamespace)
    • Will set the namespace to newNamespace. Adding this means that requires will ignore the namespace if found, on requires.
  • index.getRequirePath(moduleName)
    • Will return the real, full require path, if the module has been loaded by index. Will return moduleName otherwise.

Example usage


Supposing you have multiple libraries deep in folders:

  • "path.to.libs.numbers"
  • "path.to.libs.strings"

Simply do: require("index")("path.to.libs") and now you can require your libs require("numbers") and require("strings").

Required modules will receive a table via ... with the properties:

  • .name: The real path where the module was found.
  • .path: The path that was added by index.

A small demo is included in the source code.

Notes


Adding require path require("index").addPath("path.to.libs") and require("index")("path.to.libs") have the same effect.

Setting namespace is needed for large dependencies which require internal files. For example, if your dependency folder and file combo is screen and inside screen.lua you need to require other file, for example, helper.lua inside the same project, you will need to add the project namespace, which in this case is screen, so you would need to do require("screen.helper"). Setting namespace can also be done by doing: require("index")("path.to.libs")("namespace")


Copyright (c) 2014-2020, Basilio Germán All rights reserved.

About

Lua module path shortener for require function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages