Skip to content

Commit

Permalink
Merge pull request #176 from mcorino/develop
Browse files Browse the repository at this point in the history
Fix some missing type mappings
  • Loading branch information
mcorino authored Sep 18, 2023
2 parents e62ffe2 + 0aac22c commit 3ea0cf8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
11 changes: 6 additions & 5 deletions rakelib/lib/core/mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,19 @@ def initialize(map, temp: nil, code: nil, &block)
end

class ArgOut < Base
def initialize(map, as: nil, temp: nil, code: nil, &block)
def initialize(map, as: nil, by_ref: false, temp: nil, code: nil, &block)
super(map, temp: nil, code: code)
@as = {}
if as
map_as(as)
elsif !map.types.empty?
map.types.each_pair { |pset, type| @as[pset] = _get_mapped_type(type) }
end
@by_ref = by_ref
block.call(self) if block
end

attr_reader :as
attr_reader :as, :by_ref

def map_as(argdef)
_map_args(argdef, @as)
Expand Down Expand Up @@ -434,8 +435,8 @@ def map_freearg(temp: nil, code: nil, &block)
@check = FreeArg.new(self, temp: temp, code: code, &block)
end

def map_argout(as: nil, temp: nil, code: nil, &block)
@argout = ArgOut.new(self, as: as, temp: temp, code: code, &block)
def map_argout(as: nil, by_ref: false, temp: nil, code: nil, &block)
@argout = ArgOut.new(self, as: as, by_ref: by_ref, temp: temp, code: code, &block)
end

def map_directorin(temp: nil, code: nil, &block)
Expand Down Expand Up @@ -541,7 +542,7 @@ def ignores_input?
end

def maps_input_as_output?
!!@argout
@argout && !@argout.by_ref
end

def ignores_output?
Expand Down
12 changes: 12 additions & 0 deletions rakelib/lib/director/graphics_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ def setup
}
__CODE
end
# for GetPartialTextExtents
spec.map 'wxArrayDouble &widths' => 'Array<Float>' do
map_in ignore: true, temp: 'wxArrayDouble tmp', code: '$1 = &tmp;'

map_argout code: <<~__CODE
$result = rb_ary_new();
for (size_t i = 0; i < $1->GetCount(); i++)
{
rb_ary_push($result,DBL2NUM( $1->Item(i) ) );
}
__CODE
end
# add convenience method providing efficient gc memory management
spec.add_extend_code 'wxGraphicsContext', <<~__HEREDOC
static VALUE draw_on(wxWindow* win)
Expand Down
29 changes: 29 additions & 0 deletions rakelib/lib/director/pgproperty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ def setup
return (*self)[idx];
}
__HEREDOC
# for GetIndicesForStrings
spec.map 'wxArrayString *unmatched' => 'Array,nil' do

map_in temp: 'wxArrayString tmp, VALUE rb_unmatched', code: <<~__CODE
rb_unmatched = $input;
if (!NIL_P(rb_unmatched))
{
if (TYPE(rb_unmatched) == T_ARRAY)
{
$1 = &tmp;
}
else
{
SWIG_exception_fail(SWIG_TypeError, Ruby_Format_TypeError( "", "Array", "GetIndicesForStrings", $argnum, $input ));
}
}
__CODE

map_argout by_ref: true, code: <<~__CODE
if (!NIL_P(rb_unmatched$argnum))
{
for (size_t i = 0; i < $1->GetCount(); i++)
{
rb_ary_push(rb_unmatched$argnum,WXSTR_TO_RSTR( $1->Item(i) ) );
}
}
__CODE

end
spec.disown 'wxPGProperty *prop', 'wxPGProperty *childProperty'
# do not think this useful for wxRuby (Also; caused GC problems)
spec.ignore 'wxPGProperty::GetCellRenderer'
Expand Down
29 changes: 29 additions & 0 deletions rakelib/lib/director/richtext_buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ def setup
%set_constant("$symname", rb_str_new2((const char *)wxString($value).utf8_str()));
}
__HEREDOC
# for GetExtWildcard
spec.map 'wxArrayInt* types' => 'Array,nil' do

map_in temp: 'wxArrayInt tmp, VALUE rb_types', code: <<~__CODE
rb_types = $input;
if (!NIL_P(rb_types))
{
if (TYPE(rb_types) == T_ARRAY)
{
$1 = &tmp;
}
else
{
SWIG_exception_fail(SWIG_TypeError, Ruby_Format_TypeError( "", "Array","wxRichTextBuffer::GetExtWildcard", $argnum, $input ));
}
}
__CODE

map_argout by_ref: true, code: <<~__CODE
if (!NIL_P(rb_types$argnum))
{
for (size_t i = 0; i < $1->GetCount(); i++)
{
rb_ary_push(rb_types$argnum,INT2NUM( $1->Item(i) ) );
}
}
__CODE

end
spec.do_not_generate(:functions)
super
end
Expand Down

0 comments on commit 3ea0cf8

Please sign in to comment.