I got tired of writing boilerplate imports, so I built Block: Run Python, JS, and Lua in a single file
๐ก The Problem: The Import / Glue Code Headache A while ago, I was practicing importing modules across different projects. I wanted to use Python for its rich data science libraries and Node.js for its async web performance. Normally, if you want Python to pass a simple calculated array or dictionary to JavaScript, you have to: Spin up a local FastAPI / Flask server or write to a temporary JSONโฆ
The author, frustrated with the time-consuming boilerplate code required when importing modules across different projects, set out to create a solution. They envisioned a system where Python, JavaScript, and Lua could be written in a single file, seamlessly sharing data between languages.
This led to the creation of Block Engine, a runtime environment that allows users to write code in native language blocks. The language blocks are separated by tags, such as "py", "js", "lua", "php", and "server". The engine then automatically serializes and passes variables between these blocks through an in-memory State Pipeline.
The author demonstrates the process by writing a block file named "demo.blkp". The Python block prepares a dataset and prints a message, while the JavaScript block calculates the average of the dataset. In the Lua block, the calculated average and a bonus value are used to compute a final score, which is then printed.
To run the file, the user simply executes the command "block demo.blkp". The output shows the messages printed by each language block, and confirms that the State Pipeline synchronized the variables across the three runtimes in just 320 milliseconds.
One of the key features of Block Engine is the Zero-Glue State Pipeline, which enables variables declared in one language to be instantly accessible in others without the need for manual JSON parsing. The engine also supports native ecosystem compatibility, allowing users to access existing pip, npm, and luarocks libraries directly.
Additionally, Block Engine offers zero-install NPX execution, allowing users to run .blkp files directly from the terminal using the command "npx block-engine-runner demo.blkp". Modular imports are also supported, enabling users to import other block files and even define custom runtimes with specific commands.
The Block Engine project is open source and released under the MIT license, encouraging community contributions and improvements. The author invites feedback and suggestions from the DEV community on which additional languages they would like to see integrated into the system.
Written by urgent.news from Dev.to's reporting โ not their text. Machine-written โ may contain errors; check the original before relying on it.