Global methods: A plethora of issues

I have a script which declares global functions as thus:

local VERBOSE 						= 1
local TEST 							= game:GetService("TestService")

local wprint: (number) -> typeof(print) = function(n)
	return function(...)
		if VERBOSE < n then return end
		print(...)
		TEST:Message("\nStack Begin"..debug.traceback("", 2).."Stack End\n")
	end
end
_G.wprint = wprint
_G.vprint = wprint(1)
_G.vvprint = wprint(2)
_G.vvvprint = wprint(3)

_G.verbosityLoaded = true

return _G

Unfortunately, neither the typechecker nor IntelliSense respects variables in _G. Furthermore, these functions require one to add a line such as

repeat vprint = _G.vprint::typeof(print) task.wait() until vprint

to the top of one’s scripts.
Both of these issues suck, but I really really REALLY want my global functions without requiring any module scripts.
Any solutions?

1 Like

There are no solutions as of current. There is no way to predefine any global types without some external mean such as a module script.

That sucks a lot, that really should be a feature.

Adding it as a feature would likely be a security vulnerability, since for it to be used in the code without such declaration means modifying the script’s environment. While exploiters already have means of modifying environments, I doubt Roblox wants to make it any easier for them to do so.

If you really want to, you could make a plugin that modifies your script sources to add the getter code automatically, and also hide it from the editor, but that’s a little tedious.

Heads up, _G is quite old now and generally discouraged for use, a more modern API for this would be something like a SharedTable.