Ejemplo n.º 1
0
static int JimAioOpenCommand(Jim_Interp *interp, int argc,
        Jim_Obj *const *argv)
{
    const char *mode;
    const char *filename;

    if (argc != 2 && argc != 3) {
        Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?");
        return JIM_ERR;
    }

    mode = (argc == 3) ? Jim_String(argv[2]) : "r";
    filename = Jim_String(argv[1]);

#ifdef jim_ext_tclcompat
    /* If the filename starts with '|', use popen instead */
    if (*filename == '|') {
        Jim_Obj *evalObj[3];

        evalObj[0] = Jim_NewStringObj(interp, "popen", -1);
        evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1);
        evalObj[2] = Jim_NewStringObj(interp, mode, -1);

        return Jim_EvalObjVector(interp, 3, evalObj);
    }
#endif
    return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode);
}
Ejemplo n.º 2
0
int Jim_EvalObjBackground(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
{
    Jim_EventLoop *eventLoop = Jim_GetAssocData(interp, "eventloop");
    Jim_CallFrame *savedFramePtr;
    int retval;

    savedFramePtr = interp->framePtr;
    interp->framePtr = interp->topFramePtr;
    retval = Jim_EvalObj(interp, scriptObjPtr);
    interp->framePtr = savedFramePtr;
    /* Try to report the error (if any) via the bgerror proc */
    if (retval != JIM_OK && retval != JIM_RETURN && !eventLoop->suppress_bgerror) {
        Jim_Obj *objv[2];
        int rc = JIM_ERR;

        objv[0] = Jim_NewStringObj(interp, "bgerror", -1);
        objv[1] = Jim_GetResult(interp);
        Jim_IncrRefCount(objv[0]);
        Jim_IncrRefCount(objv[1]);
        if (Jim_GetCommand(interp, objv[0], JIM_NONE) == NULL || (rc = Jim_EvalObjVector(interp, 2, objv)) != JIM_OK) {
            if (rc == JIM_BREAK) {
                /* No more bgerror calls */
                eventLoop->suppress_bgerror++;
            }
            else {
                /* Report the error to stderr. */
                Jim_MakeErrorMessage(interp);
                fprintf(stderr, "%s\n", Jim_String(Jim_GetResult(interp)));
                /* And reset the result */
                Jim_SetResultString(interp, "", -1);
            }
        }
        Jim_DecrRefCount(interp, objv[0]);
        Jim_DecrRefCount(interp, objv[1]);
    }
    return retval;
}
Ejemplo n.º 3
0
static LRESULT CALLBACK
JimWin32WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    int objc = 0, r;
    Jim_Obj *objv[16];
    Jim_Interp *interp = (Jim_Interp *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
    
    if (interp) {
        objv[objc++] = Jim_NewStringObj(interp, "WndProc", -1);
        switch (uMsg) {
            case WM_CREATE:
                //Jim_EvalObjVector(interp, objc, objv);
                break;
            case WM_COMMAND:
                objv[objc++] = Jim_NewIntObj(interp, HIWORD(wParam));
                objv[objc++] = Jim_NewIntObj(interp, LOWORD(wParam));
                objv[objc++] = Jim_NewIntObj(interp, lParam);
                r = Jim_EvalObjVector(interp, objc, objv);
                if (r == JIM_BREAK) return 0L;
                break;
        }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}