BoxLang 🚀 A New JVM Dynamic Language Learn More...

BoxLang Jython Support

v1.1.0+2 BoxLang Modules

⚡︎ BoxLang Jython Support

|:------------------------------------------------------:  |
| ⚡︎ B o x L a n g ⚡︎
| Dynamic : Modular : Productive
|:------------------------------------------------------:  |
Copyright Since 2023 by Ortus Solutions, Corp
www.boxlang.io | www.ortussolutions.com

 

This module allows you to execute python in BoxLang via Jython. This is a very powerful feature that allows you to execute python code in your BoxLang scripts. It also allows you to create python modules and classes that can be used in your BoxLang scripts by using the jythonEvalFile( path ) function.

Usage

You can execute python code in your BoxLang scripts by using the jythonEval( code ) function. Here is an example:

jythonEval( "print('Hello World')" );

You can also evaluate python code from a file by using the jythonEvalFile( path ) function. Here is an example:

jythonEvalFile( "path/to/file.py" );

You can also create python modules and classes that can be used in your BoxLang scripts. Here is an example:

# mymodule.py
def hello():
	return "Hello World"
jythonEvalFile( "path/to/mymodule.py" );
var result = jythonEval( "hello()" );
print( result );

You can also use the <bx:jython>{python code}</bx:jython> tag to execute python code in your BoxLang scripts. Here is an example:

<bx:jython variable="result">
print("Hello, World!")

# Addition
num1 = 5
num2 = 10
sum = num1 + num2
print("Sum:", sum)

# Subtraction
num3 = 8
num4 = 3
difference = num3 - num4
print("Difference:", difference)

# Multiplication
num5 = 4
num6 = 6
product = num5 * num6
print("Product:", product)

# Division
num7 = 15
num8 = 3
quotient = num7 / num8
print("Quotient:", quotient)

# Modulo
num9 = 17
num10 = 5
remainder = num9 % num10
print("Remainder:", remainder)

# Exponentiation
base = 2
exponent = 3
result = base ** exponent
print("Result:", result)
</bx:jython>

Bindings

We will automatically bind all the variables in your variables scope into the engine bindings via JSR223. You can then use them as native variables in your python code.

variables.name = "Luis Majano";
jythonEval( "print(name)" );

Result

Each execution produces a result which is a structure with the following keys:

  • engine : A reference to the engine
  • globalScope : A reference to the global scope of JSR223
  • engineScope : A reference to the engine scope of JSR223

Ortus Sponsors

BoxLang is a professional open-source project and it is completely funded by the community and Ortus Solutions, Corp. Ortus Patreons get many benefits like a cfcasts account, a FORGEBOX Pro account and so much more. If you are interested in becoming a sponsor, please visit our patronage page: https://patreon.com/ortussolutions

THE DAILY BREAD

"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.


Unreleased

1.1.0 - 2024-08-26

  • Updated build libraries
  • Upgraded internal libraries for build
  • Upgraded Jython to 2.7.4

1.0.0 - 2024-06-17

  • Support eval and bindings
  • First iteration of this module

$ box install bx-jython

No collaborators yet.
     
  • {{ getFullDate("2024-06-17T21:44:37Z") }}
  • {{ getFullDate("2024-08-26T20:41:45Z") }}
  • 418
  • 303