@@ -253,6 +253,26 @@ def gen(srcfiles, preprocessor_definitions):
253253 nsi = sorted (namespaces .items (), key = lambda x : x [0 ])
254254 added_methods = set ()
255255
256+ # Pre-populate the `enums` list across all namespaces so the per-namespace
257+ # `register_types` emission below can filter out enum typedefs. Without this,
258+ # enum return/arg types (e.g. cv::ORB::ScoreType) leak into `mod.add_type<...>`
259+ # in the generated C++ β but the Julia side declares them as `const X = Int64`
260+ # (not a wrapped type), so loading the .so trips CxxWrap's
261+ # "No appropriate factory for type ..." at @wrapmodule time.
262+ for _ , ns in nsi :
263+ for e1 , e2 in ns .enums .items ():
264+ # Push every form a type can appear in: hdr_parser normalizes arg
265+ # types via `::` -> `_` and strips `cv::` (see hdr_parser.parse_arg,
266+ # ~line 385), giving e.g. `ORB_ScoreType`. But parse_tree.py reads
267+ # `decl[4]` (the *original* return type) into self.rettype, so a
268+ # nested enum return reaches us as `ORB::ScoreType` (cv:: stripped,
269+ # `::` preserved). Cover both shapes β plus the fully-qualified
270+ # form β so `tp in enums` matches in every code path.
271+ enums .append (e2 [0 ]) # cv::ORB::ScoreType
272+ enums .append (e2 [1 ])
273+ enums .append (e2 [0 ].replace ("cv::" , "" )) # ORB::ScoreType
274+ enums .append (e2 [0 ].replace ("cv::" , "" ).replace ("::" , '_' )) # ORB_ScoreType
275+
256276 for name , ns in nsi :
257277 cpp_code .write ("using namespace %s;\n " % name .replace ("." , "::" ))
258278
@@ -299,14 +319,9 @@ def sort_classes(classes):
299319};
300320 """ % (cl .name .replace ('.' , '::' ), cl .base .replace ('.' , '::' )))
301321
302- for e1 ,e2 in ns .enums .items ():
303- # cpp_code.write('\n mod.add_bits<{0}>("{1}", jlcxx::julia_type("CppEnum"));'.format(e2[0], e2[1]))
304- enums .append (e2 [0 ])
305- enums .append (e2 [1 ])
306- enums .append (e2 [0 ].replace ("cv::" , "" ).replace ("::" , '_' ))
307-
308-
309322 for tp in ns .register_types :
323+ if tp in enums :
324+ continue # enum typedefs are passed as int64, not wrapped as types
310325 cpp_code .write (' mod.add_type<%s>("%s");\n ' % (tp , normalize_class_name (tp )))
311326
312327 # print(enums)
0 commit comments