Skip to content
This repository has been archived by the owner on Jul 18, 2021. It is now read-only.

Handle module caching in a Team Create friendly way #1

Open
vocksel opened this issue Nov 26, 2017 · 0 comments
Open

Handle module caching in a Team Create friendly way #1

vocksel opened this issue Nov 26, 2017 · 0 comments

Comments

@vocksel
Copy link
Owner

vocksel commented Nov 26, 2017

As detailed in the Caveats section of the README, support for a team environment is currently very poor. We need a better system for importing modules that will not interfere with other users.

One proposed by einstienK on the devforums looks incredibly promising and should be exactly what we need:

local function assertf(c,m,...)
	if c then return end
	error(m:format(...),0)
end

local loading,ERR = {},{}
local function customRequire(mod)
	local cached = loading[mod]
	while cached == false do wait() cached = loading[mod] end
	assertf(cached ~= ERR,"Error while loading module")
	if cached then return cached end
	local s,e = loadstring(mod.Source)
	assertf(s,"Parsing error for %s: %s", mod:GetFullName(), tostring(e))
	loading[mod] = false
	local env = setmetatable({
		script = mod;
		require = customRequire;
	},{__index=getfenv()})
	s,e = pcall(setfenv(s,env))
	if not s then loading[mod] = ERR end
	assertf(s,"Running error for %s: %s", mod:GetFullName(), tostring(e))
	loading[mod] = e return e
end

customRequire(firstModule)

It's just a matter of implementing this now. I have other projects to worry about right now but this is a top priority when I get back to working on Code Cop. (If anyone else stumbles upon this and wants to give it a shot tho, feel free)

Once implemented we can also delete the Caveats section as it only applies to this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant