From: Lyle Johnson Date: 2002-06-14T23:53:26+09:00 Subject: Re: SWIG: returning a bool reference or pointer to Ruby > Can someone clarify how this is supposed to work? For what it's worth, I had answered Phil privately on this question before I saw that he'd asked here also. The basic answer is to use a combination of "argout" and "ignore" typemaps to tell SWIG that those arguments should be wrapped as output values. > BTW: I checked the typemaps.i file for Ruby and found no mappings from > bool* to Ruby's TrueClass or FalseClass, so maybe that's the problem, but > I'm not sure how to achieve this mapping. I suspect this would be a lot > easier if Ruby had a Bool type that could be either true or false. I > think it's been mentioned before, but it does seem a bit awkward that a > variable set to true is of type TrueClass and a variable set to false is > of FalseClass. > > So how would one go about mapping from a bool on the C side to either a > true or false on the Ruby side and visa-versa? Actually, for the most part this is already covered automatically by SWIG. You just managed to hit on a special case that wasn't covered automatically (recognizing boolean values that are output by reference in C++). In SWIG 1.3.12, you can already use the bool type in most situations, e.g. for these declarations: void func_taking_a_bool_input(bool in); bool func_returning_a_bool_result(); you'd end up with Ruby functions that accept (or return) Ruby true and false values.