Monday, February 28


Embedded Magic

I spent a couple of days last year working on a simple scripting language for Minx (beyond what is already possible with templates, which support loops, conditions, and subroutines). 

I had looked at just using Python (but Python sandboxing is broken and long since deprecated), JavaScript (but none of the embeddable JavaScript libraries were production-ready) and Lua (but LunaticPython appeared to have been abandoned at the time, didn't compile out of the box, and once I patched it, didn't really work with multi-threaded applications).

I had a complete parser and was starting to implement the runtime system (I did say that it was a simple scripting language) when I discovered that some other people had picked up LunaticPython, dusted it off, and fixed all the issues I had with it.

Which is why Lua will be the official Minx scripting language.  (Or at least, the first such.)

This blog is turning into a wall of text, so here's a picture of a defenseless crab being menaced by a giant Sayaka Isoyama.

Now, Lua is neat language, clean and simple but very capable.  It's not used much for developing applications because its standard library is much smaller than, say, Python's, but for augmenting an existing application, it's perfect.  It's interpreted, but it's pretty snappy even so.  It's actually faster than Python, which means that user scripting could in theory outrun the application itself.  (With the proviso that it takes roughly a microsecond to make a function call from Lua back to Python to retrieve shared data.  Oh, and I'm currently running Minx under Psyco rather than standard Python, which gives it a roughly 2x speed increase.)

Recently there's been significant development on LuaJIT, which is exactly what you'd expect.*  And it's apparently pretty awesome - comparable in performance to C for numeric code, with no code changes.

And someone** has picked up LunaticPython, dusted it off, adapted it to LuaJIT, and renamed it Lupa.  Which means in theory that user scripting could run rings around the application itself.  Not that there's anything wrong with that.

If you want to read about the minutiae of Just In Time Compilers until your head falls off, go here.

The only problem remaining is that there's no first-class .Net implementation of Lua, or not that I know of.  That's a problem for Miko; if you want to be able to preview a post on your site before syncing it to the server, and your site uses Lua scripting, then Miko has to support Lua.  LuaInterface looks to be the way to go there, but I haven't had a chance to try it yet.  The advantage I have with Miko is that I don't have to worry about performance of the core engine to anywhere near the same degree: If there's a slow script gumming up the works, it's your slow script, since it only hosts your blog.

Oh, and yeah, the plan is for Miko to have a scripting IDE built in.  Nothing hugely complex, but a decent code editor and a very basic debugger.

* A Just In Time compiler for Lua, just as Pysco is a JIT for Python.
** Someone named Stefan Behnel.

Posted by: Pixy Misa at 02:06 AM | Comments (3) | Add Comment | Trackbacks (Suck)
Post contains 532 words, total size 4 kb.

1 I think you've gone mad, but in an awesome way.

Also, I hope you meet a success similar to DOM+JS more than what scripted mIRC produced.

Posted by: Pete Zaitcev at Monday, February 28 2011 08:45 AM (9KseV)

2 Just wait until I add PHP support...  To the desktop client. wink

Posted by: Pixy Misa at Monday, February 28 2011 09:40 AM (PiXy!)

Hide Comments | Add Comment

Comments are disabled. Post is locked.
48kb generated in CPU 0.0399, elapsed 0.1157 seconds.
56 queries taking 0.1092 seconds, 333 records returned.
Powered by Minx 1.1.6c-pink.