lib/tcl-duktape.c
/*
 * Evaluate a Tcl string and return the result to JavaScript
 */
Evaluate a Tcl string and return the result to JavaScript
Evaluate a Tcl string and return the result to JavaScript
static duk_ret_t EvalTclFromJSWithInterp(Tcl_Interp *interp, duk_context *ctx, const char *returnType) {
    Tcl_Obj *evalScript, *evalResult, *dukStringObj;
    duk_idx_t numArgs, numRetVals;
    int tclRet;
    int idx;
    numArgs = duk_get_top(ctx);
    if (numArgs < 0) {
        duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", ERROR_INTERNAL_ARGS_ERROR);
        return(duk_throw(ctx));
    }
    evalScript = Tcl_NewListObj(0, NULL);
    for (idx = 0; idx < numArgs; idx++) {
        dukStringObj = Tclduk_JSToTcl(ctx, idx);
        if (!dukStringObj) {
            duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "%s", ERROR_INVALID_STRING);
            return(duk_throw(ctx));
        }
        tclRet = Tcl_ListObjAppendElement(interp, evalScript, dukStringObj);
        if (tclRet != TCL_OK) {
            duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", ERROR_INTERNAL_TCL_LAPPEND);
            return(duk_throw(ctx));
        }
    }
    for (idx = 0; idx < numArgs; idx++) {
        duk_pop(ctx);
    }
    tclRet = Tcl_EvalObjEx(interp, evalScript, 0);
    if (tclRet != TCL_OK) {
        duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", Tcl_GetStringResult(interp));
        return(duk_throw(ctx));
    }
    evalResult = Tcl_GetObjResult(interp);
    numRetVals = Tclduk_TclToJS(interp, evalResult, ctx, returnType);
    Tcl_FreeResult(interp);
    return(numRetVals);
}
static duk_ret_t EvalTclFromJSWithInterp ( Tcl_Interp * interp , duk_context * ctx , const char * returnType ) { Tcl_Obj * evalScript , * evalResult , * dukStringObj ; duk_idx_t numArgs , numRetVals ; int tclRet ; int idx ; numArgs = duk_get_top ( ctx ) ; if ( numArgs < 0 ) { duk_push_error_object ( ctx , DUK_ERR_ERROR , " " , ERROR_INTERNAL_ARGS_ERROR ) ; return ( duk_throw ( ctx ) ) ; } evalScript = Tcl_NewListObj ( 0 , NULL ) ; for ( idx = 0 ; idx < numArgs ; idx ++ ) { dukStringObj = Tclduk_JSToTcl ( ctx , idx ) ; if ( ! dukStringObj ) { duk_push_error_object ( ctx , DUK_ERR_TYPE_ERROR , " " , ERROR_INVALID_STRING ) ; return ( duk_throw ( ctx ) ) ; } tclRet = Tcl_ListObjAppendElement ( interp , evalScript , dukStringObj ) ; if ( tclRet != TCL_OK ) { duk_push_error_object ( ctx , DUK_ERR_ERROR , " " , ERROR_INTERNAL_TCL_LAPPEND ) ; return ( duk_throw ( ctx ) ) ; } } for ( idx = 0 ; idx < numArgs ; idx ++ ) { duk_pop ( ctx ) ; } tclRet = Tcl_EvalObjEx ( interp , evalScript , 0 ) ; if ( tclRet != TCL_OK ) { duk_push_error_object ( ctx , DUK_ERR_ERROR , " " , Tcl_GetStringResult ( interp ) ) ; return ( duk_throw ( ctx ) ) ; } evalResult = Tcl_GetObjResult ( interp ) ; numRetVals = Tclduk_TclToJS ( interp , evalResult , ctx , returnType ) ; Tcl_FreeResult ( interp ) ; return ( numRetVals ) ; }
Evaluate a Tcl string and return the result to JavaScript
Evaluate a Tcl string and return the result to JavaScript