Re: [Vala] [Genie] Problem with enums in genie

2010-09-28 Thread Nicolas

Hi,

Thanks you Jamie, i can access my enum !

I have a simple question about enum, why if i change 'value1 = 15' by 
'value1 = 15', valac does not return an error, only gcc (error: 
enumerator value for 'ENUM_TEST_value1' is not an integer constant)


[indent=4]

enum EnumTest
value1 = 15

init
print (%d, EnumTest.value1)

Thanks in advance,
Nicolas.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Two small new features

2010-09-28 Thread Julian Andres Klode
On Mo, 2010-09-27 at 02:55 +0200, Frederik Sdun wrote:
 * Jürg Billeter j...@bitron.ch [25.09.2010 18:22]:
  Hi Frederik,
  
  On Sat, 2010-09-25 at 17:20 +0200, Frederik Sdun wrote:
   i just pushed two little patches to [0] which allows to add an else
   statement to foreach and catch statements.
   For foreach, the else block is called if there is no iteration in the
   loop.
   For the catch clause, the else block is called if no exception was
   caught and before the finally statement.
   
   Here are 2 little examples:
   foreach:
   void print_array (string[] args) {
   foreach (var arg in args) {
   debug(@arg: $arg);
   } else {
   debug(no args); //called if the array is empty
   }
   }
   void main (string[] args)
   {
   string[] test_1 = new string[0];
   string[] test_2 = new string[2]{hello, world};
   print_array (test_1);
   print_array (test_2);
   }
  
  The `else` seems to indicate that the code in the else block is reached
  if the foreach is not successful. However, zero iterations are by no
  means an unusual condition. In general, I'd like to keep (control flow)
  statements relatively simple as, in my opinion, it's ok that the code
  gets more complex when the control flow is more complex. You don't want
  to hide complex control flow.
  
 This is just for convinience, for the not unusual case of:
 if (args.length  0)
 foreach(...)
 else
 ...
That would be confusing for people with Python background, as 'else' is
executed when the loop is exhausted; that is if there was no
return/break in the loop body.

Python documentation of 'for'
=
When the items are
exhausted (which is immediately when the sequence is empty), the suite
in the ``else`` clause, if present, is executed, and the loop
terminates.

A ``break`` statement executed in the first suite terminates the loop
without executing the ``else`` clause's suite.  A ``continue``
statement executed in the first suite skips the rest of the suite and
continues with the next item, or with the ``else`` clause if there was
no next item.

-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.


___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] this = Object

2010-09-28 Thread Cyrille Colin
hi,
i've just update to 0.10 from 0.8.1 and I guess now vala detect one of
my bad.
I used a init function to give my object pointer to external function
that will manage callback :

init(this)

init() is define in a vapi :
public static void init (ValaObj obj);

and use in External library like this :

static void *ValaObj;
void init (void *obj) {
ValaObj = obj;
}

Then i define in vapi the callback, C - Vala :
public delegate uint32 callback ( ValaObj, int value);

and this is my callback in Vala code:
public uint32 cb (ValaObj obj, int value) {
this = obj;
...
}
it works fine with 0.8.1 and throw exception with 0.10 :
error: unsupported lvalue in assignment
May someone could help me,
thanks in advance,
Cyrille.




___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] this = Object

2010-09-28 Thread Jiří Zárevúcky
Cyrille Colin píše v Út 28. 09. 2010 v 14:10 +0200:
 [...]
 and this is my callback in Vala code:
 public uint32 cb (ValaObj obj, int value) {
 this = obj;
 ...
 }
 it works fine with 0.8.1 and throw exception with 0.10 :
 error: unsupported lvalue in assignment
 May someone could help me,
 thanks in advance,
 Cyrille.
 

Can you tell us more about what exactly you are trying to achieve in
your code? As far as I can tell, this never made sense.



signature.asc
Description: This is a digitally signed message part
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] this = Object

2010-09-28 Thread Cyrille Colin
thanks for interest,
I have a singleton. It have a callback called by the lib_conntrack.
so when the conntrack receive something it call the callback function :
public uint32 cb (ValaObj obj-the singleton, int value) {
}
To keep the reference of my object(the singleton) i first give it with a
init(this-the singleton) function.
May be i need to mamage call in a static class ?
Cyrille. 


Le mardi 28 septembre 2010 à 15:09 +0200, Jiří Zárevúcky a écrit :
 Cyrille Colin píše v Út 28. 09. 2010 v 14:10 +0200:
  [...]
  and this is my callback in Vala code:
  public uint32 cb (ValaObj obj, int value) {
  this = obj;
  ...
  }
  it works fine with 0.8.1 and throw exception with 0.10 :
  error: unsupported lvalue in assignment
  May someone could help me,
  thanks in advance,
  Cyrille.
  
 
 Can you tell us more about what exactly you are trying to achieve in
 your code? As far as I can tell, this never made sense.
 


___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Two small new features

2010-09-28 Thread Fredderic Unpenstein
On 28 September 2010 21:19, Julian Andres Klode j...@jak-linux.org wrote:
 On Mo, 2010-09-27 at 02:55 +0200, Frederik Sdun wrote:
 This is just for convinience, for the not unusual case of:
 if (args.length  0)
     foreach(...)
 else
 ...

Personally I find myself, in almost every language, wrapping for(each)
statements in if (the list has items) ... else ..., which is exactly
what this feature addresses.  And, it's essentially saying exactly
what such a structure looks like; do this loop, else do this other
thing if the loop never happened (because there weren't any items).

Absolutely fantastic that a useful language has this!


 That would be confusing for people with Python background, as 'else' is
 executed when the loop is exhausted; that is if there was no
 return/break in the loop body.

That doesn't strike me as particularly useful, or as a particularly
good definition of else for that matter.  I'd consider that more of
a then situation, with else used because it's already a handy
reserved keyword that they couldn't think of a better use for.

Lets not punish Vala for Python's lack of good taste, though then as
in Python's for...else could be handy too.  ;)
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] this = Object

2010-09-28 Thread Jiří Zárevúcky
Cyrille Colin píše v Út 28. 09. 2010 v 16:24 +0200:
 thanks for interest,
 I have a singleton. It have a callback called by the lib_conntrack.
 so when the conntrack receive something it call the callback function :
 public uint32 cb (ValaObj obj-the singleton, int value) {
 }
 To keep the reference of my object(the singleton) i first give it with a
 init(this-the singleton) function.
 May be i need to mamage call in a static class ?
 Cyrille. 
 

I still don't get it. A code example would be nice. From what you say I
can't even tell what the problem or question is.



signature.asc
Description: This is a digitally signed message part
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] this = Object

2010-09-28 Thread Robert Powell
Hi Cyrille,

and this is my callback in Vala code:
 public uint32 cb (ValaObj obj, int value) {
this = obj;
 ...
 }
 it works fine with 0.8.1 and throw exception with 0.10 :
 error: unsupported lvalue in assignment
 May someone could help me,
 thanks in advance,
 Cyrille.

 I believe you are not allowed to assign to this.  Without seeing more
code, it is hard to tell what you are trying to do.  Why do you need to
assign this?  Why can't you just call public methods on obj?

Hope that helps,

Rob
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] this = Object

2010-09-28 Thread Jim Nelson
If you're trying to use a delegate from C, you need to be aware of the
delegate's target, which is a hidden parameter to Vala code but visible in
C.

If you compile your code with the --save-temps flag enabled, you can see how
a delegate is constructed in C.  For example:

delegate void Callback(int32 i);

Becomes this in the .c:

typedef void (*Callback) (gint32 i, void* user_data);

The user_data is the target (in Vala-parlance).  Your C code should invoke
the callback like this:

Callback _cb = cb;
...
_cb (i, obj);

Rob's right, you can't (or shouldn't) assign to this in Vala.  When you
invoke the callback with obj as the user_data, Vala's internal code will use
it as the this reference.

A useful reference if you're making a VAPI:
http://live.gnome.org/Vala/Bindings/MetadataFormat

-- Jim

On Tue, Sep 28, 2010 at 5:10 AM, Cyrille Colin co...@univ-metz.fr wrote:

 hi,
 i've just update to 0.10 from 0.8.1 and I guess now vala detect one of
 my bad.
 I used a init function to give my object pointer to external function
 that will manage callback :

init(this)

 init() is define in a vapi :
 public static void init (ValaObj obj);

 and use in External library like this :

 static void *ValaObj;
 void init (void *obj) {
ValaObj = obj;
 }

 Then i define in vapi the callback, C - Vala :
 public delegate uint32 callback ( ValaObj, int value);

 and this is my callback in Vala code:
 public uint32 cb (ValaObj obj, int value) {
this = obj;
 ...
 }
 it works fine with 0.8.1 and throw exception with 0.10 :
 error: unsupported lvalue in assignment
 May someone could help me,
 thanks in advance,
 Cyrille.




 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] this = Object

2010-09-28 Thread Cyrille Colin
hi,
even if it's weird, it worked. I'll try to write a piece of test case to
explain in vala better than in english ... :S
@robert : to call methods on object you need to know the method and the
object that's why I keep the reference to the object. When the method is
called it have to know the object it belows.
I'll write a case, i really want to know a good way to do this.
Cyrille.

Le mardi 28 septembre 2010 à 09:28 -0700, Robert Powell a écrit :
 Hi Cyrille,
 
 and this is my callback in Vala code:
 public uint32 cb (ValaObj obj, int value) {
this = obj;
 ...
 }
 it works fine with 0.8.1 and throw exception with 0.10 :
 error: unsupported lvalue in assignment
 May someone could help me,
 thanks in advance,
 Cyrille.
 
 I believe you are not allowed to assign to this.  Without seeing
 more code, it is hard to tell what you are trying to do.  Why do you
 need to assign this?  Why can't you just call public methods on obj?
 
 Hope that helps,
 
 Rob


___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] appsink binding in gstreamer

2010-09-28 Thread august


okay, I received some help from the IRC channel (thanks!) and here is
what I found:

To create the appsink object, you need to use the element factory and
cast it like this:

// not this.sink = AppSink()  like you would think.
this.sink = (AppSink)ElementFactory.make (appsink, sink);

then, you can set the signals like so:

this.sink.new_preroll.connect(this.new_preroll);
this.sink.new_buffer.connect(this.new_buf_cb);

my problem now  is how to deal with Gst.Buffers.  Sorry if my questions
are elementary.  I'm trying to learn vala, glib, gst all at once.  
In my signal callback for new_buffer, I do this:

private void new_buf_cb( ) {
print(new buffer.\n);
//Gst.Buffer.replace(ref buffer,this.sink.pull_buffer() );
buffer = this.sink.pull_buffer();
this.queue_draw();
}

Can someone tell my why the app crashes when trying to assign the
pull_buffer() to my Buffer buffer?

I also tried to call replace on the buffer, but it won't compile.

Any hints?

chugging along -august.


 
 I was talking with some folks about the faulty appsink bindings in
 gstreamer on IRC last night.
 
 I also found this online:
 http://www.mail-archive.com/vala-list@gnome.org/msg05147.html
 
 Any answers to those questions?
 
 It seems you can't even create the AppSink object.
 
 Is there another way to create it and set the signals using
 ElementFactory ?
 
 
 thanks -august.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Vala Tutorial Issue

2010-09-28 Thread Matt Harrison
In this code section of The Main Loop portion of the Vala tutorial.

void main() {var loop = new MainLoop();var time = new
TimeoutSource(2000);time.set_callback(() = {
stdout.printf(Time!\n);loop.quit();return false;
});time.attach(loop.get_context());loop.run();}

I get this Error when trying to compile:

warning: passing argument 4 of 'g_source_set_callback' from incompatible
pointer type
/usr/include/glib-2.0/glib/gmain.h:199: note: expected 'GDestroyNotify' but
argument is of type 'void (*)(struct Block1Data *)'

Is the tutorial incorrect here?
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Vala Tutorial Issue

2010-09-28 Thread JM
That is a typical warning for vala programs using closures. Looks like
correct.

 In this code section of The Main Loop portion of the Vala tutorial.
 
 void main() {var loop = new MainLoop();var time = new
 TimeoutSource(2000);time.set_callback(() = {
 stdout.printf(Time!\n);loop.quit();return false;
 });time.attach(loop.get_context());loop.run();}
 
 I get this Error when trying to compile:
 
 warning: passing argument 4 of 'g_source_set_callback' from incompatible
 pointer type
 /usr/include/glib-2.0/glib/gmain.h:199: note: expected 'GDestroyNotify' but
 argument is of type 'void (*)(struct Block1Data *)'
 
 Is the tutorial incorrect here?
 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list


___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Vala Tutorial Issue

2010-09-28 Thread Jiří Zárevúcky
Matt Harrison píše v Út 28. 09. 2010 v 16:56 -0400:
 I get this Error when trying to compile:
 
 warning: passing argument 4 of 'g_source_set_callback' from incompatible
 pointer type
 /usr/include/glib-2.0/glib/gmain.h:199: note: expected 'GDestroyNotify' but
 argument is of type 'void (*)(struct Block1Data *)'
 
 Is the tutorial incorrect here?

gcc warnings are common when compiling Vala generated code. For most
cases, the correct approach is to ignore them.



signature.asc
Description: This is a digitally signed message part
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list