EZconfig module : attribute access abstraction

ezconfig is an abstraction for instances that let you index them like a table for their attributes.
here’s the link to the module, and the example

local EZconfig = require(path.to.module) -- it gets the module
local Config = EZconfig(path.to.configuration) -- Returns an object that can be indexed for the argument's attribute

local FireRate = Config["FireRate"] --  path.to.configuration:GetAttribute("FireRate")
Config["MaxAmmoCount"] = 8 -- path.to.configuration:SetAttribute("MaxAmmoCount",8)

--these two do the same thing
print(Config:GetAll()) -- print( path.to.configuration:GetAttributes() )
print(Config()) -- print( path.to.configuration:GetAttributes() )

Working on a script, i knew it would make the code much harder to read and write if i spammed :GetAttribute everywhere. I wrote a two liner to set an empty table to a metatable with index and newindex set to return the result of the getattribute and setattribute methods.

i decided to move the code over to a module so i wouldnt have to have the big line at the top of every script that reads a gun’s config. i wrote some notes and an example script so i could share my idea with whoever needs it. i think its useful, even though theres probably an easier way to handle configs

3 Likes

This is pretty neat. Actually very useful for games with tons of configurations necessary.

1 Like