Skip to content

Adding a way to set the value of cling::utils::out #530

@MostafaNanticock

Description

@MostafaNanticock

We have a project that uses Cling to add the ability to do some actions using c++ at runtime.
currently the only way for us to show the user the result of executing a line such as int a = 5 is through std::cout.
The problem is, we are already using std::cout to print out many things like when logging is enabled in the application.

Take this output for example:

[INFO] started interactive c++ console
[cling]$ int a = 5
(int) 0
[cling]$ auto pvw = createNewPlotViewWindow()
[INFO] Creeating a new PlotViewWindow...
[INFO] Initializing OpenGL...
[INFO] Using OpenGL version 4.6
[INFO] OpenGL vendor: NVIDIA Corporation
[INFO] OpenGL renderer: Quadro T2000/PCIe/SSE2
[INFO] is OpenGLES: false
[INFO] OpenGL version: 4.6
[INFO] OpenGL options: 
    depthBufferSize 24,
    redBufferSize 8,
    greenBufferSize 8,
    blueBufferSize 8,
    alphaBufferSize 8,
    stencilBufferSize 8,
    samples 0,
    swapBehavior DoubleBuffer,
    swapInterval 1,
    colorSpace sRGBColorSpace
[INFO] OpenGL initialization finished
[INFO] Window initialization done
(PlotViewWindow *) 0x7dff598e91
[cling]$

and as you can see it becomes so frustrating especially when the user tries to scroll back through the terminal to check his previous inputs.
And after thorough examination of the Cling source code, it appears that the best solution would be for us to implement our own llvm::raw_os_ostream that we can then use as the default cling::utils::outs, cling::utils::errs and cling::utils::logs,
This would also allow us to integrate the logging library that we are using with Cling directly, so that it can simply log any cling message or error at real-time.

I don't know if there is any reason behind the choice for not having this functionality, and it's fairly easy to implement.
The simple solution that i can think of right now would be to add three functions in the form of:

namespace cling::utils {
    void setOuts(llvm::raw_ostream &newOuts);
    void setErrs(llvm::raw_ostream &newErrs);
    void setLog(llvm::raw_ostream &newLog);
}

I'd be happy to submit a pull request with this simple addition if any of the maintainers agreed on this proposed change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions