lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
440 stars 70 forks source link

Wrap gi.require with assert in class.lua and ffi.lua #319

Closed stefano-m closed 5 months ago

stefano-m commented 5 months ago

Fixes #71

Calling gi.require may not always succeed. If we do not wrap it in an assert, we will get confusing error messages.

For example, a failure in lgi/ffi.lua would look like:

attempt to index local 'gobject' (a boolean value)

wrapping gi.require with assert instead would show a more informative message:

Typelib file for namespace 'win32', version '1.0' not found

This change updates both lgi/class.lua and lgi/ffi.lua which appear to be the only two files in the codebase that do not wrap gi.require with an assert.

A practical example where this would have been useful is https://github.com/NixOS/nixpkgs/issues/139159#issuecomment-2156172046

I actually managed to figure out the issue with NixOS using this patch.

Thanks for developing and maintaining lgi!

psychon commented 5 months ago

Seems convincing enough. Thanks!

Thanks for developing and maintaining lgi!

Sorry for not doing either of that. :see_no_evil: