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

Sources/ucode/tests/custom/17_lib_ffi/15_dlopen_dlsym

  1 The `ffi.dlopen()` and `ffi.C.dlsym()` functions load dynamic libraries and resolve symbols.
  2 
  3 Load a dynamic library (libz).
  4 
  5 -- Testcase --
  6 {%
  7 import * as ffi from 'ffi';
  8 
  9 try {
 10     let libz = ffi.dlopen('z');
 11     print("dlopen result: ", libz ? "OK" : "NULL", "\n");
 12 } catch (e) {
 13     print("dlopen error: ", e, "\n");
 14 }
 15 -- End --
 16 
 17 -- Expect stdout --
 18 dlopen result: OK
 19 -- End --
 20 
 21 
 22 Resolve symbol from global scope.
 23 
 24 -- Testcase --
 25 {%
 26 import * as ffi from 'ffi';
 27 
 28 let strlen_sym = ffi.C.dlsym('strlen');
 29 print("dlsym result: ", strlen_sym ? "found" : "NULL", "\n");
 30 -- End --
 31 
 32 -- Expect stdout --
 33 dlsym result: found
 34 -- End --
 35 
 36 
 37 Wrap and call dlsym'd function.
 38 
 39 -- Testcase --
 40 {%
 41 import * as ffi from 'ffi';
 42 
 43 let strlen_sym = ffi.C.dlsym('strlen');
 44 let strlen_fn = ffi.C.wrap('size_t strlen(const char *)');
 45 let len = strlen_fn("hello");
 46 
 47 print("strlen: ", len, "\n");
 48 -- End --
 49 
 50 -- Expect stdout --
 51 strlen: 5
 52 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt