From 3b20375d44196400c7ef1faefeeeaf059b02b21f Mon Sep 17 00:00:00 2001 From: "Dr. Michael Lauer" Date: Fri, 16 Mar 2018 15:33:08 +0100 Subject: [PATCH] posix: Bind va_list and add string.concat() (POSIX) This fixes string templates when using the POSIX profile. --- vapi/posix.vapi | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/vapi/posix.vapi b/vapi/posix.vapi index 916ead5ff..93eb80b70 100644 --- a/vapi/posix.vapi +++ b/vapi/posix.vapi @@ -251,6 +251,17 @@ public struct time_t { public time_t (); } +[SimpleType] +[CCode (cheader_filename = "stdarg.h", cprefix = "va_", has_type_id = false, destroy_function = "va_end", lvalue_access = false)] +public struct va_list { + [CCode (cname = "va_start")] + public va_list (); + [CCode (cname = "va_copy")] + public va_list.copy (va_list src); + [CCode (generic_type_pos = 1.1, simple_generics = true)] + public unowned G arg (); +} + [Compact] [Immutable] [CCode (cname = "char", const_cname = "const char", copy_function = "strdup", free_function = "free", cheader_filename = "stdlib.h,string.h")] @@ -258,6 +269,20 @@ public class string { [PrintfFormat] public string printf (...); + public string concat (...) { + string result = this; + var l = va_list (); + while (true) { + unowned string? arg = l.arg (); + if (arg == null) { + break; + } else { + result += arg; + } + } + return result; + } + public inline unowned string to_string () { return this; } -- 2.47.2