Vala string with length as separate arguments

I am writing VAPI bindings for the ZXing-cpp library’s C bindings for a personal project.

The two constructor functions that I care about right now are:

The “from bytes” variant is easy because Vala automatically passes the length after the data, so:

[CCode (cprefix = "ZXing_", cheader_filename = "ZXing/ZXingC.h")]
namespace ZXing {
public class CreatorOptions {}

[CCode (unref_function = "ZXing_Barcode_delete")]
public class Barcode {
    [CCode (cname = "ZXing_CreateBarcodeFromBytes")]
    public Barcode.from_bytes(uint8[] data, CreatorOptions? opts = null);
}
}

and its usage

var barcode = new Barcode.from_bytes({ 1, 2, 3 });

compiles and runs fine.

However, the “from_text” version doesn’t work, because Vala doesn’t pass the length of the text as the second argument like it does with the array.

    [CCode (cname = "ZXing_CreateBarcodeFromText")]
    public Barcode.from_text(string data, CreatorOptions? opts = null);
var barcode = new Barcode.from_text("Hello");

Is it possible to tell Vala to send data.length as the second argument? Or is there a reasonable alternative?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.