[DiscordArchive] hmm, but in your examples there the classname is nowhere as string, would that matter?
[DiscordArchive] hmm, but in your examples there the classname is nowhere as string, would that matter?
Archived author: Foe • Posted: 2022-05-16T18:04:10.316000+00:00
Original source
```Lua
-- Parent class registry with global function to register and fetch classes
local classes = {}
function RegisterClass(class)
table.insert(classes, class)
end
function GetClasses()
return(classes)
end
-- Define class A and register
local A = {}
function A:get()
print(123)
end
RegisterClass(A)
-- Define class B and register
local B = {}
function B:get()
print("xyz")
end
RegisterClass(B)
-- Iterate over all classes and call get method
for k, v in pairs(GetClasses()) do
v:get()
end```
Archived author: Grandold • Posted: 2022-05-16T18:04:13.625000+00:00
Original source
ye just happy to get any responses and help, I'm kinda thinking out loud here as a lot of stuff is new
Archived author: Grandold • Posted: 2022-05-16T18:04:32.034000+00:00
Original source
ye Foe ended up doing it that way
Archived author: Foe • Posted: 2022-05-16T18:04:35.965000+00:00
Original source
That gives you local level storage of the object with two functions to register and return
Archived author: Foe • Posted: 2022-05-16T18:04:59.340000+00:00
Original source
Then you can require the framework wherever you define and call classes
Archived author: Grandold • Posted: 2022-05-16T18:06:11.209000+00:00
Original source
yeah it works that way atm, I was just aiming to some sort of solution where I wouldnt have to do anything inside the A and B file to register the classes, instead the file that handles loading of classes would somehow know how to do that
Archived author: Grandold • Posted: 2022-05-16T18:06:44.944000+00:00
Original source
but as the "library" classes are local and I think I wanna keep it that way, it would be kinda tweaky
Archived author: Foe • Posted: 2022-05-16T18:06:45.734000+00:00
Original source
That doesn't sound like a good approach
Archived author: Grandold • Posted: 2022-05-16T18:07:06.349000+00:00
Original source
well i dunno, seen that kinds of autoloaders a lot
Archived author: Foe • Posted: 2022-05-16T18:07:39.517000+00:00
Original source
yeah, Lua doesn't really work that way, unless you want to deal with your own file type and file io and string dumping on load