In python, I can use eval() to execute user entered code in my program.
Is there anything similar I can do in Groovy? I want to have a SWING UI textbox where the user enters a piece of code that I want to execute?
Thanks,
Hari
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
There are multiple ways of running Groovy (from both inside Java and Groovy):
http://groovy-lang.org/integrating.html
The quickest method however (for simple scripts), is probably to use the Eval class:
http://groovy-lang.org/integrating.html#integ-eval
Which would let you do something like:
See this page from more examples:
http://mrhaki.blogspot.com/2009/11/groovy-goodness-simple-evaluation-of.html