• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/17_lib_ffi/26_variadic_args

  1 Test calling C functions with variadic arguments (printf-style functions).
  2 
  3 printf() with integer argument.
  4 -- Testcase --
  5 {%
  6 import * as ffi from 'ffi';
  7 
  8 let libc = ffi.dlopen(null);
  9 let printf = libc.wrap('int printf(const char *, ...)');
 10 
 11 printf("value=%d\n", 42);
 12 -- End --
 13 
 14 -- Expect stdout --
 15 value=42
 16 -- End --
 17 
 18 
 19 printf() with multiple variadic parameters.
 20 -- Testcase --
 21 {%
 22 import * as ffi from 'ffi';
 23 
 24 let libc = ffi.dlopen(null);
 25 let printf = libc.wrap('int printf(const char *, ...)');
 26 
 27 printf("%s: %d %f\n", "test", 10, 3.14);
 28 -- End --
 29 
 30 -- Expect stdout --
 31 test: 10 3.140000
 32 -- End --
 33 
 34 
 35 sprintf() with array buffer (requires char array to pointer conversion).
 36 -- Testcase --
 37 {%
 38 import * as ffi from 'ffi';
 39 
 40 let libc = ffi.dlopen(null);
 41 let sprintf = libc.wrap('int sprintf(char *, const char *, ...)');
 42 
 43 let buf = ffi.ctype('char[256]');
 44 sprintf(buf, "value=%d", 42);
 45 
 46 print("sprintf result: ", ffi.string(buf), "\n");
 47 -- End --
 48 
 49 -- Expect stdout --
 50 sprintf result: value=42
 51 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt