jeudi 19 janvier 2017

Fast way to determine if variable is a function?

To determine if a variable is a function, I use the following method

function isFunction(variable)
    return type(variable) == "function"
end

To my knowledge, this is a string comparison. As I've understood it, string comparisons are relatively slow and I fear this function might be a bottleneck in my code. Is there a less costly way to determine if a variable is a function?

I'm hoping there's a function which returns an integer that indicates the type of the variable instead. Or I can ask my question another way: How does type(var) determine the type of a variable? Surely, each variable can't hold a string representing its type so I'm guessing there is some backend-stuff in lua that looks up the string "function" when invoking type(var).





Aucun commentaire:

Enregistrer un commentaire