Call a foreign-language function: Difference between revisions

Content added Content deleted
(→‎{{header|CMake}}: Warn about deprecation. Add instruction to run `cmake .`.)
Line 888: Line 888:
=={{header|Julia}}==
=={{header|Julia}}==
Julia has a built-in keyword <code>ccall</code> to call external C-like functions. For example:
Julia has a built-in keyword <code>ccall</code> to call external C-like functions. For example:
<lang julia>julia> p = ccall(:strdup, Ptr{Uint8}, (Ptr{Uint8},), "Hello world")
<lang julia>p = ccall(:strdup, Ptr{Cuchar}, (Ptr{Cuchar},), "Hello world")
@show unsafe_string(p) # "Hello world"
Ptr{Uint8} @0x000000011731bde0
ccall(:free, Void, (Ptr{Cuchar},), p)

</lang>
julia> bytestring(p) # convert pointer back to a native Julia string
"Hello world"

julia> ccall(:free, Void, (Ptr{Uint8},), p)</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==