lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Eric Ries wrote:
> > I agree that enforcing the isfunction might be too restrictive, but just
> > using isnil and then calling the object will raise an error if it is not
> > "callable".
> >
> > So, either you have to deal with the possible errors, or do the more
> > restrictive way. It depends on your application.
> It wouldn't be that hard to implement an "iscallable" function, would it?
> This would return true if lua_isfunction returns true, or if the object in
> question has the appropriate tag method(s) set. Maybe that's just overkill.

But what does it help?  Making sure that an object is callable will not
say that it's save to call it.  You would only know, that lua_call itself
will not generate an "unable to call" error.  But it may raise any other
error.  The object is free to produce an error in its first statement.

The only thing you do is a check for a possible "unable to call" error.
And shouldn't this be done by the VM?  The rules may change some day...

Ciao, ET.

PS: Btw, similar things apply to table checks...