Re: function to check if a symbol in a library exists or not

  • From: Coda Highland <chighland@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 31 Jul 2012 08:01:03 -0700

On Tue, Jul 31, 2012 at 7:19 AM, Duncan Cross <duncan.cross@xxxxxxxxx> wrote:
> On Tue, Jul 31, 2012 at 3:03 PM, Coda Highland <chighland@xxxxxxxxx> wrote:
>> On Tue, Jul 31, 2012 at 3:27 AM, Fjölnir Ásgeirsson
>> <fjolnir@xxxxxxxxxxxxx> wrote:
>>> Well no. It pcalls, and catches the error. That can't possibly be as fast 
>>> as just calling dlsym straight. (which is how you check for symbols at 
>>> runtime => I'm not sure what the issue is)
>>
>> Mike Pall said just a few e-mails ago that pcall is extremely cheap,
>> and it's free if it gets JIT-compiled.
>
> Look again - he clarified that this is only true if the code getting
> pcall-ed completes normally (i.e. the first return value of the pcall
> is true), and not if an error is involved, which is "very expensive on
> some platforms".
>
> -Duncan
>

Yes, but read the rest of my e-mail: he's only calling it once anyway.
I find this to be the cleanest solution as long as you're not having
to deal with errors in a performance-sensitive place.

/s/ Adam

Other related posts: