• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Lua] [Deprecated] __jarray Compactor (GUI helper)

This small snippet will cut the number of tables produced by __jarray almost by 50%. The regular __jarray function currently produces two tables per initialization due to the setmetatable call, however this will instead cache the metatables with the same default return value and recycle them.

Lua:
do --__jarray compactor 1.0 by Bribe
    local mts = {}
    function __jarray(default)
        if default then
            local mt = mts[default]
            if not mt then
                mt = {__index = function() return default end}
                mts[default] = mt
            end
            return setmetatable({}, mt)
        end
        return {}
    end
end
 
Top