Skip to content

Instantly share code, notes, and snippets.

@fracek
Created August 2, 2013 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fracek/6139414 to your computer and use it in GitHub Desktop.
Save fracek/6139414 to your computer and use it in GitHub Desktop.
define function g-value-to-dylan(instance :: <GValue>)
=> (dylan-instance);
let g-type = g-value-type(instance);
if(g-type ~= $G-TYPE-INVALID)
let dylan-type = find-gtype(g-type);
let address-thunk = curry(compose(pointer-address, g-value-peek-pointer),
instance);
if(dylan-type & subtype?(dylan-type, <GTypeInstance>))
make(dylan-type, address: address-thunk())
else
select(g-type)
$G-TYPE-NONE => #f;
$G-TYPE-CHAR => g-value-get-char(instance);
$G-TYPE-UCHAR => g-value-get-uchar(instance);
$G-TYPE-BOOLEAN => (g-value-get-boolean(instance) = 1);
$G-TYPE-INT => g-value-get-int(instance);
$G-TYPE-UINT => g-value-get-uint(instance);
$G-TYPE-LONG => g-value-get-long(instance);
$G-TYPE-ULONG => g-value-get-ulong(instance);
$G-TYPE-INT64 => g-value-get-int64(instance);
$G-TYPE-UINT64 => g-value-get-uint64(instance);
$G-TYPE-ENUM => error("Can't handle $G-TYPE-ENUM yet.");
$G-TYPE-FLAGS => error("Can't handle $G-TYPE-FLAGS yet.");
$G-TYPE-FLOAT => g-value-get-float(instance);
$G-TYPE-DOUBLE => g-value-get-double(instance);
$G-TYPE-STRING => g-value-get-string(instance);
$G-TYPE-POINTER => g-value-get-pointer(instance);
$G-TYPE-BOXED => #f;
$G-TYPE-PARAM => #f;
$G-TYPE-OBJECT => #f;
gdk-event-get-type()
=> make-gdk-event(address-thunk());
gtk-tree-iter-get-type()
=> make(<GtkTreeIter>, address: address-thunk());
gtk-tree-path-get-type()
=> make(<GtkTreePath>, address: address-thunk());
otherwise => error("Unknown Gtype %=", g-type);
end select;
end if;
end if;
end function g-value-to-dylan;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment