A better language for Lua?

Given that I work in the gaming industry, I am always fascinated with what people will do with Lua.

The Terra project struck me as an interesting investigation into building a better low-level counterpart to Lua that is not C.

The key claim to fame for Terra is that it is a dynamic language that has near native performance because it is less dynamic than Lua.

The idea behind Terra and Lua is to use Lua as a scripting language for rapid prototyping and Terra for optimized components without having to deal with the messiness of dropping into C. What makes this particular system intriguing is that the Terra functions are in the same lexical environment as the Lua functions which means they inter-operate seamlessly while having the Terra functions execute outside of the Lua VM… as per their abstract:

High-performance computing applications, such as auto-tuners and domain-specific languages, rely on generative programming techniques to achieve high performance and portability. However, these systems are often implemented in multiple disparate languages and perform code generation in a separate process from program execution, making certain optimizations difficult to engineer. We leverage a popular scripting language, Lua, to stage the execution of a novel low-level language, Terra. Users can implement optimizations in the high-level language, and use built-in constructs to generate and execute high-performance Terra code. To simplify meta-programming, Lua and Terra share the same lexical environment, but, to ensure performance, Terra code can execute independently of Lua’s runtime. We evaluate our design by reimplementing existing multi-language systems entirely in Terra. Our Terra-based auto-tuner for BLAS routines performs within 20% of ATLAS, and our DSL for stencil computations runs 2.3x faster than hand-written C.

I don’t have enough experience with Lua to offer any insight as to whether this is a good idea… but it bounced along the internet superhighway so I’ll try to take a look.

Reading the paper, I realized there is a lot more there in terms of the sophistication and science of the challenge of integrating these two different languages. Okay… I’ll have to read and noodle.

2 thoughts on “A better language for Lua?

    1. kostadis roussos Post author

      Golang is an awesome language, but like all awesome languages it has the “you must write everything from scratch” property.

      What is interesting about terra is that it allows me to import the entire C library into the lexical scope of the lua language while retaining the C execution environment and the lua execution environment.


Leave a Reply

Your email address will not be published. Required fields are marked *