[deleted]

My forever project: IronLua

I guess one of my favourite forever projects is IronLua, a Lua implementation running on .NET.

I tried to jump on the DLR (Dynamic Language Runtime) bandwagon just to see it wither away. Also, the added complexity seemed to incur non-neglibile runtime costs (see IronJS / Jurassic, and related perf comparison of these two JavaScript runtimes for more information). This caused me to reconsider using the DLR at all.

Also, since Lua is often used as a game scripting language, I also had to consider whether I wanted to implement a compiler or an interpreter. An interpreter would be very handy for environments in which runtime code compilation is not possible (XNA, low/mid trust sandboxes, etc).

The interpreter seemed easier, but that quickly changed once I had a look at the original Lua C code, which is the closest thing to hand-made obfuscation you can find in the interwebs (I guess it's extremely clever, but for the life of me I'm still having troubles understanding how stack frames are constructed and parameter / return values work).

The interpreter would also make coroutines easier to implement. Implementing them as a compiled artifact is a mess; the only way to produce non-local jumps in .NET would be using exceptions, and that's a performance nightmare.

My codeplex repository has a working top-down-operator-precedence parser for Lua 5.2 in F#.

I learned a few things along the way, so it's not all time wasted. First, that Lua is a very cool language, with loads of interesting features (metatables and coroutines above all). Second, I implemented a working TDOP, and that's cool for nerds that love lexers and parsers like me. I also learned a bit of C along the way; I never liked going too low level, but I have to admit that the raw power you can get out of a machine by using C is great.

Posted Jan 28, 2013, 11:38 AM UTC

74
Blecki•

I also dabbled with the DLR - until I realized there wasn't actually any 'magic'. Underneath, it's just a Dictionary<String,Object>.

1
rainweaver•

It kind of boils down to that. There's however a fairly intricated runtime method overload resolution based on caching that, while very smart on paper, seem to disrupt call site performance

1
pnpbios•

I may have to use this for a game I'm working on.

1
rainweaver•

we have two choices: an interpreter, or a compiler (both is just wishful thinking :) ).

I also have the basis of a Lua bytecode interpreter in C#, but as I mentioned, I always had a hard time untangling the original C source.

1