I just on internet the Go开发者_开发技巧ogle is using swig.
Does any one have used that and tell me will it be helpful for me.
I mean why it is used and how it can make my work good.
As google is using it must be good
Just because someone uses something does not make it good. That being said I love my Swig.
I've used it to wrap C++ libraries in Java and Python. It lets me write code once and still use that code in other languages. It translates the API in a meaningful and consistent manner, which is something not to be underestimated. In short, it makes life easier for those of us who have to work in multiple languages with multiple libraries at the same time.
SWIG generates the "glue code" needed when a program written in one language needs to call a program written in another. SWIG operates on the assumption that C/C++ is a kind of lowest common denominator, and if you want to connect, say, Python and Java, you will have to pass all information through C. SWIG is very ambitious and covers a large number of scripting languages, basically providing import/export to C or C++.
Exactly how you use SWIG varies by scripting language, but the general idea is always the same: you describe some C/C++ header file, and SWIG generates the glue code needed to use that header file from your favorite scripting language. Connecting two scripting languages together does not fit the common use case, and I'd be surprised if you didn't run into trouble. A good plan would be to exchange only immutable data between two languages. Even then, I'd prepare for surprises.
Summary: SWIG works well enough at what it's designed for, which is to export C/C++ libraries to a huge variety of scripting languages—but one at a time. Having two different scripting languages running in the same process image may be harder than you expect.
精彩评论