lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
436 stars 69 forks source link

Small issue in the cairo binding #162

Open fstirlitz opened 7 years ago

fstirlitz commented 7 years ago
>>> return tostring(require('lgi').cairo.PathData._field.header[3])
stdin:1: '__tostring' must return a string
stack traceback:
    [C]: in function 'tostring'
    stdin:1: in main chunk
    [C]: in ?
>>> return getmetatable(require('lgi').cairo.PathData._field.header[3]):__tostring()
nil

And similarly for cairo.PathData._field.point. I got this error by attempting to perform a recursive dump on _G; I'm not sure where else it may come up.

psychon commented 7 years ago

Looks like the third argument of component.create is supposed to be the name. According to git grep, there are many calls to that function with just two arguments (not just in cairo).

A possible fix (besides fixing all callers) might be:

diff --git a/lgi/component.lua b/lgi/component.lua
index a6803ae..d15a177 100644
--- a/lgi/component.lua
+++ b/lgi/component.lua
@@ -319,7 +319,7 @@ function component.create(info, mt, name)
    end

    -- Fill in meta of the compound.
-   local component = { _name = name }
+   local component = { _name = name or "__unnamed__" }
    if gtype then
       -- Bind component in repo, make the relation using GType.
       component._gtype = gtype

@fstirlitz What's your Lua version? My Lua 5.2 does not really complain here:

> return tostring(require('lgi').cairo.PathData._field.header[3])
nil

@pavouk I'll leave it up to you to fix this. I don't know if all callers should be fixed or the implementation should work around this issue (as in the above example patch). Also, no idea what good names for these things would be.

fstirlitz commented 7 years ago

I use Lua 5.3.

I'd rather use something that isn't a valid identifier instead of "__unnamed__" to avoid the usual problems with in-band signalling.