On 26/09/2014 16:44, Matrix wrote:
> 在 2014/9/26 22:19, Luca Bruno 写道:
>> On 26/09/2014 16:09, Matrix wrote:
>>> Hi:
>>>
>>> I'm try using Vala to write a GUI serialport tool with libserialport.
>>>
>>> I have already have a demo with pure c implenmention.
>>>
>>> I'm still working with write vapi file to this lib follow the tutorial
>>> at https://wiki.gnome.org/Projects/Vala/LegacyBindings
>>>
>>> but the c struct is init by this form:
>>>
>>> enum sp_return sp_get_port_by_name(const char *portname, struct
>>> sp_port **port_ptr);
>>>
>>> how do i to write for such form ?
>> class Port {
>>    [CCode (cname = "sp_get_port_by_name")]
>>    static Return get_port_by_name (string portname, out Port);
>> }
>>
>> Then:
>>
>> Port port;
>> Port.get_port_by_name ("foo", out port);
>> _______________________________________________
>> vala-list mailing list
>> [email protected]
>> https://mail.gnome.org/mailman/listinfo/vala-list
>
> Thank you, Luca Bruno!
>
> I follow your help, but have error....
>
> there is my vapi file snippet:
>
> /*************************************************
> using GLib;
>
> namespace SerialPort {
>     [CCode (cname = "int", cprefix = "SP_", has_type_id = "false")]
>     public enum Return {
>         OK,
>         ERR_ARG,
>         ERR_FAIL,
>         ERR_MEM,
>         ERR_SUPP
>     }
>
>     [CCode (cname = "struct sp_port", has_type_id = "false")]
>     public class Port {
>         [CCode (cname = "sp_get_port_by_name", has_type_id = "false")]
>         static Return get_port_by_name(string name, out Port);
>     }
> }
> /***************************************************
>
> $ valac -C auto_test.vala --pkg libserialport
> Compilation failed: 1 error(s), 0 warning(s)
> libserialport.vapi:16.61-16.61: error: syntax error, expected identifier
>         static Return open_get_by_name(string name, out Port);
>
Of course, out Port port :)
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to