/src/wrappers/ffi/examples/ffi_example.e

http://github.com/tybor/Liberty · Specman e · 52 lines · 25 code · 8 blank · 19 comment · 0 complexity · 61aa3a136ed7a8a89b3e15bcad9e0a71 MD5 · raw file

  1. class FFI_EXAMPLE
  2. -- Sample usage of the foreign function interface library.
  3. -- Invoking "puts" C function a couple of time with two different Eiffel strings.
  4. insert
  5. FFI_TYPES
  6. FFI_MORE_EXTERNALS
  7. ANY -- To reobtain copy, default_create and is_equal.
  8. create {ANY} make
  9. feature {ANY} -- Creating
  10. make
  11. local msg: STRING; ptr: POINTER
  12. do
  13. create call.prepare(my_function, ffi_type_sint32, <<ffi_type_pointer>>)
  14. print("Invoking 'puts'%N")
  15. msg := "Hello Liberty!"
  16. ptr := msg.to_external
  17. call.invoke($call_result, <<$ptr>>)
  18. print("Result of last call is "+call_result.out+"%N")
  19. --call.invoke(resp,<<"Hello again!".to_external>>)
  20. -- print("Result of last call is "+res.out+"%N")
  21. end
  22. feature {ANY}
  23. call_result: INTEGER_64;
  24. call: FFI_CALL
  25. my_function: POINTER
  26. external "C inline"
  27. alias "puts"
  28. end
  29. end
  30. -- Copyright (C) 2010-2017: Paolo Redaelli, 2013 Cyril Adrian
  31. -- This library is free software; you can redistribute it and/or
  32. -- modify it under the terms of the GNU Lesser General Public License
  33. -- as published by the Free Software Foundation; either version 2.1 of
  34. -- the License, or (at your option) any later version.
  35. --
  36. -- This library is distributed in the hope that it will be useful, but
  37. -- WITHOUT ANY WARRANTY; without even the implied warranty of
  38. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  39. -- Lesser General Public License for more details.
  40. --
  41. -- You should have received a copy of the GNU Lesser General Public
  42. -- License along with this library; if not, write to the Free Software
  43. -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  44. -- 02110-1301 USA