문제

What I understood from the documentation is that what is between %{ %} is inserted into the wrapper, what about %inline %{ %} ?

Is it the same? If it is not, what are the differences?

Maybe we can find many occurences of %inline %{ %} but only one occurence of %{ %}? Thank you a lot!

도움이 되었습니까?

해결책

You can have any number of occurrences of either types of block. The %{ ... }% just inserts what is in the block verbatim in the file generated by SWIG. It is used so that the generated file will compile, i.e. you normally put there whatever includes and defines and such that are required in order to get the generated file to compile.

OTOH, From the docs:

The %inline directive inserts all of the code that follows verbatim into the header portion of an interface file. The code is then parsed by both the SWIG preprocessor and parser.

So the %inline %{ ... %} does two things rather: it puts the declaration in the generated wrapper file, AND it causes SWIG to generate the wrapper code so that functions etc in the block can be called from the target language (Python, Lua, whatever). This is not the case for %{ ... }%: code in such block does not get wrapped, just gets dumped verbatim in the generated wrapper file.

Don't be afraid to open up the *_wrap.cpp that SWIG generates: put some easily searchable code in the two types of blocks and look at where they end up in the wrapper file, and what additional code got generated.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top