Frequently Asked Questions About Embedded Scripting and Math Expression Parsing
Q: Which operating system does Embedded Ch support? Embedded Ch runs where Ch is available. It supports Windows, Linux, Mac OS X, Solaris, HP-UX, FreeBSd and QNX.
Q: Can you show me a simple sample to run Embedded Ch code? Below is a sample C code embedch1.c to run Ch script embedch1.ch. The program embedch1.c needs to be compiled and linked with the Embedded Ch library to call the APIs Ch_Initialize(), Ch_RunScrip(), and Ch_End() in the library. Q: How to call a function in a Ch script from the binary application? There are many different ways to functions in a Ch script. Belwo is a sample C code embedch2.c in which API Ch_CallFuncByName() calls function func() in the Ch script embedch2.ch. The arguments x, N, and a are passed from the binary space to the script space.
Please read chapter 5 section
"Calling Back C Functions in the Main Program from Ch Space"
in Embedded Ch User's Guide located at
CHHOME/docs/embedch.pdf.
Below is a sample C code embedch3.c with a C function func() called from a Ch script embedch3.ch. The API Ch_DelcareFunc() makes the function func() available in the script space. The aruments from the script space are passed to the interface function func_chdl() first in the binary space, which in turn calls the binary function func(). The interface function func_chdl() can be automatically generated using the utilities provided in the Embedded Ch SDK. Q: Is Ch a bytecode interpreter? Can I generate bytecode for Embedded Ch? Ch is not a bytecode interpreter. It parses C/Ch/C++ scripts and generates symbol tables in memory, then runs the code from the memory directly. All information in scripts are available in the hosting application. The advantage for using Ch scripts is that Ch script is usually smaller than its corresponding bytecode, it can save bandwidth for you significantly. Q: How to direct Ch 2D/3D graphical output into a specific window in Embedded Ch? For 2D/3D graphical plottings, you need to have Ch Professional and Embedded Ch Professional instead of Ch Standard and Embedded Ch Standard. You can save a graphical output in a file first, then display the plot in a specific existing window. We have an example below to show you how it can be done. http://www.softintegration.com/products/sdk/embedch/plotexample/ Q: I am interested in parsing and evaluating math expressions with Embedded Ch. I don't need a fully embedded scripting language. Can it be done easily with Embedded Ch? Yes. It can be easily done. If you only use expressions, your functions, and built-in mathematical functions listed in the header file math.h in Embedded Ch, you don't need to distribute Ch run time files. Some API functions are listed below: Ch_ExprParse(), Ch_ExprEval(), Ch_ExprCalc(), Ch_AppendRunScript(), Ch_SetVar() Below is a sample code that demonstrate how this can be done. Winplot is an example of how Embedded Ch is used to calculate mathematical expressions entered by the user through a graphical user interface in Windows. The mathematical expression is then plotted. Q: It appears that Ch provides a makefile-based build system that uses special commands such as dlcomp and dllink, which is helpful for cross-platform development. Can we use Visual Studio's project based system or alternate systems such as qmake (Qt's make system)? We provide commands dlcomp and dllink which can be used in Makefile so that you can use the same makefile for building applications with Embedded Ch across different platforms with different C/C++ compilers. You can also build applications with Embedded Ch using your preferred IDE. Please check section "Executables in Windows Using Visual .NET" and section "Building Executables in Windows Using Visual C++ 6.0" in Chapter 1 in Embedded Ch SDK User's Guide at CHHOME/docs/embedch.pdf. It describes what header files and libraries you need to add for the project. You can apply the same header files and libraries for any other alternate systems like qmake. You can also find samples for using both VC++ 6.0 and VC.NET projects for Embedded Ch. The sample project files embedfuncmain.dsw and embedfuncmain.vcproj for interface C functions can be found in the directory CHHOME/toolkit/demos/embedch/ref/embedfuncmain. The sample project files embedclassmain.dsw and embedclassmain.vcproj for interface C++ classes are located in directory CHHOME/toolkit/demos/embedch/ref/embedclassmain. Q: What compilers does Embedded Ch support? Does it support Borland or MingW compiler? Both Borland and MingW compilers are supported. The tested and workable compilers for Embedded Ch SDK are as follows.
Q: I got the compiler error in Windows MFC application, how to resolve it? When linking an application against Microsoft Foundation Class (MFC), you might get the following error message. nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc nafxcw.lib(olelink.obj) : error LNK2001: unresolved external symbol __mbctype Q: Does Embedded Ch support multi-threading? Yes. It allows multi Ch interpreter running simultaneously. In our demos, we have samples using POSIX pthread and Windows thread. Q:How to abort an embedded Ch thread?
Embedded Ch provides API Ch_Abort(), which can be called
to abort a running Ch thread.
It can be also called to abort the execution of a Ch
script in a different thread.
Q: Does Embedded Ch support debugging? Yes. Embedded Ch has extensive support for callback and debug functions. In our Embedded Ch User's guide, it has a detailed example for using debugging API in Embedded Ch. Q: Does Embedded Ch have memory leak? We have gone through extensive testing and there is no memory leak in Embedded Ch. Q: Can I parse Ch scripts to check if there are syntax errors before I execute them? Yes. Embedded Ch provides solutions to handle complicate cases. For example, it can parse a script in the memory as well as loading and parsing a script from a file. Please Please check functions Ch_ParseScript(), Ch_ExprParse() and Ch_AppendParseScript about parsing scripts. Q: How can I redirect the stdout or stderr from Embedded Ch to a file? You can use Embedded Ch API Ch_Reopen() to redirect the output stream for stdout and stderr from Ch into a file that can be used as a log file or opened via your C application. Q: Can I run Ch script in either memory or from a file? Yes. You can use Ch_AppendRunScript() to execute Ch code in memory and use Ch_RunScript() or Ch_AppendRunScriptFile() to execute Ch code in a file. Q: How can I run Ch function from memory and get the returned value? The following is an example about how to call Ch function, pass arguments, and return a value. The Ch function runs a loop with 10000 iterations. Q: Does Ch support C++ class inheritance? Can Embedded Ch interface with C++ class with inheritance? Ch itself doesn't support inheritance. However, Ch can interafce with inherited class in C++ space. For example, you have the C++ code below: Q:Does Ch support some kind of reflection mechanism that will enable it to look up class methods (i.e: all the information exists in the chf file)? How to use reflection mechanism to get e class or struct name? Yes. The following APIs can be used. Q:I use Embedded Ch and have a C program that launches Ch scripts in Windows. This C code calls function popen() to capture the output and displays it through GUI. I see the output of the C program, but not the output from Ch scripts. How to display the output from the stdout stream from both C and Ch scripts? You can put setbuf(stdout, NULL) in all Ch scripts or in a header file for Ch scripts. All of the output from Ch scripts will be unbuffered and displayed in a correct sequence. Q: I have many functions in a C library. Is there a convenient way to expose these functions to Ch scripts without manually writing wrapper function files with file extension .chf? Yes. Ch SDK has an utility called c2chf, you can use it to generate wrappers automatically. You can find more information about c2chf in chapter 3 in Ch SDK User's Guide at CHHOME/docs/chsdk.pdf. Q: I don't want my end users to install a standalone Ch separately. How can I distribute my application with Embedded Ch? How can I distribute wrapper function files with file extension .chf? How can I distribute minimized run time environment with features of C/C++ only? Your end users do not have to install standalone Ch in order to use your application with Embedded Ch. After obtaining the authorization, you need to distribute files located in the directory CHHOME/toolkit/embedch with your applications. This directory contains the Ch runtime environment. Typically, it will be placed under the home directory of your application. Your application program should set the Embedded Ch home directory properly in option.chhome argument before calling Ch_Initialize().
If you want to distribute minimized run time environment
with features of C/C++ only, you may only need to distribute
the following files from CHHOME/toolkit/embedch. It will reduce
the size of run time environment significantly.
If you have function files (.chf) used to interface with binary functions, you need to distribute them along with your application. You may put these function files in a separate directory under your application home directory such as C:/MyApplication/chffile. Then add the directory in the system variable _fpath in file config/chrc under the home directory of Embedded Ch. The file CHHOME/toolkit/embedch/config/chrc contains an example on how to add a directory. However, if you use Embedded Ch for parsing and processing math and expressions, you may not need to distribute Embedded Ch runtime environment, namely Embedded Ch Standard or Professional Edition. You can find more detailed information about distribution of your applications with Embedded Ch in section "Distributing Embedded Ch in Your Applications" of the first chapter in Embedded Ch User's Guide. ChExcel is a sample distribution of an application with Embedded Ch, but without a standalone Ch. Q: How to specify a user-defined paths to the Ch files and DLL? You can specify the paths _path, _lpath, _ipath etc in the file in either the system startup file EMBEDDED_CHHOME/config/chrc or individual user's startup ~/_chrc. More about _path, _lpath and _ipath can be found in Ch User's Guide (chguide.pdf). You can look over the index in the Ch User's Guide. For, the command search paths can be modified in a startup file as follows: Q: Does Embedded Ch change the windows PATH? Yes. When you run applications with Embedded Ch, it will change the system PATH. The default setting is: Q:Is it royalty free to distribute a Ch run-time environment? It depends. Please click here for more details. Q: Where can I find more information about Embedded Ch? You can find the following two links helpful. Embedded Solution and Embedded Ch product. To use Embedded Ch, you need to install Ch Standard or Ch Professional, and Embedded Ch SDK. Then you can find Embedded Ch SDK User's Guide at CHHOME/docs/embedch.pdf. Q: Can I have Embedded Ch user's references about using Embedded Ch? Sure. Below are comments from some users of Embedded Ch.
Q: Can I try a sample application with Embedded Ch? You can download and try ChExcel. ChExcel is freeware and it is a Microsoft Excel add-in. It allows Excel speadsheets to be manipulated through C/C++ scripts. Q: How to disable floating point exception handling under Borland C/C++ compiler or CBuilder? Borland environment builds applications and DLL with floating point exceptions enabled, while Microsoft does the opposite. In order to work arround the issue it is possible to disable FP exception as shown below. Q: I would like to use Embedded Ch, what is the price? Please click here for more details. |