Im trying to create a utility "class" wich returns "allObjects" either by function or directly.
Objects are files within a specified folder with a specified extension.
local Handler = {object = {}}
local workspace = {
shell.getWorkingDirectory().."dir1",
shell.getWorkingDirectory().."dir2"
}
for key, dir in pairs(workspace) do
for element in fs.list(dir) do
local s, e = string.find(element, "%.")
local ext = string.sub(element, s + 1)
local title = string.sub(element, 1, s - 1)
if ext == "foo" or ext == "bar" then
if Handler.object[ext] == nil then Handler.object[ext] = {} end
result, Handler.object[ext][title] = shell.execute(dir.."/"..element)
end
end
end
return Handler
Works actually fine but the problem is that I need to require the handler in the object files themselfs since they need to know eachother.
This though leads to a problem since I also use the handler in the main class which when called gives the error:
"already loading: handler"
Example of an object ("dir1/obj1.foo"):
local handler = require("handler")
local obj1
obj1.title = handler.object.foo.obj2.title
return obj1
The main file needs the handler aswell:
local handler = require("handler")
--For example
for k, v in pairs(handler.object.foo)
v.run()
end
which isn't a suprise. I also tried shell.execute instead of require which ended in an endless loop. I understand the problem but I can't think of an elegant way to solve it.
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Im trying to create a utility "class" wich returns "allObjects" either by function or directly.
Objects are files within a specified folder with a specified extension.
Works actually fine but the problem is that I need to require the handler in the object files themselfs since they need to know eachother.
This though leads to a problem since I also use the handler in the main class which when called gives the error:
"already loading: handler"
Example of an object ("dir1/obj1.foo"):
The main file needs the handler aswell:
which isn't a suprise. I also tried shell.execute instead of require which ended in an endless loop. I understand the problem but I can't think of an elegant way to solve it.
Link to post
Share on other sites