You might just be right, swig is a well tested and used tool and might have proven much better to write the bindings then creating yet another tool. My approach has the benefit that it encourages in code documentation and that generating new bindings takes 5 minutes but that may not be enough to justify the creation and maintenance of another binder. The python bindings for OpenCV are made with swig on the C interface and although the new C++ API for opencv has been around for some time, it is taking time to migrate and that does not seem like SWIG is an agile tool. Finally, the code generated by SWIG is quite unreadable and uses tons of ugly constructs (goto, static_cast ?), but that may be because Python is not as easy to interface as Lua even though I doubt it.
Just as an example, I wanted to catch cv::Exceptions to produce good error messages in Lua. To do this I adapted a single template:
<%= comment(@function) %>
<%= signature(@function) %> {
try {
<%= indent(body(@function), 4) %>
} catch (cv::Exception &e) {
std::string *s = new std::string("<%= @function.id_name %>: failed (");
s->append(e.err);
s->append(")");
lua_pushstring(L, s->c_str());
delete s;
lua_error(L);
// never reached
return 0;
} catch (std::exception &e) {
std::string *s = new std::string("<%= @function.id_name %>: ");
s->append(e.what());
lua_pushstring(L, s->c_str());
delete s;
lua_error(L);
// never reached
return 0;
} catch (...) {
lua_pushstring(L, "<%= @function.id_name %>: Unknown exception");
lua_error(L);
return 0;
}
}
This kind of templates (and the generated code) is very easy to maintain. From my point of view, SWIG is a good old 14 years old grandfather that got a little senile over the years ;-). I don't pretend Dub is better (it surely is more buggy), but it lets me work in ways I understand (well documented intermediate models with good introspection capabilities), test-driven development. In fact, if swig was so cool, the Lua bindings for OpenCV would be here for ages and the Python stuff would be totally up to date (and there would not be 3 versions of these bindings).
But maybe my view on swig is too biased and I'm just too stupid to adapt (sincerely).