an object with "call"/"apply" properties should be "callable"
eg,
anus = {
"call": function(){ ... }
}
anus() // same as anus.call(anus)
Name:
Anonymous2011-12-18 16:58
Yeah, you can do this in lua. It's just syntactic sugar really. The runtime would need to check the type of the thing being called, which it has to do anyways for type safety, and if it is a function, a normal function call will result, and if it is an object, then o.call(...) will attempt to be executed. It could come in handy if you have code that relies on functions being passed in as arguments, and you would like to pass in an object instead of a function. But you can always emulate this by wrapping your object in a closure.
function checkMaDubs(dubsPrinter) {
dubsPrinter("<<-- check ma dubs");
}
now it is impossible to change the anus() function without wiping out all the properties on it... you would have to make a new function object and copy over all the properties from the old anus and that would probably mess up the prototype.
in the first example, one can just change the call property to change the function
you could store the actual function to call as a property, and then have the anus function call the property function when anus is called. But why you changing methods at run time huh? Doncha know that bad?