Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tcltest.cpp: 定义应用程序的入口点。
- //
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tcl.h>
- Tcl_Interp *interp;
- int PowObjCmd(ClientData clientData, Tcl_Interp *interp, int objc,
- Tcl_Obj *CONST objv[]) {
- Tcl_Obj *resultptr;
- double x, y, result;
- int error;
- if (objc != 3) {
- Tcl_WrongNumArgs(interp, 2, objv, "Usage : pow x y");
- return TCL_ERROR;
- }
- error = Tcl_GetDoubleFromObj(interp, objv[1], &x);
- if (error != TCL_OK)
- return error;
- error = Tcl_GetDoubleFromObj(interp, objv[2], &y);
- if (error != TCL_OK)
- return error;
- result = pow(x, y);
- resultptr = Tcl_GetObjResult(interp);
- Tcl_SetDoubleObj(resultptr, result);
- return TCL_OK;
- }
- int Example_Init() {
- interp = Tcl_CreateInterp();
- if (interp == NULL) {
- return 1;
- }
- Tcl_CreateObjCommand(interp, "pow111", PowObjCmd, (ClientData)NULL,
- (Tcl_CmdDeleteProc *)NULL);
- return TCL_OK;
- }
- int main() {
- int ret;
- Example_Init();
- Tcl_Eval(interp, "puts {hello world!!!}");
- Tcl_Eval(interp, "set a 123");
- Tcl_Eval(interp, "puts [expr $a +23]");
- Tcl_Eval(interp, "puts [pow111 2 3]");
- ret = Tcl_EvalFile(interp, "test.tcl");
- if (ret == TCL_ERROR) {
- printf("Tcl script error :%d", interp->errorLineDontUse);
- // DataLog::insertERROR(logdata);
- }
- printf("ok %d\n", ret);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement