Between CSL and C

C Scripting Language
Reference Manual
Version 4.4.0

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using the CSL executive
Language
   Comments
   Numbers
   Literals
   Var and const
   Operators
   Statements and blocks
   Program flow
   Trace facility
   Exception handling
      Between CSL and C
      Between CSL and C++
   Functions
   Predefined identifiers
Directives
System library
String library
Math library
Regular expression lib.
File library
Database library
Async Communication
Registry/Profile handling
Windows control
C API
C++ Class Interface
CSL links
  

Errors emitted by ZCslSetError will raise an exception in the calling CSL code:

C function
----------
 
ZExportAPI(void) myFunc(ZCslHandle csl)
{
  char buf[20];
  long bufsiz;
  int argc;
 
  bufsiz = sizeof(buf);
  if ( ZCslGet(csl, "argCount", buf, &bufsiz) ) return;
  argc = atoi(buf);
  if (argc == 2) {
    ZCslSetError("Error in myFunc:");
    ZCslSetError("%%% argcount must be 1 or 3");
    return;
  } // if
  ...
} // myFunc
 
 
CSL program
-----------
 
#loadLibrary 'ZcSysLib'
#loadLibrary 'ZcMyLib'
 
main()
{
  try { myFunc(1, 2); }
  catch (var exc[]) {
    sysLog('caught exception with '+sizeof(exc)+' line(s):');
    for (var i = 0; i < sizeof exc; i++)
      sysLog(exc[i]);
  } // catch
} // main
 
 
Output when running:
--------------------
 
caught exception with 2 line(s):
Error in myFunc:
%%% argcount must be 1 or 3

Exceptions thrown in CSL will be returned as error by ZCslCall:

CSL Function
------------
 
test(const mode)
{
  if (mode < 0 || mode > 3) {
    const exc[2] = {
      'error in test():',
      'invalid mode:'+mode
    };
    throw exc;
  } // if
  ....
} // test
 
 
C Code
------
...
static char *args[] = { "5" };
errs = ZCslCall(csl, module, "test", 1, args);
if (errs) {
   // errs will be 1 and ZCslGetError(csl, 0,...)
   // will return 'invalid mode:5'
...
  Copyright © IBK Landquart Last revision: 27.05.2002 << Back  Top  Next >>