[perl-Glib-Object-Introspection] Add Glib::Object::Introspection::GValueWrapper::get_value
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib-Object-Introspection] Add Glib::Object::Introspection::GValueWrapper::get_value
- Date: Mon, 24 Oct 2016 19:13:51 +0000 (UTC)
commit 8326a03eb50551b29de8657552ee6d133e799579
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Mon Oct 24 21:08:19 2016 +0200
Add Glib::Object::Introspection::GValueWrapper::get_value
To obtain the actual value of the wrapped GValue. This is necessary
when a functions expects an already set-up GValue and then modifies it
to return a value. Like Gtk3::Container::child_get_property.
GObjectIntrospection.xs | 10 ++++++++++
lib/Glib/Object/Introspection.pm | 13 +++++++++++--
t/values.t | 18 ++++++++++++++----
3 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index ef9b3e0..2361dc9 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -1039,6 +1039,16 @@ new (class, const gchar *type_package, SV *perl_value)
OUTPUT:
RETVAL
+SV *
+get_value (SV *sv)
+ PREINIT:
+ GValue *v;
+ CODE:
+ v = SvGValueWrapper (sv);
+ RETVAL = gperl_sv_from_value (v);
+ OUTPUT:
+ RETVAL
+
void
DESTROY (SV *sv)
PREINIT:
diff --git a/lib/Glib/Object/Introspection.pm b/lib/Glib/Object/Introspection.pm
index 2347277..4b6e61b 100644
--- a/lib/Glib/Object/Introspection.pm
+++ b/lib/Glib/Object/Introspection.pm
@@ -673,12 +673,21 @@ wrapper for a function that expects a GValue, do this:
...
my $type = ...; # somehow get the package name that
# corresponds to the correct GType
- my $real_value =
+ my $wrapper =
Glib::Object::Introspection::GValueWrapper->new ($type, $value);
# now use Glib::Object::Introspection->invoke and
- # substitute $real_value where you'd use $value
+ # substitute $wrapper where you'd use $value
...
+If you need to call a function that expects an already set-up GValue and
+modifies it, use C<get_value> on the wrapper afterwards to obtain the value.
+For example:
+
+ my $wrapper =
+ Glib::Object::Introspection::GValueWrapper->new ('Glib::Boolean', 0);
+ $box->child_get_property ($label, 'expand', $gvalue);
+ my $value = $gvalue->get_value
+
=head2 Handling extendable enumerations
If you need to handle extendable enumerations for which more than the
diff --git a/t/values.t b/t/values.t
index 36b813f..bb34369 100644
--- a/t/values.t
+++ b/t/values.t
@@ -5,10 +5,20 @@ BEGIN { require './t/inc/setup.pl' };
use strict;
use warnings;
-plan tests => 2;
+plan tests => 3;
-SKIP: {
- skip 'SV → GValue not implemented', 1;
- is (Regress::test_int_value_arg (23), 23);
+{
+ my $wrapper = Glib::Object::Introspection::GValueWrapper->new ('Glib::Int', 23);
+ is (Regress::test_int_value_arg ($wrapper), 23);
}
+
is (Regress::test_value_return (23), 23);
+
+SKIP: {
+ skip 'more GValue tests', 1
+ unless check_gi_version (1, 38, 0);
+
+ my $wrapper = Glib::Object::Introspection::GValueWrapper->new ('Glib::Int', 42);
+ GI::gvalue_in_with_modification ($wrapper);
+ is ($wrapper->get_value, 24);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]