require("tprint") local Proxies = { __mode = "k", load = function(self, tbl) local proxy = self[tbl] local lib = GetPluginVariable(proxy.id, "Library") if lib == nil then error("[LoadPPI]: Unable to load interface for plugin " .. (proxy.id or ""), 0) end self[tbl].library = loadstring(lib)() return proxy.library end, } setmetatable(Proxies, Proxies) local Proxy = { new = function(id) local proxy = { id = id, library = false, __metatable = false, __newindex = function(tbl, idx, val) (Proxies[tbl].library or Proxies:load(tbl))[idx] = val end, __index = function(tbl, idx) return (Proxies[tbl].library or Proxies:load(tbl))[idx] end, } local tbl = setmetatable({}, proxy) Proxies[tbl] = proxy return tbl end, } -- Creates new Proxies for a plugin library local Loader = { __metatable = false, __newindex = function() error("Please don't modify this table.") end, __index = { load = function(id) if type(id) ~= "string" then error("Plugin ID must be a string.") end return Proxy.new(id) end, }, } -- Returns a new read-only loader. return setmetatable({}, Loader)