- Joined
- Apr 24, 2012
- Messages
- 5,113
Since Lua is coming to Warcraft 3 and Lua IO is not supported, it would be a hassle breaking the reknown Lua modules which could be helpful in Wc3 Lua modding, so I wrote a module system for Lua.
There are two module systems I designed: a dependent module system, and an asynchronous module system:
Example DMS:
Example AMS:
Here's the repo link: LXSMNSYC/Lua-Wc3-Module
There are two module systems I designed: a dependent module system, and an asynchronous module system:
Example DMS:
Lua:
module.create("A")(function ()
print("module A loaded")
return 100
end)
module.create("B")(function ()
print("module B loaded")
return 200
end)
module.create("C")(function ()
print("module C loaded")
return function (a, b)
return a + b
end
end)
module.create("D", {"A", "B", "C"})(function (imports)
print("module D loaded")
return imports.C(imports.A, imports.B)
end)
module.create("E")(function ()
print("module E loaded")
return print
end)
module.create("F", {"D", "E"})(function (imports)
print("module F loaded")
imports.E(imports.D)
end)
module.init()
Example AMS:
Lua:
module.create("A", function() return 100 end)
module.create("B", function() return 200 end)
module.create("add", function ()
return function (a, b)
return a + b
end
end)
module.create("print", function ()
return print
end)
module.create("addAB", function (require)
local A = require("A")
local B = require("B")
local add = require("add")
return add(A, B)
end)
module.create("init", function (require)
require("print")(require("addAB"))
end)
module.load("init")
Here's the repo link: LXSMNSYC/Lua-Wc3-Module
Last edited: