lubyk / dub

A Lua bindings generator that uses Doxygen to parse C/C++ headers.
doc.lubyk.org/dub.html
Other
82 stars 34 forks source link

error occurred while generating binding for opencv #9

Closed seanlis closed 9 years ago

seanlis commented 9 years ago

hi,

I got the following error when trying to generate a binding for opencv:

lua: /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:727: attempt to index a nil value (field 'ctype')
stack traceback:
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:727: in local 'func'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:635: in local 'func'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:489: in field 'children'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:607: in local 'func'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:489: in field 'children'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:470: in field 'header'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:406: in field 'parseAll'
    /home/sean/.luarocks/share/lua/5.3/dub/MemoryStorage.lua:61: in function 'dub.MemoryStorage.parse'
    /home/sean/.luarocks/share/lua/5.3/dub/Inspector.lua:68: in field 'parseXml'
    /home/sean/.luarocks/share/lua/5.3/dub/Inspector.lua:121: in field 'parse'
    /home/sean/.luarocks/share/lua/5.3/dub/Inspector.lua:32: in function 'dub.Inspector.new'
    (...tail calls...)
    opencv.lua:7: in main chunk
    [C]: in ?

Here is what I did.

I was using Arch linux and opencv 2.4.10-3. First I copied the include file to the working directory:

[sean@ArchHp dubgenerators]$ cp /usr/include/opencv2/ include/ -r

then run the following script opencv.lua:

package.path='/home/sean/.luarocks/share/lua/5.3/?.lua;/home/sean/.luarocks/share/lua/5.3/?/init.lua;/usr/share/lua/5.3/?.lua;/usr/share/lua/5.3/?/init.lua;/usr/lib/lua/5.3/?.lua;/usr/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua'
package.cpath='/home/sean/.luarocks/lib/lua/5.3/?.so;/usr/lib/lua/5.3/?.so;/usr/lib/lua/5.3/loadall.so;./?.so'

local lub = require 'lub'
local dub = require 'dub'

local inspector = dub.Inspector {
  INPUT    = {
    lub.path '|include/opencv2',
    lub.path '|include/opencv2/core',
  },
}

local binder = dub.LuaBinder()

binder:bind(inspector, {
  -- Mandatory library name. This is used as prefix for class types.
  lib_name = 'cv',

  output_directory = lub.path '|src/bind',

  -- Remove this part in included headers
  header_base = lub.path '|include',

  -- Open the library with require 'xml.core' (not 'xml') because
  -- we want to add some more Lua methods inside 'xml.lua'.
  luaopen    = 'cv_core',
})

./dub-tmp/xml had been generated with some xml files under it. Then I got the error.

Is there anything wrong I did in this process?

gaspard commented 9 years ago

OpenCV is a very complex C++ library with lots of legacy functions. Binding it all at once like this seems difficult and possibly error prone (memory management, etc).

For such a big library, what I would do is define what I need (classes, functions) and try to bind just these elements.

Dub should output a warning if the ctype is not found instead of crashing. I'll fix this in a new version...

In any case, there is this project which provides some bindings http://sourceforge.net/projects/luacv/.

gaspard commented 9 years ago

Released 2.2.3 which should at least display an error with the file/line concerned by the failing ctype resolution.

seanlis commented 9 years ago

OK. Thank you for the suggestion.

Gaspard Bucher (bumagy) notifications@github.com于2015年6月26日周五 下午4:58写道:

OpenCV is a very complex C++ library with lots of legacy functions. Binding it all at once like this seems difficult and possibly error prone (memory management, etc).

For such a big library, what I would do is define what I need (classes, functions) and try to bind just these elements.

Dub should output a warning if the ctype is not found instead of crashing. I'll fix this in a new version...

In any case, there is this project which provides some bindings http://sourceforge.net/projects/luacv/.

— Reply to this email directly or view it on GitHub https://github.com/lubyk/dub/issues/9#issuecomment-115586000.