• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Modules for Wc3 Lua

Status
Not open for further replies.
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:
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:
Status
Not open for further replies.
Top