/src/wrappers/ffi/examples/foreign_interface_example.e

http://github.com/tybor/Liberty · Specman e · 57 lines · 25 code · 13 blank · 19 comment · 0 complexity · 933c63033bfbe78e9ab61ad7e168dca9 MD5 · raw file

  1. class FOREIGN_INTERFACE_EXAMPLE
  2. -- Sample usage of the foreign function interface library using Liberty's
  3. -- foreign interface which makes handling applying the types of a call as
  4. -- comfortable as possible from the strongly-typed Liberty world.
  5. -- Invokes "puts" C to print "Hello Liberty" and "Hello again" strings.
  6. insert
  7. ANY -- To get copy, default_create and is_equal
  8. FFI_TYPES
  9. FFI_MORE_EXTERNALS
  10. create {ANY} make
  11. feature {ANY} -- Creating
  12. make
  13. local res: FOREIGN_OBJECT; args: FOREIGN_PARAMETERS
  14. do
  15. create call.make(my_function,<<types.c_string>>, types.sint32)
  16. print("Invoking 'puts'%N")
  17. args.set(<<types.create_string("Hello Liberty!")>>)
  18. res := call.item(args)
  19. print("Result of last call is "+res.out+"%N")
  20. end
  21. feature {ANY}
  22. types: FOREIGN_TYPES
  23. call_result: INTEGER_64;
  24. call: FOREIGN_EXTERNAL_FUNCTION
  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