L programs can call external code using C calling convertion. Classes that call native code are marked unsafe.
Source:namespace Native is
class Main is
const int LENGTH = 20;
// define two native functions:
native char ptr GC_malloc( int size ); // provided by libgc
native void strncpy( char ptr s, char ptr t, int len ); // provided by libc
void init() is
// allocate a char ptr buffer for a C string:
var s = GC_malloc(LENGTH);
// copy a C string literal into the buffer
strncpy(s, `Hello World!`, LENGTH);
// ensure it's null terminated:
[s + LENGTH - 1] = 0c;
// print the result:
IO.Std.out.println( "s is: '" + s + "'" );
si
si
si
s is: 'Hello World!'
site design and content copyright (C) jeek 1995-2010  
[
13132
]