lua-users home
lua-l archive

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


On Sun, Oct 4, 2015 at 4:04 PM, Simon Cozens <simon@simon-cozens.org> wrote:
> On 05/10/2015 06:53, Coda Highland wrote:
>> Just wondering if you had considered an API like:
>>
>> dc:openDocumentWithContentsOfURL{fileurl, display=true, error=nil}
>
> I agree that the syntax looks nicer, but there are a couple of
> challenges: first, you're now resolving the method name a lot later,
> which is a bit of a pain (but can be overcome); second, and more
> importantly, you need to construct the method name by pulling the keys
> out of the table *in the right order*. The example you've given is fine
> but how would you correctly construct a method name out of
>
> dc:shouldCloseWindowController({wc, delegate=d, shouldCloseSelector=s,
> contextInfo=c})
>
> (or {wc, delegate=d, contextInfo=c, shouldCloseSelector=s}, which is
> exactly the same table)?
>
> Given that - and the fact that the syntax I have gone with is familiar
> to users of other bridges such as PyObjC - I don't think it's worth the
> change for a bit of syntactic sugar.
>
> S

I'm not aware of any APIs in Cocoa that are overloaded in a way that
would be sensitive to ordering, but I get what you're saying -- since
you have to construct the message name, you would have to know the
proper order in advance.

My solution to this would be to just use something like
class_copyMethodList when bridging an object and use that to construct
the complete method list in advance. You could cache this based on
instance type, so effectively speaking you'd be resolving it EARLIER,
not later.

/s/ Adam