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

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 30 Jul 2012 09:24:24 +0100

On Mon, Jul 30, 2012 at 7:46 AM, Cosmin Apreutesei
<cosmin.apreutesei@xxxxxxxxx> wrote:

> Btw, I think it would be more in the spirit of Lua if the ffi wouldn't
> break at all when a symbol is not found and just return nil instead. I
> wouldn't even need the check function then, and it would make life
> easier, like with the metatype table constructor above.

This did come up before and it seems unlikely to change. Nil is a
valid result for a symbol (null) for a start. Also pcall has no
particular overhead on luajit so there is no real reason not to use
it. Also you can always memoize yourself in a table if it is
worthwhile, or test for functionality at library load time.

If it is something for which there is no way to do an alternative
implementation I might just let it error. What is code using your
library going to do if it needs the functions? Maybe you provide a
test routine or table that lets the user know what is there so they
can abort if stuff they need is missing.


Other related posts: