Skip to content

Commit

Permalink
Wrap gi.require with assert in class.lua and ffi.lua
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
stefano-m committed Jun 15, 2024
1 parent 700fcda commit 5233d83
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lgi/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local component = require 'lgi.component'
local record = require 'lgi.record'
local ffi = require 'lgi.ffi'
local ti = ffi.types
local GObject = gi.require 'GObject'
local GObject = assert(gi.require('GObject'))

-- Implementation of class and interface component loading.
local class = {
Expand Down
4 changes: 2 additions & 2 deletions lgi/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ local record = require 'lgi.record'

local ffi = {}

local gobject = gi.require('GObject')
local glib = gi.require('GLib')
local gobject = assert(gi.require('GObject'))
local glib = assert(gi.require('GLib'))

-- Gather all basic types. We have to 'steal' them from well-known
-- declarations, because girepository API does not allow synthesizing
Expand Down

0 comments on commit 5233d83

Please sign in to comment.