vrld / hump

LÖVE Helper Utilities for Massive Progression
http://hump.readthedocs.org
1.09k stars 154 forks source link

hump.signal - crashes when sending "clear", "remove" or any other signals that share a name with a Registry function name. #118

Open sysl-dev opened 5 years ago

sysl-dev commented 5 years ago

signal.emit("clear")

Error: library/hump/signal.lua:42: bad argument #1 to 'pairs' (table expected, got function)

function Registry:emit(s, ...)
    for f in pairs(self[s]) do
        f(...)
    end
end

Registry:emit does not check if self[s] is a function before trying to read it like a table.

sysl-dev commented 5 years ago

This is the patch I'm using:

function Registry:emit(s, ...)
    if type(self[s]) == "function" then
        print("HUMP Signal:", "This would have crashed hump signal.")
    else
    for f in pairs(self[s]) do
        f(...)
    end
end