37 lines
907 B
C
37 lines
907 B
C
//-*-c-*-
|
|
// flf.c, Call a foreign-language function
|
|
|
|
// export zklRoot=/home/ZKL
|
|
// clang -O -fPIC -I $zklRoot/VM -c -o flf.o flf.c
|
|
// clang flf.o -L$zklRoot/Lib -lzkl -shared -Wl,-soname,flf.so -o flf.so
|
|
|
|
#include <string.h>
|
|
|
|
#include "zklObject.h"
|
|
#include "zklMethod.h"
|
|
#include "zklString.h"
|
|
#include "zklImports.h"
|
|
|
|
// strlen(str)
|
|
static Instance *zkl_strlen(Instance *_,pArglist arglist,pVM vm)
|
|
{
|
|
Instance *s = arglistGetString(arglist,0,"strlen",vm);
|
|
size_t sz = strlen(stringText(s));
|
|
return intCreate(sz,vm);
|
|
}
|
|
|
|
static int one;
|
|
|
|
DllExport void *construct(void *vm)
|
|
{
|
|
if (!vm) return (void *)ZKLX_PROTOCOL; // handshake
|
|
// If this is reloaded, nothing happens except
|
|
// construct() is called again so don't reinitialize
|
|
if (!one) // static items are zero
|
|
{
|
|
// do some one time initialization
|
|
one = 1;
|
|
}
|
|
return methodCreate(Void,0,zkl_strlen,vm);
|
|
}
|