Difference between revisions of "Lianja/SDK C API"

From Lianjapedia
Jump to: navigation, search
m (Text replace - "lianjaapi.h" to "lianja_api.h")
Line 4: Line 4:
 
The main source file for the DLL must include the following four elements:
 
The main source file for the DLL must include the following four elements:
  
====The include file "dbapi.h"====
+
====The include file "lianja_api.h"====
  
  
Line 12: Line 12:
  
  
====The API_SHARED_FUNCTION_TABLE structure====
+
====The LIANJA_EXTENSION_TABLE structure====
 
Used to define the 'C' functions and classes included in the library:
 
Used to define the 'C' functions and classes included in the library:
  
  
 
<code lang="c">
 
<code lang="c">
// API function address table
+
static struct LIANJA_EXTENSION_TABLE lianja_extension_table[] =  
static struct API_FUNCTION_ADDRESS_TABLE *api_function_address_table = NULL;
+
 
+
// Add all functions to this structure as follows:
+
// Name, C Function Name , Type
+
//
+
// Make sure the last entry is NULL.
+
//
+
static struct API_SHARED_FUNCTION_TABLE api_function_table[7] = {
+
{"schar", "fnSamplesCharacter", API_FUNCTION},
+
{"stype", "fnSamplesType", API_FUNCTION},
+
{"slog", "fnSamplesLogical", API_FUNCTION},
+
{"snum", "fnSamplesNumeric", API_FUNCTION},
+
{"sopen", "fnSamplesOpen", API_FUNCTION},
+
{"myclass", "clsMyClass", API_CLASS},
+
{NULL, NULL, -1}
+
} ;
+
</code>
+
 
+
 
+
====The initAPI() function====
+
 
+
 
+
<code lang="c">
+
// This function is used to define function addresses for API calls.
+
// C++ example
+
extern "C" int WINAPI EXPORT initAPI(struct API_FUNCTION_ADDRESS_TABLE *function_address_table)
+
 
{
 
{
api_function_address_table = function_address_table;
+
  {"example_character", "fnExampleCharacter", API_FUNCTION},
return 0;
+
  {"example_type", "fnExampleType", API_FUNCTION},
}
+
  {"example_logical", "fnExampleLogical", API_FUNCTION},
</code>
+
  {"example_numeric", "fnExampleNumeric", API_FUNCTION},
 +
  {"example_execute", "fnExampleExecute", API_FUNCTION},
 +
  {"example_evaluate", "fnExampleEvaluate", API_FUNCTION},
 +
  {"example_class", "clsMyClass", API_CLASS},
 +
  {NULL, NULL, -1}
 +
};
  
  
====The getFunctions() function====
+
//================================================================================
 +
// *** REQUIRED *** only once in each extension library and *must* come after the
 +
// declaration for LIANJA_EXTENSION_TABLE.
 +
//--------------------------------------------------------------------------------
 +
LIANJA_INIT_API;
  
<code lang="c">
 
// This function is used to return the function names of the API.
 
// C++ example
 
extern "C" struct API_SHARED_FUNCTION_TABLE *getFunctions(void)
 
{
 
return api_function_table;
 
}
 
 
</code>
 
</code>
  
  
 
==Using the 'C' functions and classes==
 
==Using the 'C' functions and classes==
Shared libraries are loaded using the [[SET LIBRARY|SET LIBRARY TO <library> [ADDITIVE]]] command or the [[REQUIRE()]], [[REQUIRE_ONCE()]], [[INCLUDE()]] or [[INCLUDE_ONCE()]] functions. By default library files are accessed from the directory defined by the [[DB_LIBDIR]] environment variable.
+
Shared libraries are loaded automatically by placing directives in the extensions.ini file in the Lianja extensions directory.
  
If full path information is specified, the shared library files can be loaded from other directories, e.g.
+
Here is an example of the extensions.ini file:
  
<code lang="recital">
+
<code>
// pdf.dll is in the DB_LIBDIR directory
+
[windows]
set library to pdf
+
library=example.dll
   
+
[linux]
//mylib.dll is in C:\Program Files\Lianja\Myapplibs\myapplibs
+
#library=example.so
set library to "C:\Program Files\Lianja\Myapplibs\mylib"
+
[mac]
 +
#library=example.dylib
 
</code>
 
</code>
  
 
The function [[LOADLIBRARY()|LOADLIBRARY(<library>)]] can also be used to load additional shared libraries.  The name of the shared library file including the full path and file extension must be specified.
 
 
The [[SET LIBRARY|SET LIBRARY TO]] or [[RELEASE LIBRARY|RELEASE LIBRARY <library>]] commands are used to close all or specified shared libraries.
 
  
 
The [[LIST PROCEDURE]] and [[DISPLAY PROCEDURE]] commands include loaded shared library function names in their listings and the [[LIST CLASSES]] and [[DISPLAY CLASSES]] commands include loaded shared library class names in their listings.
 
The [[LIST PROCEDURE]] and [[DISPLAY PROCEDURE]] commands include loaded shared library function names in their listings and the [[LIST CLASSES]] and [[DISPLAY CLASSES]] commands include loaded shared library class names in their listings.

Revision as of 23:56, 15 April 2013

'C' functions and classes defined in dynamic link libraries (DLLs) can be used on Windows.

Defining the C functions

The main source file for the DLL must include the following four elements:

The include file "lianja_api.h"

#include "lianja_api.h"


The LIANJA_EXTENSION_TABLE structure

Used to define the 'C' functions and classes included in the library:


static struct LIANJA_EXTENSION_TABLE lianja_extension_table[] = 
{
   	{"example_character",	"fnExampleCharacter",		API_FUNCTION},
   	{"example_type",		"fnExampleType",			API_FUNCTION},
   	{"example_logical",		"fnExampleLogical",			API_FUNCTION},
   	{"example_numeric",		"fnExampleNumeric",			API_FUNCTION},
   	{"example_execute",		"fnExampleExecute",			API_FUNCTION},
   	{"example_evaluate",	"fnExampleEvaluate",		API_FUNCTION},
   	{"example_class",		"clsMyClass",				API_CLASS}, 
   	{NULL,					NULL,						-1}
};
 
 
//================================================================================
// *** REQUIRED *** only once in each extension library and *must* come after the
// declaration for LIANJA_EXTENSION_TABLE.
//--------------------------------------------------------------------------------
LIANJA_INIT_API;


Using the 'C' functions and classes

Shared libraries are loaded automatically by placing directives in the extensions.ini file in the Lianja extensions directory.

Here is an example of the extensions.ini file:

[windows] library=example.dll [linux]

  1. library=example.so

[mac]

  1. library=example.dylib


The LIST PROCEDURE and DISPLAY PROCEDURE commands include loaded shared library function names in their listings and the LIST CLASSES and DISPLAY CLASSES commands include loaded shared library class names in their listings.

Loaded shared library functions can be used in the same way as an internal function. Loaded shared library classes can be used in the same way as system classes.