1 local Module = Dragonblocks.create_class()
3 function Module:constructor(name)
5 self._dependencies = {}
7 local depfile = io.open(self:get_path() .. "/dependencies.txt")
9 local data = depfile:read("*a")
11 self._dependencies = data:split("\n")
15 function Module:run(s)
16 return require(self:get_path() .. "/src/" .. s)
19 function Module:start()
23 print("Started module " .. self._name)
26 function Module:get_path()
27 return "modules/" .. self._name
30 function Module:get_data_path()
31 local p = "data/" .. self._name
32 if not lfs.attributes(p, "mode") then
38 function Dragonblocks:read_modules()
39 if not lfs.attributes("data", "mode") then
40 lfs.mkdir(self.data_path)
43 for modulename in lfs.dir("modules") do
44 if modulename:sub(1, 1) ~= "." then
45 local m = Module(modulename)
46 self.modules[modulename] = m
51 function Dragonblocks:start_module(name)
52 local m = self.modules[name]
54 error("Module '" .. name .. "' not found.")
55 elseif m._started then
58 for _, dep in ipairs(m._dependencies) do
59 self:start_module(dep)