PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1class 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
 6	-- Invokes "puts" C to print "Hello Liberty" and "Hello again" strings.
 7	
 8insert 
 9    ANY -- To get copy, default_create and is_equal
10	FFI_TYPES
11    FFI_MORE_EXTERNALS
12
13create {ANY} make
14
15feature {ANY} -- Creating
16	make
17		local res: FOREIGN_OBJECT; args: FOREIGN_PARAMETERS
18	do
19		create call.make(my_function,<<types.c_string>>, types.sint32)
20
21		print("Invoking 'puts'%N")
22		args.set(<<types.create_string("Hello Liberty!")>>)
23		res := call.item(args)
24
25		print("Result of last call is "+res.out+"%N")
26	end
27
28feature {ANY} 
29	types: FOREIGN_TYPES
30
31	call_result: INTEGER_64;
32
33	call: FOREIGN_EXTERNAL_FUNCTION
34
35	my_function: POINTER
36		external "C inline"
37		alias "puts"
38		end
39end
40
41-- Copyright (C) 2010-2017: Paolo Redaelli, 2013 Cyril Adrian
42
43-- This library is free software; you can redistribute it and/or
44-- modify it under the terms of the GNU Lesser General Public License
45-- as published by the Free Software Foundation; either version 2.1 of
46-- the License, or (at your option) any later version.
47--
48-- This library is distributed in the hope that it will be useful, but
49-- WITHOUT ANY WARRANTY; without even the implied warranty of
50-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
51-- Lesser General Public License for more details.
52--
53-- You should have received a copy of the GNU Lesser General Public
54-- License along with this library; if not, write to the Free Software
55-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
56-- 02110-1301 USA
57