/umdlua

Primary LanguageLuaMIT LicenseMIT

umdlua (URL Module Definition of Lua)

this is a UMD Module and also is a UMD tool

WHY UMD?


  • 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

HOW TO WRITE A UMD?


  • 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)

INSTALLATION


  • Using LuaRocks
luarocks install umdlua
  • copy amd.lua to lua search path