summaryrefslogtreecommitdiffstats
path: root/lua/snippet/c.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/snippet/c.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/snippet/c.lua b/lua/snippet/c.lua
index 3c1e127..7ef2e51 100644
--- a/lua/snippet/c.lua
+++ b/lua/snippet/c.lua
@@ -54,4 +54,26 @@ ls.add_snippets('c', {
}
)
),
+ s({
+ name = 'Variadic function parser',
+ trig = 'infinite vars',
+ dscr = 'Parse an infinite number of arguments passed to a function',
+ },
+ {
+ t({
+ "/*",
+ " * NOTE: the function must have a int before the ... argument",
+ " * and you need to include <stdarg.h> for this to work",
+ " */",
+ "va_list ptr;",
+ "va_start(ptr, ", i(1, "n"),
+ ");",
+ "for (int i = 0; i < ", ri(1),
+ "; i++) {",
+ i(2),
+ "}",
+ "va_end(ptr);",
+ }),
+ }
+ )
})