Jump to content

Call a foreign-language function: Difference between revisions

Added Odin variant
(Added Odin variant)
Line 2,057:
(g_application_run app 0 #false)
</syntaxhighlight>
 
=={{header|Odin}}==
 
<syntaxhighlight lang="odin">package main
 
import "core:fmt"
 
foreign import libc "system:c"
 
@(default_calling_convention="c")
foreign libc {
@(link_name="strdup") cstrdup :: proc(_: cstring) -> cstring ---
@(link_name="free") cfree :: proc(_: rawptr) ---
}
 
main :: proc() {
s1 : cstring = "hello"
s2 := cstrdup(s1)
fmt.printf("{}\n", s2)
cfree(rawptr(s2))</syntaxhighlight>
 
=={{header|Oz}}==
First we need to create a so-called "native functor" that converts the arguments and describes the C functions:
29

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.