News for hackers. Stuff that matters.
Re:MicroPython by pansa2 on Sunday August 16, 2020 @02:31PM (#24180001)
MicroPython seems to be heavily focused on embedded systems.

Is there any support for embedding it within an application, i.e. as a replacement for Lua? Or is there another lightweight Python implementation (or Python-like language) that supports this?

Re:MicroPython by albertzeyer on Sunday August 16, 2020 @03:41PM (#24180594)
What is lightweight for you?

I bundled the official Python (CPython 2.7, that was some years ago; but I don't think CPython 3 would be so much different) in an application (http://albertz.github.io/music-player/), and the whole MacOSX app zip file ended up at 11 MB. This includes my whole app + whole CPython 2.7 (including all stdlib) + extra Python libs (all the ObjC/Cocoa bindings, which I use for the GUI). I find this is still pretty ok.

(Still much smaller than Qt, wxWidgets, Electron, or whatever else there is. But maybe this comparison is unfair.)

The scripts to build CPython suitable for embedding it into an app are here: https://github.com/albertz/python-embedded/ (But this is not really updated, and so far for CPython 2.7, not CPython 3. But this is not really so difficult anyway. These scripts are mostly such that you have it as a Xcode project and also compiles on iOS.)

I think Dropbox does the same, as far as I remember.

Re:MicroPython by ngcc_hk on Sunday August 16, 2020 @06:04PM (#24181752)
Wow. Very interesting. Hope it can be upgraded to 3
Re:MicroPython by as-j on Sunday August 16, 2020 @02:59PM (#24180235)
Why not just use Lua? :) yes I get it, Lua is yet another language to your stack.

But so is MicroPython. We were looking for a higher lever than C language for an embedded Linux system* and one engineer was massively in favor of MicroPython. But it’s not python, it’s based on 3.4 so it’s like python but not. It has its own rules and particularities. When I hire a new engineer I’d rather say “here read this book and learn this language” than “ok we have this python work alike/fork, now learn all these exceptions.”

It’s also not a good fit for embedded Linux system programming like Lua is.

*) this is an in production, professional environment, which decision will have years of legacy support and ramifications.

Re:MicroPython by marktangotango on Sunday August 16, 2020 @04:54PM (#24181216)
“Not quite python” is a subtle point many people miss and indeed can be an issue. Third party library support is also huge, does micropython support the cpython library ecosystem? In this case the plethora of lua libraries readily available via luarocks is a huge advantage.
Re:MicroPython by jononor on Sunday August 16, 2020 @04:02PM (#24180736)
If it is a desktop-type application, just use CPython itself? It has good embedding support since forever, and is the "Python" that most people know and are used to. Best compatibility with existing code, for third party libraries and tooling. https://docs.python.org/3/extending/embedding.html

Many applications in the graphics space embed or otherwise allow Python scripting. Some open source examples are: Blender, FreeCAD, GIMP, Inkscape.

Re:MicroPython by toastal on Sunday August 16, 2020 @03:04PM (#24180275)
Why would you want to replace Lua in this space? At least why replace with another dynamically typed, imperative scripting language, but without tail-call optimization? What would be the gain?
Re:MicroPython by pansa2 on Sunday August 16, 2020 @08:50PM (#24182710)
I'd prefer to use a language that's more orthodox than Lua, e.g. one with class-based OOP and separate lists & maps, rather than tables-for-everything.

I'd also like a language that puts more emphasis on backwards-compatibility than Lua. Sure, everyone complains about the Python 2 => 3 transition, but there have been 3 new major versions of Lua since the release of Python 3.

Re:MicroPython by toastal on Sunday August 16, 2020 @10:53PM (#24183419)
Lua versioning is a really weird thing I'll give you that. I find class-based OOP a point against a language rather than for it, but there's already a huge chunk of languages that compile to/add types to Lua (https://github.com/hengestone/Lua-languages), with Wu and Amulet looking intriguing to me.
Re:MicroPython by londons_explore on Sunday August 16, 2020 @05:19PM (#24181420)
> Why would you want to replace Lua in this space?

The crowd of people who speak Lua is pretty different than those who speak Python.

I would guess the Lua crowd to be older, more experienced, but smaller.

The Python crowd is much bigger, and includes people who dabble in coding rather than those of us who do it for a living.

It depends on the user base of your application, but I can totally see why Python would be a better embedding language for users to use. You build the product for the users after all.

In todays world, I'd make some V8 bindings and get users to use javascript, because that's even easier to embed, has a bigger ecosystem via nodejs/npm, and has a probably larger userbase... It's got a nice remote debugger/UI too, which is quite a plus if you're expecting inexperienced users to write plugins/modules for you.

Re:MicroPython by toastal on Sunday August 16, 2020 @10:47PM (#24183401)
The Lua crowd includes kids learning to code because they want mods in Minecraft and other games. Sometimes I see Lua suggested a a first language over JavaScript because it's much smaller and has less warts (plenty of warts exist though). Can you even use V8/SpiderMonkey in the same way as LuaJIT?
Re:MicroPython by wizzwizz4 on Monday August 17, 2020 @07:13AM (#24186088)
You mean Minetest, right? Minecraft doesn't have native modding support, let alone Lua modding support.
Re:MicroPython by detaro on Monday August 17, 2020 @07:16AM (#24186106)
Various, including some very popular, mods for Minecraft include Lua. I assume that's what they are referring to.
Re:MicroPython by mottosso on Sunday August 16, 2020 @04:17PM (#24180881)
I was wondering the same as the parent, and in my case it's library support (e.g. NumPy) and compatibility/familiarity in the space (VFX) where Python is everywhere and Lua is unheard of.
Re:MicroPython by otterlicious on Sunday August 16, 2020 @04:39PM (#24181100)
If you want NumPy support in particular you basically have to use CPython.

The only other implementation that really supports it is PyPy which is not in any sense more lightweight.

Re:MicroPython by matt_trentini on Sunday August 16, 2020 @09:30PM (#24182956)
Although much smaller in scope than NumPy, MicroPython (and CircuitPython) now have the ulab library which provides similar fast array manipulations:

https://github.com/v923z/micropython-ulab

Re:MicroPython by drran on Monday August 17, 2020 @03:29AM (#24184854)
So, use Python instead of MicroPython.
Re:MicroPython by tomlogic on Sunday August 16, 2020 @08:49PM (#24182708)
Digi International embedded it into some of their XBee wireless radios (802.15.4-based and Cellular models) to allow customers to run an on-device application without compromising any certifications for the radio portion of the firmware. Easier than needing to design hardware with an additional host processor and work out the serial communications between that host and the radio module.

While MicroPython was designed to be "bare iron", it wasn't overly difficult to port it to run as a separate task inside the XBee firmware, and connect it up with internals for I/O and file system access. These are ARM Cortex products with firmware sizes in the area of 500KB to 700KB.

Re:MicroPython by vsgzusnex on Sunday August 16, 2020 @02:42PM (#24180098)
It's slightly more constrained for performance but maybe Starlark is what you're looking for? https://github.com/bazelbuild/starlark
Re:MicroPython by stinos on Monday August 17, 2020 @02:56AM (#24184691)
We've been running it like that for multiple desktop applications for years. So it's supported in the sense that it works but depending on what you do with it exactly it needs some boilerplate code which mostly means copy-pasting some parts from one of the main.c files for the different ports, no big deal. Creating bindings is another point which requires boilerplate code but that's no diferent from other scripting embeddings.
Re:MicroPython by HALtheWise on Sunday August 16, 2020 @02:53PM (#24180186)
It should be supported, although I don't have any good examples of people doing it. There is work being put into making micropython into a powerful webasm package for frontend development.

https://github.com/micropython/micropython/tree/master/examp...

Re:MicroPython by matt_trentini on Sunday August 16, 2020 @09:28PM (#24182937)
Yes, and this has recently attracted some focus. Take a look at the example for embedding MicroPython:

https://github.com/micropython/micropython/tree/master/examp...

Re:MicroPython by pjc50 on Sunday August 16, 2020 @04:14PM (#24180850)
There used to be Jython, for embedding inside JVM apps, but the 2/3 transition killed it.