User:NXTBoy/Scripts/implicit multiplication

From Legacy Roblox Wiki
Jump to navigationJump to search

This code allows you to do implicit multiplication of single-character global variables. It's a neat use of metatables, but I'd strongly advise against using it.

setmetatable(getfenv(), {    
    __index = function(t, k)    
        local product = 1    
        for c in k:gmatch(".") do    
            local val = rawget(t, c)    
            if type(val) ~= "number" then return end    
            product = product * val    
        end    
        return product    
    end    
})

Here is the code it allows you to write

y = 2    
x = 3    
print(xy) -- 6  
a = 2  
print(xxya) -- 36