this is a UMD Module and also is a UMD tool
- Using umd to write lua, you can directly reference modules written by others on the network in the code without pre-installation. like this(using tsort):
return require("umd").define({
"exports",
"github.com/vanishs/lua-resty-tsort-release001/lib/resty/tsort"
}, function(exports, tsort)
- You can package UMD Module (including the UMDs they refer to) into a single lua file. like this(package github.com/vanishs/umdluam2-tag1/main to single.lua):
umd.lua src single.lua github.com/vanishs/umdluam2-tag1/main
- You can package UMD Module and execute a function in a single lua file. like this(package github.com/vanishs/umdluam2-tag1/main to func1.lua and execute function func1)
umd.lua src func1 github.com/vanishs/umdluam2-tag1/main
- Modules of Lua (old way)
local m2={}
local m1=require("m1")
function m2.func1()
print("m2")
m1.func1()
end
return m2
- UMD of Lua
return require("umd").define({
"exports",
"m1",
}, function(m2, m1)
function m2.func1()
print("m2")
m1.func1()
end
end)
-
You can check out this commit to learn how to make old code changes
-
"exports" is this module table.
-
modname can be a URL. like: "github.com/vanishs/lua-resty-tsort-release001/lib/resty/tsort" . (release001 is a tag name)
- Using LuaRocks
luarocks install umdlua
- copy amd.lua to lua search path