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
  

It is possible to throw an ZException within a C++ function and catch it in CSL:

C++ function
------------
 
static ZString myCppFunc(ZCsl* csl)
{
  int argc = csl->get("argCount").asInt();
  if (argc == 2)
    ZTHROWEXC("%%% argcount must be 1 or 3");
  ...
} // myCppFunction
 
 
CSL program
-----------

#loadLibrary 'ZcSysLib.dll'
#loadLibrary 'ZcMyLib.dll'
 
main()
{
  try { myCppFunc(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 1 line(s):
argcount must be 1 or 3

The vice versa is also possible:

CSL Function
------------
 
test(const mode)
{
  if (mode < 0 || mode > 3) {
    const exc[2] = {
      'error in test():',
      'invalid mode:'+mode
    };
    throw exc;
  } // if
  ....
} // test
 
 
C++ Function
------------
 
void cppTest()
{
  try {
    ZCsl csl;
    csl.loadScript("test.csl");
    ZString ret = csl.call("cppTest.exe","test",1,"5");
    ....
  } // try
  catch (const ZException& err) {
    for (int i = err.textCount()-1; i >= 0; i--)
      cerr << err.text(i) << endl;
  } // catch
} // cppTest
  Copyright © IBK Landquart Last revision: 27.05.2002 << Back  Top  Next >>