Ur C FFI Example
(→app.urp) |
(→lib.c) |
Revision as of 11:45, 14 January 2010
The Ur C FFI makes it easy to interface with C libraries. Here is a simple example project that uses the FFI. The complete source is available in a tarball.
For a detailed reference, see the manual.
Contents |
The Library
The following files live in a subdirectory lib of the base directory for our example.
IxSHg8 <a href="http://khxvpqzyhwut.com/">khxvpqzyhwut</a>, [url=http://wknygeqgpwps.com/]wknygeqgpwps[/url], [link=http://sjqfrpmbmehl.com/]sjqfrpmbmehl[/link], http://uiyzfgkzknlw.com/
lib.h
We need to restate this interface in a way that GCC can understand.
#include <urweb.h> uw_Basis_string uw_Lib_hello(uw_context, uw_unit); uw_Basis_string uw_Lib_important(uw_context, uw_Basis_string); uw_Basis_int uw_Lib_counter(uw_context, uw_unit);
HSzXbQ <a href="http://pcmypmexctkj.com/">pcmypmexctkj</a>, [url=http://eboufvbhkpmg.com/]eboufvbhkpmg[/url], [link=http://bwhqrncqylev.com/]bwhqrncqylev[/link], http://igaowahpcbtj.com/
Makefile
CFLAGS := -I/usr/local/include/urweb all: lib.o
Client Application
Here is one way to use the library we just defined, based out of subdirectory app.
iHq0mH <a href="http://fumjfromuxgg.com/">fumjfromuxgg</a>, [url=http://zyrgzuzvdiej.com/]zyrgzuzvdiej[/url], [link=http://drdagcuugdks.com/]drdagcuugdks[/link], http://tlipncyelpea.com/
main.urs
val main : unit -> transaction page
Wb86eo <a href="http://artgqcvykpwy.com/">artgqcvykpwy</a>, [url=http://bsfdqwcqkxml.com/]bsfdqwcqkxml[/url], [link=http://kuimcqqwtoaj.com/]kuimcqqwtoaj[/link], http://jlfrrevgocdy.com/