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