Anonymous user
Use another language to call a function: Difference between revisions
Use another language to call a function (view source)
Revision as of 16:11, 19 November 2009
, 14 years agoFixed lang tags.
(Added HaXe language) |
m (Fixed lang tags.) |
||
Line 27:
=={{header|Ada}}==
The interface package Exported specification:
<lang Ada>with Interfaces.C; use Interfaces.C;▼
▲with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
Line 35 ⟶ 34:
return int;
pragma Export (C, Query, "Query");
end Exported;</lang>
The package implementation:
<lang Ada>package body Exported is
function Query (Data : chars_ptr; Size : access size_t)
return int is
Line 52 ⟶ 49:
end if;
end Query;
end Exported;</lang>
With [[GNAT]] it can be built as follows:
<lang
gnatmake -c exported.adb
gnatbind -n exported.ali
gnatlink exported.ali main.o -o main</lang>
Sample output:
<pre>
Line 68 ⟶ 62:
=={{header|HaXe}}==
=== PHP ===
<
=={{header|Lisaac}}==
query.li
<lang Lisaac>Section Header
+ name := QUERY;
Line 104 ⟶ 97:
+ size : NATIVE_ARRAY[INTEGER];
query(buffer, size); // need this to pull the query() method
);</lang>
Makefile
<lang
all: $(TARGET)
Line 122 ⟶ 113:
clean:
rm -f $(TARGET) *.o query.c</lang>
=={{header|OCaml}}==
<lang
#include <string.h>
#include <caml/mlvalues.h>
Line 172 ⟶ 162:
;;</lang>
<lang
gcc -c main.c -I"`ocamlc -where`"
gcc -o prog.opt main.o caml_part_obj.o \
Line 182 ⟶ 172:
===‘In’ Parameters===
To connect a function to Tcl that passes an arbitrary C string as input, you'd use a short C thunk, like this:
<lang
Tcl_Obj *arguments[2];
int code;
Line 211 ⟶ 201:
===‘Out’ Parameters===
However, in the specific case of writing to a user-specified buffer (an “out” parameter) the thunk code would instead manage copying the result from the interpreter back to the buffer:
<lang
const char *str;
int len;
Line 232 ⟶ 222:
===Connecting up the pieces===
You would also need a short piece of code in <code>main()</code> to initialize the Tcl library and create an interpreter instance, and you would need to build and link against [[libtcl]].
<lang
Tcl_Interp *interp;
|