Feature Requests: Browse | Submit New | Admin

[#29306] Tweak SWIG to match Ruby's notion of truth

Date:
2011-07-06 20:22
Priority:
3
Submitted By:
Ryan Hinton (iobass)
Assigned To:
Alex Fenton (brokentoy)
Category:
API improvement
State:
Open
Summary:
Tweak SWIG to match Ruby's notion of truth

Detailed description
Original email follows, see <http://rubyforge.org/pipermail/wxruby-users/2011-July/005901.html>.  Alex Fenton's
follow-up has a brief description of ways to solve the problm.  I favor fiddling with SWIG to translate Ruby return
values to C++ booleans in the expected way.

I'm working on enabling/disabling controls, and I keep getting
exceptions like the following:

mysource.rb:262:in `enable': Expected argument 1 of type bool, but got
NilClass nil (TypeError)
        in SWIG method 'Enable'
        from mysource.rb:262
        from
C:/Ruby187/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mingw32/lib/wx/classe
s/app.rb:16:in `call'
        from
C:/Ruby187/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mingw32/lib/wx/classe
s/app.rb:16:in `process_event'
        from
C:/Ruby187/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mingw32/lib/wx/classe
s/app.rb:16:in `on_run'
        from
C:/Ruby187/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mingw32/lib/wx/classe
s/app.rb:16:in `main_loop'
        from
C:/Ruby187/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mingw32/lib/wx/classe
s/app.rb:16:in `run'
        from app.rb:188

Is there an (easy) way to help WxRuby follow Ruby's notion of truth,
i.e. everything but +nil+ and +false+ are true?

The current best workaround I have is 

  enable(... ? true : false)

but that's clunky, and I obviously keep forgetting to use it.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2011-07-07 10:24
Sender: Alex Fenton

Not something we should add to a stable version, but in favour
of this. Think it needs three typemaps in swig/typemap.i, something
like

%typemap(in) bool "$1 = ( ! ( NIL_P($input) || $input ==
Qtrue) );"
# And similar for %typemap(directorout)

# Accept any ruby object as input for bool
%typemap(typecheck) bool ""

Have forgotten the Ruby C API - there is surely a standard way
to implement Ruby's not-nil-or-false notion of truth better than
above...

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item