Lunatic Python: Lua Inside Python, and Python Inside Lua
labix.org
labix.org
Way back when I played minecraft, we used a mod called OpenComputers, which was basically a lua-based terminal inside minecraft. It had a package manager, python, and pastebin for managing code. It was really neat! Still think it's funny that it was Java -> Lua -> Python.
Ended up using that to "3d print" objects to make png murals using a python backend, some jad/sed/awk/grep, lua, and a python "frontend". The 3d printer allowed specifying color, but since you could also specify colors by x/y/z coords of other blocks, I decided to constrain the project to color definitions that way. Because masochism, probably. Wasn't easy, since block definitions were sometimes in java, hence jad. By FAR the jankiest project I've ever worked on, but damn did I learn a lot along the way, including some machine learning basics.
Posts like the OP's make fun projects like mine possible!
Fork https://github.com/bastibe/lunatic-python , with a commit in 2020, says:
> Sadly, Lunatic Python is very much outdated and won't work with either a current Python or Lua. [] This is an updated version of lunatic-python that works with Python 2.7-3.x and Lua 5.1-5.3 I tried contacting the original author of Lunatic Python, but got no response.
This fork has forks. https://pypi.org/project/lunatic-python-universal/ says:
> This package is a fork of the original from http://labix.org/lunatic-python, updated to support Python 3, and forked again from https://github.com/bastibe/lunatic-python to release to PyPi and support newer versions of Lua and macOS Homebrew-installed Lua.
http://lua-users.org/wiki/BindingCodeToLua also mentions https://pypi.org/project/lupa/ and https://pypi.org/project/ffilupa/ .
import browser
from browser import window
document = window.get_prop('document')
document_body = document.get_prop('body')
document_body.set_prop('textContent', browser.jsstr('hi'))
[0]: https://rustpython.github.io/demo/https://github.com/brython-dev/brython
I especially like the fact that I can have the same language in the backend and the front-end and it doesn't have to be JS, which I hate with passion.
My main beef with Lua is the absence of ‘null’, which means I can't write middleware doing transformations on data without a schema—i.e. API requests and processing, for which Lua would be great otherwise.
Lua’s equivalent is `nil` - I assume that doesn’t do what you need? How would the behaviour of `null` differ from Lua’s `nil`?
Lua's ‘nil’ is not a value, it's a void in which all undefined variables swim. Specifically, if you assign nil to a table field, you can't know what fields the table has unless you have that schema beforehand.
and https://www.wired.com/2015/11/null/
There was even something in this vein on the front page.
Secondly, even if there's another, more special value, that can't be conflated with a string (Lua does support some kind of user-values that are distinct from any built-in types)—it still leaves a question of how different modules handle that. In fact, different modules like CJSON already do this—but what if I decode JSON with CJSON's null value and need to encode XML when the XML module has its own null value? I'd need to walk the data and convert from one to the other.
Well, some modules do support a common value denoting null: https://github.com/moteus/lua-null
But by now why not just have this value in the language, since various modules need it anyway for interoperability with other systems?
I heard even that there were attempts at deciding on such a value for a new version of Lua, only with some bunk name like ‘undefined’, which is actually the opposite of what ‘null’ is.
Actually, I can already see ways this is going to be good for Lua adoption on some of my projects, but also simultaneously threatening, since it means a 'more widely accepted language' could predispose continuing in Lua.
Actually, this is going to be very weird, once word gets out that Pythons batteries are up for grabs in certain circles ..