Products > Ch SDK
Ch SDK
Introduction
Documentation
Ch SDK is included in Ch Professional and Student Editions.

Ch SDK allows C/C++ scripts (Ch scripts) to interface C/C++ binary libraries. It allows Ch scripts to access global variables or call functions in compiled C/C++ libraries such as static libraries, shared libraries or Dynamically Linked Libraries (DLL). Ch scripts can callback Ch functions from C/C++ libraries. There is no distinction between the interpreted and compiled code.

Ch SDK
Using Ch SDK to build dynamically loaded libraries
to interface C/C++ scripts with C/C++ libraries.

If you want to invoke Ch scripts, functions, or variables from C/C++ binary applications at the runtime, please try Embedded Ch.

Ch SDK requires neither any modification of your C/C++ source code and libraries, nor re-compilation of your applications and libraries. It enables you to have a powerful C interpreter to control your systems and applications across different platforms. Your binary modules can readily be executed interpretively and shared with other users with Ch SDK. It creates a greater benefit for code reuse.

Another advantage of using Ch SDK is that you don't need to recompile even if the binary dynamically linked libraries are updated. Once you created a Ch package or toolkit for the library, you do not need to update the Ch package or toolkit if the interface and function prototypes are not modified, even though you have modified the internal code of functions in the library. You can simply overwrite the existing .DLL or .so libraries. The Ch package or toolkit can automatically access the modified library. It saves your time for maintenance of Ch packages or toolkits.

You will find Ch SDK an ideal solution in the following situations:

  • You want to have your large existing C/C++ library accessed from Ch scripts for rapid prototyping.
  • You want to make Ch scripts run faster, and make the frequently called underlying C/C++ functions a binary library.
  • You want to protect your intellectual property and source code from being revealed.
Ch SDK allows you to enjoy a truly powerful scripting language environment to interface with C/C++ libraries. Ch SDK can handle complicated C functions such as pointer to function with different argument, variable argument list, variable length arrays (VLAs), which are difficult or impossible to handle by other scripting languages.

Typically, Ch SDK can access the following components in C/C++ libraries:

  • Regular C functions.
  • C functions with arguments of pointer to function, and the pointer to function can either have argument or no argument.
  • C functions with arguments of pointer to function and the pointer to function may have different arguments which are of different data types.
  • C functions with arguments of class, pointer to class and pointer to pointer of class.
  • C functions with return values of pointer to function, and the pointer to function can either have argument or no argument.
  • C functions with variable argument lists.
  • Complex numbers.
  • Variable length arrays.
  • Struct, union, enum data types.
  • Class in C++.
  • Global variables.
Ch SDK is easy to use and yet powerful. It provides a utility to generate wrappers for Ch to interface your C/C++ libraries automatically. You may not need to write code to have your most job done. To handle complicated cases such as pointer to functions, Variable Length Arrays(VLAs) and classes in C++, Ch SDK ships with easy to use APIs, many templates and examples for you to get started quickly to write wrapper functions.

Ch SDK also provides you with extended functionalities in interfacing with C/C++ libraries. For example, you can take advantage of the string type and computational array to interface with C/C++ libraries. It will make your Ch script easy to use without losing the power of C/C++ libraries.

It is easy to cause the memory leak for passing the argument to get the returned value, or call a function with a return value that is allocated in your C/C++ wrapper. Ch provides a convenient memory management utilty for users to have a good control and track for the memory allocation and deallocation. Ch SDK has been effectively used to interface with industry standard C libraries such as POSIX, C LAPACK, X/Motif, Win32, GTK+, OpenGL, ODBC, OpenCV, NI-DAQ, NI-Motion, etc. Its power and flexibility have been demonstrated.

Please click the link to download a simple example. This demo example is also available at CHHOME/toolkit/demos/SDK/chapters/runc2chf_dll/chf/ directory when Ch is installed.

An example of using Ch SDK is Ch K8055 Package. It contains the source code for building Ch interface to the Velleman USB interface board K8055. In this example, a simplified header file k8055d_c.h is used to generate Ch function files *.chf and dynamical loaded library libk8055d_c.dl.

Another example of using Ch SDK is Ch PNG Package. It contains the source code for building cross platform Ch interface to the PNG library. In this example, the Ch function files and dynamical loaded library are generated from the original header file png.h directly.