A Scripting Language for Web, Linux and Windows

A Scripting Language for Web, Linux and Windows

Native function calling

V1 can call native functions of dynamic libraries (.dll, .so).

Load dynamic link library

// Load the libZ library and return module number
// Parameter true means, that libz is a native dynamic link library and no V1 module!
module dl ('libz.so'true);
if (!
module) {
  print (
"Module not found.");
  exit ();
}

Call a function

// Call the function "zlibVersion" with no parameters and return const char* (string)
version call (module"zlibVersion", [[], 's']);
Function/Arguments Return Description
call (number module, string function, array paramDef [, mixed arg1 ... ]) mixed Call a native function of a module loaded with dl() function. The array paramDef defines the parameters and return code of native funtion:
[[ 'type of param1' ... 'type of param N' ], 'type of return' ]

Types and corresponding C datatypes:

Parameter / Return Type Native C datatype V1 datatype Description
i int number Signed integer number
f float number Low precision floting point number (32 Bit)
d double number High precision floting point number (64 Bit)
s const char* or void* string 0 terminated string or buffer
p void* or unsigned int number Memory pointer or unsigned integer. Memory pointers can be used with memat() to read or memset() to write memory data. memref() return a reference pointer to the memory buffer of a V1 string.
To navigate throught the memory, the offset in constant _ALIGN can be used where the default byte align is defined
(4 on 32 Bit, 8 on 64 Bit versions of V1).
r void* &string Reference to V1 string which can be written by native function.
Enough buffer must be allocated with resize() or binformat() function.

src 
"String to compress with ZLib native function.";

// Make enough destination buffer 
dst ""
resize (dststrlen (src));

// The length of the desination buffer as binary string
len binformat (strlen (src));

// Call the native function which is defined as:
// int compress (void *dstBuf, int *dstLen, const char* srcBuf, int srcLen);
// dst and len are reference parameters and filled with binary data by native function.
ret call (module"compress", [['r''r''s''i'], 'i'], dstlensrcstrlen(src));
if (
ret===0) {
  
// Parse the binary length and truncate destination string
  
len binparse (len);
  
resize (dstlen);

  print (
"Compressed string: "dst);
}

Example 2


// Show a multibyte message box on Windows by calling two native functions
hDLLUser32 dl ('user32.dll'true);
hDLLKernel32 dl ('kernel32.dll'true);

function 
MultiByteToWideChar (src) {
  global 
hDLLKernel32;
  
dst "";
  
resize (dststrlen(src)*2+2); // Make enough buffer for wide char string
  
size call (hDLLKernel32"MultiByteToWideChar", [["i","i""s""i"'r','i'], "i"],  650010src, -1dststrlen(src)+1);
  if (
size>0)
    
resize (dstsize*2);  // Resize to correct length (byte aligned)
  
return dst;
}

function 
MessageBox (texttopic="Info") {
    global 
hDLLUser32;
    
call (hDLLUser32"MessageBoxW", [["p","s""s""i"], "i"], nullMultiByteToWideChar(text), MultiByteToWideChar (topic), 0|0x00000030);
}

if (
hDLLKernel32) {
    
MessageBox ("специальный символ");
}

See also enhanced example: Connect to MySQL database

back to Home

V1 Version 0.96 - Documentation generated Sat, 12 Oct 2019 09:24