Embedding Lucee as a Scripting Engine

I’m trying to embed lucee as one of several scripting engines to use in a Kotlin / +Java application and I’m running into an issue with output handling.

It seems that the Lucee / CFML engine implementations assume you are using it as a CLI if you are creating them directly and I need to figure out how to capture output into a string.

The following code is a simple version of what I’m trying to do:

    val scriptEngine = CFMLTagEngineFactoryImpl().scriptEngine

    try {
        println(scriptEngine.javaClass.canonicalName)

        val output = StringWriter()
        scriptEngine.context.writer = output

        println("----- OUTPUT ------------------------------")
        println(output.buffer)
        println("----- /OUTPUT ------------------------------")

        val value = scriptEngine.eval("<cfoutput>#Now()#</cfoutput>")

    } catch (exception:Exception) {
        exception.printStackTrace()
    }

In the code above, you can see where I’m setting the writer in the script context, which has no affect on the results, but with all the other scripting engines actually captures the output for me to a string that I can then use.

I am willing to fix this myself in the lucee code and submit a pull request, but I could use some advice to speed things up. My only other option is to wrap a savecontent or function around it all, but it will still output tons of blank lines into my console.

I would appreciate any advice or suggestions!

I’m making some progress and have gotten the Lucee repository forked, cloned, and building each sub-project. Now I’m digging in to figure out where and how requests find the output stream they will use if it is not the output stream provided by the ScriptContext.

This would save a lot of time if someone could point me the right direction. I should be able to take care of the rest as getting familiar with the code is going to take the longest and this is the key part of it.

Thanks in advance for any help others can offer.