Gtk toArray List funkiness
Mike Wey via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 16 20:54:21 UTC 2017
On 16-09-17 20:58, Joseph wrote:
>
> https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d
>
>
> has the code
>
> foreach ( int i, string selection ; fs.getSelections())
> {
> Â writeln("File(s) selected [%d] %s",i,selection);
> }
>
> which is invalid for the demo, but
>
> foreach ( int i, string selection ; fd.getFilenames().toArray!(string,?))
> {
> Â writeln("File(s) selected [%d] %s",i,selection);
> }
>
> results in some funky code. Gives errors in ObjectG about uint when
> setting ? to string, string* or void* or even uint:
>
> GtkD\generated\gtkd\gobject\ObjectG.d(172): Error: incompatible types
> for ((obj) is (null)): 'uint' and 'typeof(null)'
> GtkD\generated\gtkd\glib\ListSG.d(98): Error: template instance
> gobject.ObjectG.ObjectG.getDObject!(string, string, uint) error
> instantiating
> test.d(91):Â Â Â Â Â Â Â instantiated from here: toArray!(string, uint)
> test.d(93): Error: invalid foreach aggregate `fd.getFilenames()`, define
> opApply(), range primitives, or use .tupleof
>
> without specifying ? it assumes it's a tuple, which seems wrong?
>
>
>
> Â Â Â Â public T[] toArray(T, TC = typeof(T.tupleof[0]))()
> Â Â Â Â {
> Â Â Â Â Â Â Â T[] arr = new T[length()];
> Â Â Â Â Â Â Â ListSG list = this;
> Â Â Â Â Â Â Â size_t count;
>
> Â Â Â Â Â Â Â while(list !is null && count < arr.length)
> Â Â Â Â Â Â Â {
> Â Â Â Â Â Â Â Â Â Â Â arr[count] = ObjectG.getDObject!(T)(cast(TC)list.data);
> Â Â Â Â Â Â Â Â Â Â Â list = list.next();
> Â Â Â Â Â Â Â Â Â Â Â count++;
> Â Â Â Â Â Â Â }
>
> Â Â Â Â Â Â Â return arr;
> Â Â Â Â }
>
>
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â foreach ( int i, Value
> selection ; fd.getFilenames().toArray!(Value)())
> {
> Â writeln("File(s) selected [%d] %s",i,selection.getString);
> }
>
> crashes ;/
>
> I'm not sure what types are what and it changes depending on the input.
> I think Value is the wrong type to use but string doesn't work so...
ListG and ListSG are missing an toArray overload for string. And
getFilenames returns a list of strings.
I've added a string overload for toArray:
https://github.com/gtkd-developers/GtkD/commit/ba20490b38e502a4d281226572c83c662a700858
--
Mike Wey
More information about the Digitalmars-d-learn
mailing list