Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:20:51+00:00 2026-05-27T12:20:51+00:00

I am writing a DSL for expressing flow (original I know) in groovy. I

  • 0

I am writing a DSL for expressing flow (original I know) in groovy. I would like to provide the user the ability to write functions that are stored and evaluated at certain points in the flow. Something like:

states {
    "checkedState" {
        onEnter {state->
           //do some groovy things with state object
        }
    }
}

Now, I am pretty sure I could surround the closure in quotes and store that. But I would like to keep syntax highlighting and content assist if possible when editing these DSLs. I realize that the closure COULD reference artifacts from the surrounding flow definition which would no longer be valid when executing the closure in a different context, and I am fine with this. In reality I would like to use the closure syntax for a non-closure function definition.

tl;dr; I need to get the closure’s code while evaluating the DSL so that it can be stored in the database and executed by a script host later.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:20:51+00:00Added an answer on May 27, 2026 at 12:20 pm

    I don’t think there is a way to get a closure’s source code, as this information is discarded during compilation. Perhaps you could try writing an AST transformation that would make closure’s syntax tree available at runtime.

    If all you care about is storing the closure in the database, and you don’t need later access to the source code, you can try serializing it and storing the serialized form.

    Closure implements Serializable, and after nulling its owner, thisObject and delegate attributes I was able to serialize it, but I’m getting ClassNotFoundException on deserialization.

    def myClosure = {a, b -> a + b}
    
    Closure.metaClass.setAttribute(myClosure, "owner", null)
    Closure.metaClass.setAttribute(myClosure, "thisObject", null)
    myClosure.delegate = null
    
    def byteOS = new ByteArrayOutputStream()
    new ObjectOutputStream(byteOS).writeObject(myClosure)
    def serializedClosure = byteOS.toByteArray()
    
    def input = new ObjectInputStream(new ByteArrayInputStream(serializedClosure))
    def deserializedClosure = input.readObject() // throws CNFE
    

    After some searching, I found Groovy Remote Control, a library created specifically to enable serializing closures and executing them later, possibly on a remote machine. Give it a try, maybe that’s what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing a Jabber client that uses Twisted Words. I would like to know an
I'm writing a DSL where the + operator is strictly numeric, like some other
I'm writing an F# dsl for SQL ( http://github.com/kolosy/furious ). A select statement would
I a writing a DSL to generate parsers for bioinformatics flat files. I would
I writing a DSL that executes as a Script ; it has various classes
I'm writing a small gem, and I want to define a DSL-like method, pretty
I'm writing a Java program that requires its (technical) users to write scripts that
I writing a DSL in IronPython. Overloading operators in C# and using them in
I am writing a simple little DSL for specifying constraints on messages, and Have
Writing htaccess that allows me to remove index.php from the URL can confuse search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.