Skip to content

Indaxia/imp-lua-mm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lua Module Manager for IMP

IMP - Indaxia Modules & Packages for Lua (Package Manager).

Provides functions to create and use ES6-style modules in lua code.

Modules let you write componentized and sharable code. IMP Module Manager allows you to declare your modules in any order. It arranges everything for you: dependency tree, loop detection, lazy loading, naming conflicts isolation etc.

It is friendly for code inspectors like:

Automatic installation

Initialize and build your project using IMP

Manual installation

Copy imp-module-manager.lua to your code head section.

Example Usage

-- file 1
Hello = Imp.export("Hello", function()
  -- make any init code here that is executed once

  -- export module (your data & functions or empty table)
  return {
    foo = "bar",
    welcome = function() print "Hello world!" end
  }
end)

-- file 2
World = Imp.export("World", function()
  -- import modules
  local Hello = Imp.import(Hello)

  -- make any init code here that is executed once
  Hello.welcome()

  -- export module (your data & functions or empty table)
  return {}
end)

-- init section (main)
local World = Imp.import(World)

Result:

Hello world!

Alternate naming

You can rename globally defined modules in case of conflict and use both:

-- vendor module 1
Hello = Imp.export("Hello", function()
  return {
    x = "this is A"
  }
end)

-- vendor module 2
Hello = Imp.export("Hello", function()
  return {
    y = "this is B"
  }
end)

-- vendor module 3
Hello = Imp.export("Hello", function()
  return {
    z = "this is C"
  }
end)

-- your module
World = Imp.export("World", function()
  ---@type { x: string }
  local A = Imp.import({ name = "Hello" })
  ---@type { y: string }
  local B = Imp.import({ name = "Hello*" })
  ---@type { z: string }
  local C = Imp.import({ name = "Hello**" })

  print(A.x .. ", " .. B.y .. ", " .. C.z)
end)

-- init section (main)
World = Imp.import(World)

Result:

this is A, this is B, this is C

About

Lua Module Manager for IMP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages