Runtime:setCheckGlobals( true ) -- no longer working

Runtime:setCheckGlobals( true ) – is no longer working

Has anyone else noticed that Runtime:setCheckGlobals( true ) stopped working a while ago.  It’s a brilliant little method that exposed not only those pesky globals but also my pesky slips of logic ; )

*I only use this in the Simulator as an extra debugging layer.

Max OS 10.12

Corona 2016.2992 (and several early versions)

UPDATE This was removed/disabled a while back in build 2876

http://developer.coronalabs.com/release/2016/2876/

Here is a alternative solution fix:

--=================================================== --= Niklas Frykholm -- basically if user tries to create global variable -- the system will not let them!! -- call GLOBAL\_lock(\_G) -- --=================================================== function GLOBAL\_lock(t) local mt = getmetatable(t) or {} mt.\_\_newindex = lock\_new\_index setmetatable(t, mt) end --=================================================== -- call GLOBAL\_unlock(\_G) -- to change things back to normal. --=================================================== function GLOBAL\_unlock(t) local mt = getmetatable(t) or {} mt.\_\_newindex = unlock\_new\_index setmetatable(t, mt) end function lock\_new\_index(t, k, v) if (k~="\_" and string.sub(k,1,2) ~= "\_\_") then GLOBAL\_unlock(\_G) error("GLOBALS are locked -- " .. k .. " must be declared local or prefix with '\_\_' for globals.", 2) else rawset(t, k, v) end end function unlock\_new\_index(t, k, v) rawset(t, k, v) end local public = {} public.lock = GLOBAL\_lock public.unlock = GLOBAL\_unlock return public

local gl = require "global\_lock" gl.lock(\_G) \_G.bob = true

Note: Be sure not to lock until AFTER initializing SSK2.

require "ssk2.loadSSK" \_G.ssk.init() \_G.ssk.init( { launchArgs = ..., enableAutoListeners = true, exportCore = true, exportColors = true, exportSystem = true, exportSystem = true, gameFont = "Prime.ttf", debugLevel = 0 } ) local gl = require "global\_lock" gl.lock(\_G)

Uh oh… too quick on the advice to file bug…

This was disabled in an prior build:

http://developer.coronalabs.com/release/2016/2876/

PS - Ironically, I had this in the ‘external’ section of SSK2 and took it out because this feature was in Corona.  I’ll put a locker back in SSK2.  So this will be available in a future release.

Thanks Ed,

I’ll give that a try and lock out those globals AFTER I initialize SSK2 and Coronium (I’m still using Coronium for now).

Jonathan

– I tried it, it’s a great module (not as useful as Runtime:setCheckGlobals) but helpful nonetheless.  Thanks for sharing!

UPDATE This was removed/disabled a while back in build 2876

http://developer.coronalabs.com/release/2016/2876/

Here is a alternative solution fix:

--=================================================== --= Niklas Frykholm -- basically if user tries to create global variable -- the system will not let them!! -- call GLOBAL\_lock(\_G) -- --=================================================== function GLOBAL\_lock(t) local mt = getmetatable(t) or {} mt.\_\_newindex = lock\_new\_index setmetatable(t, mt) end --=================================================== -- call GLOBAL\_unlock(\_G) -- to change things back to normal. --=================================================== function GLOBAL\_unlock(t) local mt = getmetatable(t) or {} mt.\_\_newindex = unlock\_new\_index setmetatable(t, mt) end function lock\_new\_index(t, k, v) if (k~="\_" and string.sub(k,1,2) ~= "\_\_") then GLOBAL\_unlock(\_G) error("GLOBALS are locked -- " .. k .. " must be declared local or prefix with '\_\_' for globals.", 2) else rawset(t, k, v) end end function unlock\_new\_index(t, k, v) rawset(t, k, v) end local public = {} public.lock = GLOBAL\_lock public.unlock = GLOBAL\_unlock return public

local gl = require "global\_lock" gl.lock(\_G) \_G.bob = true

Note: Be sure not to lock until AFTER initializing SSK2.

require "ssk2.loadSSK" \_G.ssk.init() \_G.ssk.init( { launchArgs = ..., enableAutoListeners = true, exportCore = true, exportColors = true, exportSystem = true, exportSystem = true, gameFont = "Prime.ttf", debugLevel = 0 } ) local gl = require "global\_lock" gl.lock(\_G)

Uh oh… too quick on the advice to file bug…

This was disabled in an prior build:

http://developer.coronalabs.com/release/2016/2876/

PS - Ironically, I had this in the ‘external’ section of SSK2 and took it out because this feature was in Corona.  I’ll put a locker back in SSK2.  So this will be available in a future release.

Thanks Ed,

I’ll give that a try and lock out those globals AFTER I initialize SSK2 and Coronium (I’m still using Coronium for now).

Jonathan

– I tried it, it’s a great module (not as useful as Runtime:setCheckGlobals) but helpful nonetheless.  Thanks for sharing!