Re: [Vala] C# developer, newbie question

2018-12-19 Thread Andy Lees via vala-list
I believe it's because the string produced in your first assignment to
strState is the C transformed enum value which concatenates the type and
value with an "_".  It does this to map the nested name space of Vala enums
into the flat C name space.  You would need to remove the type + "_" from
the returned string to create the associated enum value.

On Wed, Dec 19, 2018 at 10:28 PM Wolfgang Mauer 
wrote:

> Hi all,
> i try to put a enum to string and back, with no success.
>
> var strState = get_window().get_state().to_string(); <--
> "GDK_WINDOW_STATE_FOCUSED"
>
> and back dont work
>
> EnumClass enumc = (EnumClass)typeof(Gdk.WindowState).class_ref ();
> var state = (Gdk.WindowState)enumc.get_value_by_name(strState).value;
>
> What im doing wrong?
>
> Thanks for help
>
> Wolfgang
>
>
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Newbie need help

2018-09-30 Thread Andy Lees via vala-list
I find Anjuta to be usable, good for setting up projects and ok for
debugging (you have to have some understanding of the Gobject structure to
use it though, and "this." is "self->"). Anjuta ctags understands Vala, so
go to declaration works, etc. Symbol completion is pretty good, and
generally understands the context of the completion.

Mostly however, I use Sublime Text with the Vala package installed (Vala
and Vala-TMBundle - not sure if the second helps, but I've had it installed
from way back).  Install the ctags package and make sure to set up ctags to
use anjuta-ctags.  Here are my ctags settings:
{
  "debug": true,
  "autocomplete": true,
  "opts" : ["-V", "--languages=Vala", "--exclude='Make*'",
"--exclude='Optimized/*'", "--exclude='Debug/*'"],
  "command": "/usr/bin/anjuta-tags"
}

Mostly I set up projects using Anjuta, and then use autogen.sh with
suitable CTAGS options to regenerate the project, "make" to make it and gdb
for debugging.  In gdb ^X^A and ^XA are very useful keystrokes for going in
to/out of visual mode. My gdb settings are:

set print pretty on
set confirm off
set height 0
set width 0
set history save on

def cl
  if $argc == 0
tbreak +1
continue
  else
tb $arg0
continue
  end
end

def jb
  if $argc == 1
tbreak $arg0
jump $arg0
  end
end

def fatalc
  set environment G_DEBUG = fatal-criticals
end

I have found Vala/glib and associated libraries to be a highly productive
development tool, better than C++ in general despite a few peculiarities.
It has simpler semantics more suitable for my typical work.  It does take a
bit of getting used to, but I hope you'll find it worthwhile.

Good Luck!

On Mon, Oct 1, 2018 at 8:13 AM Wolfgang Mauer 
wrote:

> Well, for beginner's like me, I think auto-completion is very important and
> a "must"
>
> Wolfgang
>
> -Ursprüngliche Nachricht-
> Von: Vivien Kraus 
> Gesendet: Montag, 1. Oktober 2018 00:03
> An: Wolfgang Mauer 
> Cc: vala-list@gnome.org
> Betreff: Re: [Vala] Newbie need help
>
>
> Wolfgang Mauer writes:
>
> Hello,
>
> > Hi all,
> > I'm a C# developer (MS/MONO) and like to try vala.
> > I'm wondering there is not a really useful IDE?!
> >
> > Current i use Monodevelop/VS2017 to develop C# programs and debug my
> > application.
> > This is very comfortable for writing and debugging.
> >
> > I tried glade-builder and anjuta, but both are not really usable.
> >
> > Does that mean that vala-dvelopers must use command-line tools? (Back
> > to the 80's ;-))
>
> I like to use a text editor, but if you want an IDE then it seems that
> GNOME
> builder is the way to go: https://wiki.gnome.org/Apps/Builder
>
> Vivien
> >
> > Please give me a hand if there are some useful IDE's.
> >
> > /
> > Wolfgang
> >
> > ___
> > vala-list mailing list
> > vala-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/vala-list
>
>
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Catch divide by zero

2016-12-03 Thread Andy Lees
Is there a simple way to catch and propagate a divide by zero error in
Vala?  In C I can use a setjmp to define a catch point, and then do a
suitable jongjmp from a signal handler.  However this mechanism doesn't
appear to be available to the Vala programmer, so what can be done?

Regards,

Andrew Lees.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Socket source

2016-09-29 Thread Andy Lees
Hi,

After 0.30, the socket create source function changed from returning a
SocketSource to returning a GLib.Source.  Now, for the correct operation of
the socket callback, the returned object must be a SocketSource, so:

   - Is the implementation still the same, and presumably if so it is safe
   to do a hard cast to a SocketSource on the return object?  That appears to
   be the only option given that SocketSource is a compact class.
   - Why was the change to the return type from socket create_source made?

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Array as big as an enum

2016-08-31 Thread Andy Lees
You can access them as strings: Foo.ELEMENT.to_string() (or any Foo-typed
expression).  The default result may be a bit clunky, but very useful
nevertheless.  Add you own to_string if you want to get fancy.

On Thu, Sep 1, 2016 at 3:51 AM, rastersoft  wrote:

> El 31/08/16 a las 17:20, Al Thomas escribió:
> > - Original Message -
> >
> >> From: Evan Nemerson 
> >> Sent: Tuesday, 30 August 2016, 17:11
> >> Subject: Re: [Vala] Array as big as an enum
> >>
> >> On Mon, 2016-08-29 at 23:47 +0200, rastersoft wrote:
> >>>  Sorry, I found how to do that:
> >>>
> >>>  int[] blah = new int[LAST_ELEMENT];
> >> If you want to avoid having a LAST_ELEMENT value, something like this
> >> will also work:
> >>
> >> ((GLib.EnumClass) typeof(Foo).class_ref ()).n_values
> >>
> >> I'm not necessarily advocating it, but if you really want to keep your
> >> API clean it's an option.
> >>
> >
> > This gets the GType of Foo, instantiates it by increasing the ref count,
> > casts it to EnumClass and then uses the n_values field.
> >
> > If someone was to add syntax support for this for both EnumClass and
> > FlagsClass, what would be the best way for this to look?
> >
> > a) Explicit instantiation of the Foo EnumClass:
> >
> > var a = new Foo ();
> > print ("%i", a.n_values);
> >
> > b) Implicit access to EnumClass methods and fields:
> > print ("%i", Foo.v_values);
> >
>
> The B one sounds better, I think. Even more: it would be great to be
> able to access to the enums as strings too.
>
> --
> Nos leemos
>  RASTER(Linux user #228804)
> ras...@rastersoft.com  http://www.rastersoft.com
>
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Trap for the unwary or incorrect code?

2016-05-21 Thread Andy Lees
Ah yes, my bad, my original code had the unsigned operand as explicitly 32
bits, which I had expected to up-cast to int.  But in fact ints aren't
wider even with a 64 bit architecture.  Strict type checking as an option
for all type in all uses would be a helpful bug squishing tool.

On Sun, May 22, 2016 at 12:56 AM, Al Thomas <astav...@yahoo.co.uk> wrote:

>
>
>
>
> - Original Message -
> > From: Andy Lees <andrewl...@gmail.com>
> > Sent: Saturday, 21 May 2016, 14:56
> > Subject: [Vala] Trap for the unwary or incorrect code?
> >
> > If I have the following code, or similar:
> > void main (string[] args) {
> >   uint ui = 2;
> >   int i = -3;
> >   if (i < ui) {
> > stdout.printf("Comparison works\n");
> >   }
> > }
> >
> > No output is produced.  Given Vala is generally very good at warning
> about
> > type mismatches, or correctly doing an implicit cast, I find this rather
> > strange.  Yes, I should not be comparing a negative value against an
> > unsigned value, but logically the comparison should produce the expected
>
> > output, I would have thought?
> > > In general, as type inference can make the type of a variable unclear
> to
> > the casual viewer, and the declaration of a variable may be in a
> different
> > file, this permissiveness is a potential source of error, I think.
>
>
>
> At present I would say this is a trap for the unwary, although a
>
> --strict-value-type mode for Vala may be helpful. This is a well known
> problem
> in the C world.
>
> In Vala the spec for relational arithmetic operators says "Where both
> operands
>
> are of integer type, both are converted to the largest integer type
> involved"
>
> https://wiki.gnome.org/Projects/Vala/Manual/Expressions#Relational_operations
> Presumably that means the largest value rather than range of values.
>
> You will also find this with arithmetic operations, e.g.
>
>
> http://stackoverflow.com/questions/35305625/vala-quotient-of-two-integers-is-always-an-integer-why
>
> In C this type of behaviour is labelled the "usual arithmetic conversions"
> if
> you want to do a search. Some examples showing what you have found:
>
> https://www.securecoding.cert.org/confluence/display/c/INT02-C.+Understand+integer+conversion+rules
>
> http://www.iesensor.com/blog/2012/10/21/unsigned-integer-can-be-evil-c-implicit-conversion/
>
> Al
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Trap for the unwary or incorrect code?

2016-05-21 Thread Andy Lees
Hi gentlemen,

If I have the following code, or similar:
void main (string[] args) {
  uint ui = 2;
  int i = -3;
  if (i < ui) {
stdout.printf("Comparison works\n");
  }
}

No output is produced.  Given Vala is generally very good at warning about
type mismatches, or correctly doing an implicit cast, I find this rather
strange.  Yes, I should not be comparing a negative value against an
unsigned value, but logically the comparison should produce the expected
output, I would have thought?  Also, I note that I can assign a value of -2
to ui without any complaint.

In general, as type inference can make the type of a variable unclear to
the casual viewer, and the declaration of a variable may be in a different
file, this permissiveness is a potential source of error, I think.

Regards,

Andrew Lees.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any usable editor for Vala?

2016-05-17 Thread Andy Lees
Have you done Find->ctags->rebuild tags?

On Wed, May 18, 2016 at 1:19 AM, Ralph Plawetzki <ra...@purejava.org> wrote:

> Dear list,
>
> Am 14.02.2016 um 13:02 schrieb Andy Lees:
> > haven't tried it.  Make sure you set the ctags executable to use
> > anjuta-ctags (installed with Anjuta), which understands vala code and
> > generates suitable tags files.
>
> I am on Arch linux 64bit, so do have a current stack installed.
> In sublime 2 the CTags plugin is installed and configured with:
> // Path to ctags executable.
> ...
> "command": "/usr/bin/anjuta-tags",
>
> When I use Navigate to Definition via right click in a vala file of a
> cloned project, sublime allways comes back with Can't find any relevant
> tags file.
>
> How can this be solved - what else needs to be configured?
>
> Thanks,
> Ralph
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Problem with programmatic generic object instantiation

2016-02-16 Thread Andy Lees
So this is what I now have:

namespace ObjectFactory {

  [CCode (has_target = false)]
  public delegate Object Maker();

  Gee.HashMap<Type,Maker> construct_map;

  public  void add_maker(Type for_type, Maker maker) {
if (construct_map == null) {
  construct_map = new Gee.HashMap<Type,Maker>();
}
construct_map[for_type] = maker;
  }

  public  Object? make(Type one_of_these) {
if (construct_map != null && construct_map.has_key (one_of_these)) {
  Maker m = construct_map[one_of_these];
  return m ();
}
return null;
  }

}

and then in each instantiation:

public class IntArr : GArrSerializable {

  class construct {
ObjectFactory.add_maker(typeof (IntArr), () => { return new IntArr ();
});
  }

  public IntArr(int size = 0) {
base (size);
  }
}

then I use ObjectFactory.make (type) in my deserialization procedure, and
it appears to work ok at last.

On Wed, Feb 17, 2016 at 10:26 AM, Andy Lees <andrewl...@gmail.com> wrote:

> Momentarily I thought that might work, but it does match the Json
> serialization structure - the context of deserializing an array does not
> provide the initialised array, the deserialization procedure has to do the
> creation, and only has the type id to work with.  It looks like I'll have
> to create an object factory of my own for this, as I don't want to get into
> the internals of Json glib.
>
> On Wed, Feb 17, 2016 at 10:09 AM, Daniel Espinosa <eso...@gmail.com>
> wrote:
>
>> I run in the same issue for GXml and SerializableListArray<>, for example.
>>
>> The way I resolve, in my case, I've defined a new Interface called
>> SerializableCollection, with a init() function. This function is called by
>> Serializable.deserialize() method in order to help implementators to
>> initialize its generic containers by calling MyObjectCollection.new()
>> providing any information it needs like the Generic Type it should work on.
>>
>> In my other project, I've just initialize any public property as
>>
>> MyProperty prop { get; set; default = new MyProperty(); }
>>
>> or inside construct {}
>>
>> The point is to call MyProperty.new() not Object.new() on generic classes.
>>
>>
>> 2016-02-16 16:59 GMT-06:00 Andy Lees <andrewl...@gmail.com>:
>>
>>> Yes, the problem is that for types derived from generics (and for the
>>> generic constructor itself), the type information is not set in the
>>> construct function, so very little can be done.
>>>
>>> On Wed, Feb 17, 2016 at 9:53 AM, Daniel Espinosa <eso...@gmail.com>
>>> wrote:
>>>
>>>> If you want to execute code on Object creation using Object.new(), you
>>>> should use
>>>>
>>>> construct {
>>>>   // Your code here
>>>> }
>>>>
>>>> When define code at MyObject.new(), you execute the code in this method
>>>> not Object.new(), then use the above should help.
>>>>
>>>>
>>>> 2016-02-16 15:58 GMT-06:00 Andy Lees <andrewl...@gmail.com>:
>>>>
>>>>> The problem with Object.new is that it doesn't call the object
>>>>> constructor so far as I can tell, just calling g_object_new without any of
>>>>> the Vala object construction code.
>>>>>
>>>>> My Serializable is an interface.  I'm trying to make use of the Json
>>>>> serialization framework, and for the most part it's working.  The problem
>>>>> I'm having is with the construction of instances of array types - there
>>>>> appears to be no factory framework for object creation in Vala, and so far
>>>>> the only workaround I've come up with is very clunky.
>>>>>
>>>>> Is there an object factory somewhere that someone could point me
>>>>> towards?
>>>>>
>>>>> On Wed, Feb 17, 2016 at 1:49 AM, Daniel Espinosa <eso...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Try use Object.new(typeof(IntArr))
>>>>>>
>>>>>> Try to rename type() to any other, to avoid conflics with
>>>>>> Object.type()
>>>>>>
>>>>>> You are trying to implement Gee.ArrayList<>, may you:
>>>>>>
>>>>>> A) wrap Gee.ArrayList in your class
>>>>>>
>>>>>> B) Derive directly from Gee.Arraylist then convert your base class
>>>>>> Serializable as an interface with all required methods implemented as
>>>>>> virtual, then you have two bas

Re: [Vala] Problem with programmatic generic object instantiation

2016-02-16 Thread Andy Lees
Momentarily I thought that might work, but it does match the Json
serialization structure - the context of deserializing an array does not
provide the initialised array, the deserialization procedure has to do the
creation, and only has the type id to work with.  It looks like I'll have
to create an object factory of my own for this, as I don't want to get into
the internals of Json glib.

On Wed, Feb 17, 2016 at 10:09 AM, Daniel Espinosa <eso...@gmail.com> wrote:

> I run in the same issue for GXml and SerializableListArray<>, for example.
>
> The way I resolve, in my case, I've defined a new Interface called
> SerializableCollection, with a init() function. This function is called by
> Serializable.deserialize() method in order to help implementators to
> initialize its generic containers by calling MyObjectCollection.new()
> providing any information it needs like the Generic Type it should work on.
>
> In my other project, I've just initialize any public property as
>
> MyProperty prop { get; set; default = new MyProperty(); }
>
> or inside construct {}
>
> The point is to call MyProperty.new() not Object.new() on generic classes.
>
>
> 2016-02-16 16:59 GMT-06:00 Andy Lees <andrewl...@gmail.com>:
>
>> Yes, the problem is that for types derived from generics (and for the
>> generic constructor itself), the type information is not set in the
>> construct function, so very little can be done.
>>
>> On Wed, Feb 17, 2016 at 9:53 AM, Daniel Espinosa <eso...@gmail.com>
>> wrote:
>>
>>> If you want to execute code on Object creation using Object.new(), you
>>> should use
>>>
>>> construct {
>>>   // Your code here
>>> }
>>>
>>> When define code at MyObject.new(), you execute the code in this method
>>> not Object.new(), then use the above should help.
>>>
>>>
>>> 2016-02-16 15:58 GMT-06:00 Andy Lees <andrewl...@gmail.com>:
>>>
>>>> The problem with Object.new is that it doesn't call the object
>>>> constructor so far as I can tell, just calling g_object_new without any of
>>>> the Vala object construction code.
>>>>
>>>> My Serializable is an interface.  I'm trying to make use of the Json
>>>> serialization framework, and for the most part it's working.  The problem
>>>> I'm having is with the construction of instances of array types - there
>>>> appears to be no factory framework for object creation in Vala, and so far
>>>> the only workaround I've come up with is very clunky.
>>>>
>>>> Is there an object factory somewhere that someone could point me
>>>> towards?
>>>>
>>>> On Wed, Feb 17, 2016 at 1:49 AM, Daniel Espinosa <eso...@gmail.com>
>>>> wrote:
>>>>
>>>>> Try use Object.new(typeof(IntArr))
>>>>>
>>>>> Try to rename type() to any other, to avoid conflics with Object.type()
>>>>>
>>>>> You are trying to implement Gee.ArrayList<>, may you:
>>>>>
>>>>> A) wrap Gee.ArrayList in your class
>>>>>
>>>>> B) Derive directly from Gee.Arraylist then convert your base class
>>>>> Serializable as an interface with all required methods implemented as
>>>>> virtual, then you have two bases.
>>>>>
>>>>> You may want to check at GXml.Serializable interface and its
>>>>> GXml.SerializableArrayList implementation based on Gee.
>>>>> El feb. 16, 2016 7:10 AM, "Andy Lees" <andrewl...@gmail.com> escribió:
>>>>>
>>>>>> I would have expected the generic type to be obtained from the type
>>>>>> id of the derived type (generic instantiation), which is obtained fresh
>>>>>> each execution, but it seems not.  Is the generic type a hidden property 
>>>>>> of
>>>>>> the class derived from the generic class, and if so, what would its name 
>>>>>> be
>>>>>> so that it can be set in the new call?
>>>>>>
>>>>>> Alternatively, is there a way to call an object constructor given the
>>>>>> type id?
>>>>>>
>>>>>> On Tue, Feb 16, 2016 at 11:16 PM, Daniel Espinosa <eso...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Take in account that Type system is dynamically created, then a type
>>>>>>> number will change with each execution.
>>&

Re: [Vala] Problem with programmatic generic object instantiation

2016-02-16 Thread Andy Lees
Yes, the problem is that for types derived from generics (and for the
generic constructor itself), the type information is not set in the
construct function, so very little can be done.

On Wed, Feb 17, 2016 at 9:53 AM, Daniel Espinosa <eso...@gmail.com> wrote:

> If you want to execute code on Object creation using Object.new(), you
> should use
>
> construct {
>   // Your code here
> }
>
> When define code at MyObject.new(), you execute the code in this method
> not Object.new(), then use the above should help.
>
>
> 2016-02-16 15:58 GMT-06:00 Andy Lees <andrewl...@gmail.com>:
>
>> The problem with Object.new is that it doesn't call the object
>> constructor so far as I can tell, just calling g_object_new without any of
>> the Vala object construction code.
>>
>> My Serializable is an interface.  I'm trying to make use of the Json
>> serialization framework, and for the most part it's working.  The problem
>> I'm having is with the construction of instances of array types - there
>> appears to be no factory framework for object creation in Vala, and so far
>> the only workaround I've come up with is very clunky.
>>
>> Is there an object factory somewhere that someone could point me towards?
>>
>> On Wed, Feb 17, 2016 at 1:49 AM, Daniel Espinosa <eso...@gmail.com>
>> wrote:
>>
>>> Try use Object.new(typeof(IntArr))
>>>
>>> Try to rename type() to any other, to avoid conflics with Object.type()
>>>
>>> You are trying to implement Gee.ArrayList<>, may you:
>>>
>>> A) wrap Gee.ArrayList in your class
>>>
>>> B) Derive directly from Gee.Arraylist then convert your base class
>>> Serializable as an interface with all required methods implemented as
>>> virtual, then you have two bases.
>>>
>>> You may want to check at GXml.Serializable interface and its
>>> GXml.SerializableArrayList implementation based on Gee.
>>> El feb. 16, 2016 7:10 AM, "Andy Lees" <andrewl...@gmail.com> escribió:
>>>
>>>> I would have expected the generic type to be obtained from the type id
>>>> of the derived type (generic instantiation), which is obtained fresh each
>>>> execution, but it seems not.  Is the generic type a hidden property of the
>>>> class derived from the generic class, and if so, what would its name be so
>>>> that it can be set in the new call?
>>>>
>>>> Alternatively, is there a way to call an object constructor given the
>>>> type id?
>>>>
>>>> On Tue, Feb 16, 2016 at 11:16 PM, Daniel Espinosa <eso...@gmail.com>
>>>> wrote:
>>>>
>>>>> Take in account that Type system is dynamically created, then a type
>>>>> number will change with each execution.
>>>>>
>>>>> Use
>>>>>
>>>>> YourCreatedObject is typeof (Object)
>>>>>
>>>>> to check if the created object is of type you need, like a derived
>>>>> object.
>>>>>
>>>>> You can use
>>>>>
>>>>> obj.get_type().is_a(typeof (Object))
>>>>>
>>>>> And consider that your example is exactly the way to create an object
>>>>> of Generic class, because you have set tje object type. Create a generic
>>>>> instance with Object.new you should provide the object type.
>>>>> El feb. 16, 2016 5:14 AM, "Andy Lees" <andrewl...@gmail.com> escribió:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I have a generic array implementation like so:
>>>>>>
>>>>>> public class GArrSerializable : Serializable, Object  {
>>>>>>   public T[] data;
>>>>>>   public int length;
>>>>>>   public GArrSerializable(int size = 0) {
>>>>>> data = new T[size];
>>>>>>   }
>>>>>>
>>>>>>   public Type type () { return typeof (T); }
>>>>>>
>>>>>> ...etc
>>>>>>
>>>>>> and a derived type:
>>>>>>
>>>>>> public class IntArr : GArrSerializable {
>>>>>>
>>>>>>   public IntArr(int size = 0) {
>>>>>> base (size);
>>>>>>   }
>>>>>> }
>>>>>>
>>>>>> If I create an instance of the type, then instance.type () returns 24
>>>>>> as
>>>>>> expected.
>>>>>> If I create an instance like so:
>>>>>> var ia = Object.@new (type) as IntArr;
>>>>>> var t = ia.type ();
>>>>>>
>>>>>> Then t is 4 rather than 24.  As it is in the instance when it tries to
>>>>>> deserialize.
>>>>>>
>>>>>> Can you tell me why this is so, and how I can programmatically create
>>>>>> objects derived from a parameterised type?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> Andrew Lees
>>>>>> ___
>>>>>> vala-list mailing list
>>>>>> vala-list@gnome.org
>>>>>> https://mail.gnome.org/mailman/listinfo/vala-list
>>>>>>
>>>>>
>>>>
>>
>
>
> --
> Trabajar, la mejor arma para tu superación
> "de grano en grano, se hace la arena" (R) (en trámite, pero para los
> cuates: LIBRE)
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Problem with programmatic generic object instantiation

2016-02-16 Thread Andy Lees
The problem with Object.new is that it doesn't call the object constructor
so far as I can tell, just calling g_object_new without any of the Vala
object construction code.

My Serializable is an interface.  I'm trying to make use of the Json
serialization framework, and for the most part it's working.  The problem
I'm having is with the construction of instances of array types - there
appears to be no factory framework for object creation in Vala, and so far
the only workaround I've come up with is very clunky.

Is there an object factory somewhere that someone could point me towards?

On Wed, Feb 17, 2016 at 1:49 AM, Daniel Espinosa <eso...@gmail.com> wrote:

> Try use Object.new(typeof(IntArr))
>
> Try to rename type() to any other, to avoid conflics with Object.type()
>
> You are trying to implement Gee.ArrayList<>, may you:
>
> A) wrap Gee.ArrayList in your class
>
> B) Derive directly from Gee.Arraylist then convert your base class
> Serializable as an interface with all required methods implemented as
> virtual, then you have two bases.
>
> You may want to check at GXml.Serializable interface and its
> GXml.SerializableArrayList implementation based on Gee.
> El feb. 16, 2016 7:10 AM, "Andy Lees" <andrewl...@gmail.com> escribió:
>
>> I would have expected the generic type to be obtained from the type id of
>> the derived type (generic instantiation), which is obtained fresh each
>> execution, but it seems not.  Is the generic type a hidden property of the
>> class derived from the generic class, and if so, what would its name be so
>> that it can be set in the new call?
>>
>> Alternatively, is there a way to call an object constructor given the
>> type id?
>>
>> On Tue, Feb 16, 2016 at 11:16 PM, Daniel Espinosa <eso...@gmail.com>
>> wrote:
>>
>>> Take in account that Type system is dynamically created, then a type
>>> number will change with each execution.
>>>
>>> Use
>>>
>>> YourCreatedObject is typeof (Object)
>>>
>>> to check if the created object is of type you need, like a derived
>>> object.
>>>
>>> You can use
>>>
>>> obj.get_type().is_a(typeof (Object))
>>>
>>> And consider that your example is exactly the way to create an object of
>>> Generic class, because you have set tje object type. Create a generic
>>> instance with Object.new you should provide the object type.
>>> El feb. 16, 2016 5:14 AM, "Andy Lees" <andrewl...@gmail.com> escribió:
>>>
>>>> Hi,
>>>>
>>>> I have a generic array implementation like so:
>>>>
>>>> public class GArrSerializable : Serializable, Object  {
>>>>   public T[] data;
>>>>   public int length;
>>>>   public GArrSerializable(int size = 0) {
>>>> data = new T[size];
>>>>   }
>>>>
>>>>   public Type type () { return typeof (T); }
>>>>
>>>> ...etc
>>>>
>>>> and a derived type:
>>>>
>>>> public class IntArr : GArrSerializable {
>>>>
>>>>   public IntArr(int size = 0) {
>>>> base (size);
>>>>   }
>>>> }
>>>>
>>>> If I create an instance of the type, then instance.type () returns 24 as
>>>> expected.
>>>> If I create an instance like so:
>>>> var ia = Object.@new (type) as IntArr;
>>>> var t = ia.type ();
>>>>
>>>> Then t is 4 rather than 24.  As it is in the instance when it tries to
>>>> deserialize.
>>>>
>>>> Can you tell me why this is so, and how I can programmatically create
>>>> objects derived from a parameterised type?
>>>>
>>>> Thanks
>>>>
>>>> Andrew Lees
>>>> ___
>>>> vala-list mailing list
>>>> vala-list@gnome.org
>>>> https://mail.gnome.org/mailman/listinfo/vala-list
>>>>
>>>
>>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Problem with programmatic generic object instantiation

2016-02-16 Thread Andy Lees
I would have expected the generic type to be obtained from the type id of
the derived type (generic instantiation), which is obtained fresh each
execution, but it seems not.  Is the generic type a hidden property of the
class derived from the generic class, and if so, what would its name be so
that it can be set in the new call?

Alternatively, is there a way to call an object constructor given the type
id?

On Tue, Feb 16, 2016 at 11:16 PM, Daniel Espinosa <eso...@gmail.com> wrote:

> Take in account that Type system is dynamically created, then a type
> number will change with each execution.
>
> Use
>
> YourCreatedObject is typeof (Object)
>
> to check if the created object is of type you need, like a derived object.
>
> You can use
>
> obj.get_type().is_a(typeof (Object))
>
> And consider that your example is exactly the way to create an object of
> Generic class, because you have set tje object type. Create a generic
> instance with Object.new you should provide the object type.
> El feb. 16, 2016 5:14 AM, "Andy Lees" <andrewl...@gmail.com> escribió:
>
>> Hi,
>>
>> I have a generic array implementation like so:
>>
>> public class GArrSerializable : Serializable, Object  {
>>   public T[] data;
>>   public int length;
>>   public GArrSerializable(int size = 0) {
>> data = new T[size];
>>   }
>>
>>   public Type type () { return typeof (T); }
>>
>> ...etc
>>
>> and a derived type:
>>
>> public class IntArr : GArrSerializable {
>>
>>   public IntArr(int size = 0) {
>> base (size);
>>   }
>> }
>>
>> If I create an instance of the type, then instance.type () returns 24 as
>> expected.
>> If I create an instance like so:
>> var ia = Object.@new (type) as IntArr;
>> var t = ia.type ();
>>
>> Then t is 4 rather than 24.  As it is in the instance when it tries to
>> deserialize.
>>
>> Can you tell me why this is so, and how I can programmatically create
>> objects derived from a parameterised type?
>>
>> Thanks
>>
>> Andrew Lees
>> ___
>> vala-list mailing list
>> vala-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/vala-list
>>
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Parsing Vala/Genie code for auto-completion propuse: Should it be a `valac' feature or a separate project?

2016-02-15 Thread Andy Lees
Anjuta provides a ctags binary (anjuta-ctags) that will index vala code.

On Tue, Feb 16, 2016 at 3:36 AM, Ben Iofel  wrote:

> This might help
>
> https://github.com/benwaffle/vala-completion
>
> On Sun, Feb 14, 2016, 6:34 PM Felipe Lavratti  wrote:
>
> > Hello friends!
> >
> > I want to spend some effort in bringing up a nice auto complete system to
> > be used in the Atom code editor.
> >
> > First thing I am studying how to do the the indexation of code elements,
> > and this question has came to me: Why not use the vala compiler itself as
> > the parser, since it already does all the parsing job? I started my
> > learning with the vala compiler code, it doesn't seem hard to add this
> > feature to it, so I must come here and ask what do you vala experts think
> > about this?
> >
> > Should it be or shouldn't it be a Valac feature?
> >
> > Thanks
> > ___
> > vala-list mailing list
> > vala-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/vala-list
> >
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is there any usable editor for Vala?

2016-02-14 Thread Andy Lees
Hi,

A recent version of Anjuta compiled with Vala support enabled does pretty
well on code completion and go to declaration, and has the best debugger
for Vala that I've come across, albeit with a need to understand the C
structures produced by the Vala compiler.

However, for significant coding tasks (other than error fixes) I by far
prefer sublime text 3 with the Vala textmate bundle and ctags installed.
Of course if you use a Mac, then Textmate might be an alternative, but I
haven't tried it.  Make sure you set the ctags executable to use
anjuta-ctags (installed with Anjuta), which understands vala code and
generates suitable tags files.

I tried Valama a while back but couldn't get it to work with Vala on my box
(Mint 17).

Atom might also work, but I haven't tried it recently.

So my tools of choice are Anjuta for debugging and for compile error fixes
and other small changes, and Sublime Text 3 for most of my editing.

Good luck!

On Sun, Feb 14, 2016 at 10:32 PM, Matthias Berndt 
wrote:

> Hi,
>
> I wonder if you have any recommendation regarding a decent editor for Vala.
> I don't need much, just code completion and "go to declaration", but I
> can't seem to find anything that works. Here's the one's I've looked at:
>
> Anjuta: Imported the vala compiler as an autotools project, but neither
> code completion nor go to declaration works.
> Gnome Builder: crashes as soon as I open a .vala file.
> Geany: completion only suggests bogus (i. e. it offers methods that don't
> exist, doesn't offer the ones that do etc.).
> vala tools for gedit: not tried, but seems dead (last release was five
> years ago)
> valencia: also seems dead, couldn't get it to compile
> MonoDevelop: Vala support seems to have been removed
> Valama: Completion works! It also has 100% CPU usage at all times,
> millions of "self != NULL" assertion failures, no way to import existing
> code, it is slow and if a "go to declaration" feature exists, I couldn't
> find it. So it's also not really usable.
>
> What do you guys use to hack the vala compiler?
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] string.to_long vs long.parse

2016-02-10 Thread Andy Lees
Hello list,

I note that string.to_long is deprecated, but that the replacement
long.parse has reduced functionality.  Using to_long, I can have
hexadecimal, octal and binary number strings accepted, whilst long.parse
doesn't allow for this.

This does seem rather a backward step.  Was there some reason for not
accepting different standardised number representations?

Can I safely used the to_long function, without fear of it suddenly
disappearing?  Given it's extremely useful functional advantage over the
alternative, can it be un-deprecated, perhaps?

Best Regards,

Andrew Lees.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Generic implementation

2015-12-01 Thread Andy Lees
Hi,

If I define a generic array implementation for type T that contains an
array of type T[], there is a requirement for anything > 4 bytes in size to
be boxed.  That suggests that some separate storage is created for the
boxed types, is that so?  And if so is each element of the array as
appended separately allocated, or is a block allocation done as the T[]
array is extended?

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Generic implementation

2015-12-01 Thread Andy Lees
Yes, I've done that, but it doesn't particularly help - what is done
depends on the implementation of the boxed duplication function used for
the generic implementation, and I have no idea where that's defined.

On Wed, Dec 2, 2015 at 2:42 PM, Felipe de Andrade Neves Lavratti <
felipe...@gmail.com> wrote:

> Not really answering, but you could always run vala with -C to access the
> generated C code. There you could get tge result of the conversion.
>
>
> —
> Sent from Mailbox <https://www.dropbox.com/mailbox>
>
>
> On Wed, Dec 2, 2015 at 1:13 AM, Andy Lees <andrewl...@gmail.com> wrote:
>
>> Hi,
>>
>> If I define a generic array implementation for type T that contains an
>> array of type T[], there is a requirement for anything > 4 bytes in size
>> to
>> be boxed. That suggests that some separate storage is created for the
>> boxed types, is that so? And if so is each element of the array as
>> appended separately allocated, or is a block allocation done as the T[]
>> array is extended?
>>
>> Regards,
>>
>> Andrew Lees
>> ___
>> vala-list mailing list
>> vala-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/vala-list
>>
>>
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Fwd: Re: GenericArray problem

2015-10-17 Thread Andy Lees
Thanks Daniel, and I agree an empty subclass of a generic mostly works -
but not with GenericArray for some reason.  A direct specialisation of
GenericArray works fine, but if one creates a subclass as indicated, the C
comipler error appears in the compilation of the subclass definition.

I wonder if anyone has suggestions as to why GenericArray should
demonstrate this behaviour?

Also I note that the doco for GenericArray indicates that it takes a
defaulted initial size parameter, but it appears that it just ain't so -
giving an initial size causes a compilation error on too many args.

On Sat, Oct 17, 2015 at 11:58 PM, Daniel Espinosa <eso...@gmail.com> wrote:

> -- Mensaje reenviado --
> De: "Daniel Espinosa" <eso...@gmail.com>
> Fecha: oct. 17, 2015 7:58 AM
> Asunto: Re: [Vala] GenericArray problem
> Para: "Andy Lees" <andrewl...@gmail.com>
> Cc:
>
> In LibreSCL (www.librescl.org) I just declare an empty class derived from
> a
> generic one, this makes to call
>
> var a = new Intclass ();
>
> Just works.
>
> If you want a binding friendly class definition you should define your own
> get/set methods returning the actual value type not a generic, as in:
>
>
> https://github.com/powerwaremediacore/librescl/blob/master/librescl/tDA.vala
>
> I plan to add iterator methods to collections, this will allow bindings to
> use them on loops. Because we relay on Gee, its iterators are generic
> making hard/impossible to use on GObject Introspection bindings.
> El oct. 16, 2015 6:22 PM, "Andy Lees" <andrewl...@gmail.com> escribió:
>
> > Hi,
> >
> > If I declare a derived class of GenericArray, like so:
> >
> > public class IntArray : GenericArray {
> >   public IntArray() {
> >   }
> > }
> >
> > I get a gcc error, like so:
> > /tmp/a.vala.AH856X.c: In function ‘int_array_new’:
> > /tmp/a.vala.AH856X.c:66:2: error: too few arguments to function
> > ‘g_ptr_array_new_with_free_func’
> >   self = (IntArray*) g_ptr_array_new_with_free_func ();
> >
> > whereas with Array (for example) it just works.
> >
> > Is there something I'm doing wrong, or is this a bug?
> >
> > Using Vala 0.30.0
> >
> > Regards,
> >
> > Andrew Lees
> > ___
> > vala-list mailing list
> > vala-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/vala-list
> >
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Fwd: Re: GenericArray problem

2015-10-17 Thread Andy Lees
Thanks for the very detailed response, Evan.  I have filed a bug
accordingly.

In the meantime a simple [Compact] vala implementation of the generic array
functionality I need appears to take fewer cpu cycles than GenericArray
(when optimised) when tested with a few operation patterns, so it's not a
stopper issue for me, and the derivation works fine in that case.

On Sun, Oct 18, 2015 at 5:25 AM, Evan Nemerson <e...@coeus-group.com> wrote:

> On Sun, 2015-10-18 at 00:13 +1100, Andy Lees wrote:
> > I wonder if anyone has suggestions as to why GenericArray should
> > demonstrate this behaviour?
>
> The types in GLib aren't designed for inheritance.  Due to restrictions
> in the C API it can never be fully functional, so it is generally
> better to use composition.
>
> That said, this specific case *could* work with a bit of work in the
> compiler.  Support for inheriting from a compact class which uses
> simple generics in the constructor (a fairly uncommon thing to do) is,
> apparently, a bit buggy.  Specifically, the generic free function isn't
> passed.  It would be great if you filed a bug about this.
>
> > Also I note that the doco for GenericArray indicates that it takes a
> > defaulted initial size parameter, but it appears that it just ain't
> > so -
> > giving an initial size causes a compilation error on too many args.
>
> If you take a look at the VAPI, you'll notice it looks like this:
>
> #if GLIB_2_30
> [CCode (cname = "g_ptr_array_new_full", simple_generics = true)]
> public GenericArray (uint reserved_size = 0);
> #else
> [CCode (cname = "g_ptr_array_new_with_free_func", simple_generics =
> true)]
> public GenericArray ();
> #endif
>
> The version with the reserved_size argument is only available if you
> target a version of glib >= 2.30, which makes sense given that
> g_ptr_array_new_full was only added in glib 2.30.
>
> Pass --target-glib=2.30 (or greater) to valac and the extra argument
> will work.
>
> I believe valadoc.org produces documentation which assumes you are
> targeting the current stable version of glib.  Unfortunately it's not
> really possible to produce output which contains both versions without
> substantial changes to the parser in libvala, so a choice had to be
> made.  Targeting the current stable version seemed like the best
> approach.
>
>
> > On Sat, Oct 17, 2015 at 11:58 PM, Daniel Espinosa <eso...@gmail.com>
> > wrote:
> >
> > > -- Mensaje reenviado --
> > > De: "Daniel Espinosa" <eso...@gmail.com>
> > > Fecha: oct. 17, 2015 7:58 AM
> > > Asunto: Re: [Vala] GenericArray problem
> > > Para: "Andy Lees" <andrewl...@gmail.com>
> > > Cc:
> > >
> > > In LibreSCL (www.librescl.org) I just declare an empty class
> > > derived from
> > > a
> > > generic one, this makes to call
> > >
> > > var a = new Intclass ();
> > >
> > > Just works.
> > >
> > > If you want a binding friendly class definition you should define
> > > your own
> > > get/set methods returning the actual value type not a generic, as
> > > in:
> > >
> > >
> > > https://github.com/powerwaremediacore/librescl/blob/master/librescl
> > > /tDA.vala
> > >
> > > I plan to add iterator methods to collections, this will allow
> > > bindings to
> > > use them on loops. Because we relay on Gee, its iterators are
> > > generic
> > > making hard/impossible to use on GObject Introspection bindings.
> > > El oct. 16, 2015 6:22 PM, "Andy Lees" <andrewl...@gmail.com>
> > > escribió:
> > >
> > > > Hi,
> > > >
> > > > If I declare a derived class of GenericArray, like so:
> > > >
> > > > public class IntArray : GenericArray {
> > > >   public IntArray() {
> > > >   }
> > > > }
> > > >
> > > > I get a gcc error, like so:
> > > > /tmp/a.vala.AH856X.c: In function ‘int_array_new’:
> > > > /tmp/a.vala.AH856X.c:66:2: error: too few arguments to function
> > > > ‘g_ptr_array_new_with_free_func’
> > > >   self = (IntArray*) g_ptr_array_new_with_free_func ();
> > > >
> > > > whereas with Array (for example) it just works.
> > > >
> > > > Is there something I'm doing wrong, or is this a bug?
> > > >
> > > > Using Vala 0.30.0
> > > >
> > > > Regards,
> > > >
> > > > Andrew Lees
> > > > ___
> > > > vala-list mailing list
> > > > vala-list@gnome.org
> > > > https://mail.gnome.org/mailman/listinfo/vala-list
> > > >
> > > ___
> > > vala-list mailing list
> > > vala-list@gnome.org
> > > https://mail.gnome.org/mailman/listinfo/vala-list
> > >
> > ___
> > vala-list mailing list
> > vala-list@gnome.org
> > https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] GenericArray problem

2015-10-16 Thread Andy Lees
Hi,

If I declare a derived class of GenericArray, like so:

public class IntArray : GenericArray {
  public IntArray() {
  }
}

I get a gcc error, like so:
/tmp/a.vala.AH856X.c: In function ‘int_array_new’:
/tmp/a.vala.AH856X.c:66:2: error: too few arguments to function
‘g_ptr_array_new_with_free_func’
  self = (IntArray*) g_ptr_array_new_with_free_func ();

whereas with Array (for example) it just works.

Is there something I'm doing wrong, or is this a bug?

Using Vala 0.30.0

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Another question about enums and arrays

2015-04-30 Thread Andy Lees
Hi,

What is the reason for enumeration values (which can be treated as ints
without a cast) not being allowed where a const int is required?  Surely
enum values are the epitome of const values?

To whit:
int64 arr[AnEnum.SIZE];

results in:
arr2.vala:18.20-18.30: error: Expression of constant integer type expected
  int64 arr[AnEnum.SIZE];
^^^
Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Const declaration after use

2015-04-29 Thread Andy Lees
Hi,

I had thought that the following issue with declaration order (variables vs
#defines) in the generated C code had been fixed a while ago, but I seem to
be having the old problem:

Code:
public enum AnEnum {
  LEVEL_UP, //
  SIZE  // for array sizing
}
const int AnEnumSize = (int)AnEnum.SIZE;
int64 *ptrs2[AnEnumSize];

Result:
/tmp/arr2.vala.R3EBYX.c:20:22: error: ‘AnEnumSize’ undeclared here (not in
a function)
 extern gint64* ptrs2[AnEnumSize];
  ^
error: cc exited with status 256

Using 0.26.2

Perhaps I am recalling the existence of the fix incorrectly?

I can work around with a dynamic array, but given the static nature of the
declaration, I'd prefer not to.

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Export vapi from libray

2014-11-21 Thread Andy Lees
Hi,

I would like to export an interface to some C structures from a vala
library that provides a number of other classes, etc.  If I include the
vapi and associated .h file in the library, it compiles fine, but does not
export the contents of the referenced vapi in the library vapi.

How would one go about including the vapi contents in the library interface?

Thanks for your attention.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Testing out parameters

2014-11-21 Thread Andy Lees
Is there a way to test if an out parameter has been provided, assuming I
default it to null?  In the case I want to avoid an expensive calculation
if it's not required?

Thanks for your attention.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Tokenize_and_fold bug?

2014-11-17 Thread Andy Lees
Same result.  Submitted bug.

On Mon, Nov 17, 2014 at 7:31 PM, Michele Dionisio 
michele.dioni...@gmail.com wrote:

 try to define your variable x with

 [CCode (array_length = false, array_null_terminated = true)]


 2014-11-17 5:15 GMT+01:00 Andy Lees andrewl...@gmail.com:

 Hi,

 Not sure if I'm doing this wrong, but if I do something like:

 public static int main(string [] argv) {
   string[] x;
   var a = 1,2, 345.tokenize_and_fold (en_GB, out x);
   stdout.printf(Len: %d\n, a.length);
   foreach (var s in a) {
 stdout.printf(tok: %s, s);
   }
   return 0;
 }

 I get a C compiler error:
 /home/andrewl/Vala/VTest1/prop.vala.c: In function ‘_vala_main’:
 /home/andrewl/Vala/VTest1/prop.vala.c:41:2: error: too many arguments to
 function ‘g_str_tokenize_and_fold’
   _tmp3_ = _tmp2_ = g_str_tokenize_and_fold (1,2, 345, en_GB, _tmp0_,
 _tmp1_);
   ^

 As does any variation of two arguments.  Fewer than 2 args results in a
 vala compiler error.

 Bug?
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list



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


[Vala] Tokenize_and_fold bug?

2014-11-16 Thread Andy Lees
Hi,

Not sure if I'm doing this wrong, but if I do something like:

public static int main(string [] argv) {
  string[] x;
  var a = 1,2, 345.tokenize_and_fold (en_GB, out x);
  stdout.printf(Len: %d\n, a.length);
  foreach (var s in a) {
stdout.printf(tok: %s, s);
  }
  return 0;
}

I get a C compiler error:
/home/andrewl/Vala/VTest1/prop.vala.c: In function ‘_vala_main’:
/home/andrewl/Vala/VTest1/prop.vala.c:41:2: error: too many arguments to
function ‘g_str_tokenize_and_fold’
  _tmp3_ = _tmp2_ = g_str_tokenize_and_fold (1,2, 345, en_GB, _tmp0_,
_tmp1_);
  ^

As does any variation of two arguments.  Fewer than 2 args results in a
vala compiler error.

Bug?
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Const #defs after use: is this a known problem?

2014-10-21 Thread Andy Lees
Thanks for that.  I did search, but not with the right term it seems!

On Tue, Oct 21, 2014 at 6:32 PM, Luca Bruno lethalma...@gmail.com wrote:

 On 21/10/2014 02:14, Andy Lees wrote:
  If I have the following structure:
 
  public class Main : Object
  {
  
static const int max_chans = 64;
  
static int out_chans[max_chans];
 
  The compilation fails because the #defines for the const declarations are
  made after the declarations of the non-const arrays.  Is there a reason
 for
  this, or is it just a compiler error?
 Known bug: https://bugzilla.gnome.org/show_bug.cgi?id=727667
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list

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


[Vala] Const #defs after use: is this a known problem?

2014-10-20 Thread Andy Lees
If I have the following structure:

public class Main : Object
{

  static const int max_chans = 64;

  static int out_chans[max_chans];

The compilation fails because the #defines for the const declarations are
made after the declarations of the non-const arrays.  Is there a reason for
this, or is it just a compiler error?

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] open and read a csv file

2014-10-16 Thread Andy Lees
Have a look at
https://github.com/ktt-ol/serial-barcode-scanner/blob/master/src/web/csv.vala
for a split regexp and how to deal with quotes.  Should be fairly
straightforward to use an existing io class (FileStream if reading from a
file) as the basis for your data source.

Regards,

Andy

On Fri, Oct 17, 2014 at 12:42 AM, Jason Scurtu scu...@mail.de wrote:

 Hi,

 I am new to vala and gnome programming and I am looking for a way to open
 and read a csv file.
 Still toying with it and trying to figure everything out.
 Basicly, I want to open a csv and write the data to a SQLite database and
 display it in a GridView .. but, how to read a CSV?
 I come from a C# background and I can hardly find any doucumentation or a
 app that does something similar (code peek).

 Im using Arch with the latest Vala release : 0.26.1 .

 Please, can someone help me get started. Would really apprieciate it.

 Thanks

 Jason


 -
 FreeMail powered by mail.de - MEHR SICHERHEIT, SERIOSITÄT UND KOMFORT
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list

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


[Vala] converting void** to int[]*, or other ways to generically assign arrays

2014-10-15 Thread Andy Lees
Hi,

In providing a general purpose configuration facility, I register the
address of configured variables in a void*. The description of a configured
item is:
string key;
Type type;
void *loc;
string? deflt;
int size;
ConfigFlags flags;
and an example configuration definition would be:
Conf.ConfItem (Priority, typeof (int32), conf.priority, 30, 0, 0)
or
Conf.ConfItem (Channels, typeof (int32[]), conf.channels, , 0, 0)
and an assignment is like:
*((int32*)it.loc) = int.parse (val);
This works fine with single values, but I cannot seem to find a way to
assign arrays.  If I use something like:
void **ptr = it.loc;
*ptr = to_int32_arr (list);
The array pointer is assigned, but the length (and I assume a reference
count) is not.

A problem is that I cannot figure out how to declare a pointer to an array
- declarations like: int32[] *target; don't compile.  Similarly an
assignment like:
*((int32[]*)it.loc) = to_int32_arr (list);
Doesn't compile. ( syntax error, expected identifier).

Surely there is a way to do this sort of thing straightforwardly in vala?
Is there a way to declare a pointer to an array?

Any assistance is welcome.

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Type parameter not stored as expected

2014-09-15 Thread Andy Lees
Hi Luca,

Example attached.  Output (compiled with valac 0.24) is:

ReaderState start: k 0x2233030

(process:28945): GLib-GObject-WARNING **: cannot retrieve class for invalid
(unclassed) type '(null)'
ReaderState end: k 0x2233030 this.kl: (nil)
klass: 0x2233030 r.kl: (nil)
Set_state start r.kl (nil)
Set_state end k: (nil), r.kl (nil)
196, 0x2233030 : 196, (nil)

After doing this I installed 0.25.3, which provides hints by way of
compilation errors:

t7.vala:10.17-10.17: error: duplicating TypeClass instance, use unowned
variable or explicitly invoke copy method
  this.kl = k;
^

** (valac:29749): CRITICAL **:
vala_ccode_assignment_module_real_store_field: assertion 'value != NULL'
failed
t7.vala:18.9-18.12: error: duplicating TypeClass instance, use unowned
variable or explicitly invoke copy method
k = r.kl;


** (valac:29749): CRITICAL **:
vala_ccode_assignment_module_real_store_parameter: assertion '_value !=
NULL' failed
Compilation failed: 2 error(s), 0 warning(s)

So perhaps that resolves the problem.

Regards,

Andrew Lees.


On Fri, Sep 12, 2014 at 5:41 PM, Luca Bruno lethalma...@gmail.com wrote:

 On 12/09/2014 02:31, Andy Lees wrote:
  Greetings,
 
  I have a data type used to store parser state declared as:
class ReaderState {
  public Object obj;
  public bool in_array;
  public Type type;
  public TypeClass kl;
 
  public ReaderState (Object o, bool a, Type t, TypeClass k) {
this.obj = o;
this.in_array = a;
this.type = t;
this.klass = k;
  }
}

 Can you please provide a self-contained test case with a main() that I
 can compile and run?
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list



  class ReaderState {
public Type type;
public TypeClass kl;

public ReaderState (Type t, TypeClass k) {
  stdout.printf(ReaderState start: k %p\n, k);
  this.type = t;
  this.kl = k;
  stdout.printf(ReaderState end: k %p this.kl: %p\n, k, this.kl);
}
  }

  static void set_state(ReaderState r, out Type t, out TypeClass k) {
stdout.printf(Set_state start r.kl %p\n, r.kl);
t = r.type;
k = r.kl;
stdout.printf(Set_state end k: %p, r.kl %p\n, k, r.kl);
  }


public static int main(string [] argv) {
var type = typeof (ReaderState);
var klass = type.class_ref ();
Type t2;
TypeClass kl2;
ReaderState r = new ReaderState (type, klass);
stdout.printf(klass: %p r.kl: %p\n, klass, r.kl);
set_state (r, out t2, out kl2);
stdout.printf(%d, %p : %d, %p\n, (int)type, klass, (int)t2, kl2);
  return 0;
}
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Type parameter not stored as expected

2014-09-11 Thread Andy Lees
Greetings,

I have a data type used to store parser state declared as:
  class ReaderState {
public Object obj;
public bool in_array;
public Type type;
public TypeClass kl;

public ReaderState (Object o, bool a, Type t, TypeClass k) {
  this.obj = o;
  this.in_array = a;
  this.type = t;
  this.klass = k;
}
  }

When creating a new element, obj, in_array and type are all stored
correctly, while klass is never stored.  The parameter value is correct,
but the stored value is always 0.  Instances of ReaderState are stored in a
stack, and if the stored TypeClass is used on retrieval, it is always 0,
but if regenerated from the type element, it is correct, so I do have a
workaround for the issue.

My concern is that I'm failing to understand something about the language
semantics that will bite me elsewhere, so does anyone have any idea as to
why this behaviour is demonstrated?  Or is it just a bug?

From the calling perspective, type and klass are instance variables and are
assigned as:

  type = current.get_type ();
  klass = type.class_ref ();

The C generated for the klass assignment internally to ReaderState is:
_tmp4_ = k;
_tmp5_ = _g_type_class_ref0 (_tmp4_);
_g_type_class_unref0 (self-klass);
self-klass = _tmp5_;

Does that suggest what is happening?

Regards,

Andrew Lees.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] GLib-GObject-WARNING but code appears to work

2014-09-11 Thread Andy Lees
Greetings,

I am building a simple structure driven json reader, and in the process
construct objects from Type values.  The construction appears to work
correctly, in that the instances are created, have the expected fields that
can be found by find_property, and end up with values from the json string
correctly assigned.  My concern is a warning message generated when the
following code is executed:

Object child = Object.@new (e_type);

Which results in a message:
 GLib-GObject-WARNING **: cannot retrieve class for invalid (unclassed)
type '(null)'

A typical type generating this warning on creation via the above code is:

public class AxleInfo : GLib.Object {

  public int pos {get; set; }
  public int weight {get; set; }
  public bool twin {get; set; }

  public AxleInfo(int pos, int weight, bool twin = false) {
this.pos = pos;
this.weight = weight;
this.twin = twin;
  }
}

The e_type value is consistent with the typeof (AxleInfo) value, and is
obtained via:

  Gee.CollectionObject arr = (Gee.CollectionObject)current;
  Type e_type = arr.element_type;

So, is there something I should be doing to register this type, or some
other step I'm missing?
Is the element_type value returned the correct parameter to pass to
Object.@new to create a new array element?
What does the error message mean in practice?  I have not had any luck so
far in finding an explanation.

Regards,

Andrew Lees
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list