3 ms·
is there anything inherent in the Lua Language that makes it a good match for an in-game-engine programming language?
by whitten 10y ago
is there anything inherent in the Lua Language that makes it a good match for an in-game-engine programming language?
- careersuicide 10y agoNot so much in the language itself (I'm not a fan), but the process of embedding Lua and pushing data into a Lua context and pulling data out of a Lua context is so simple the first time I got it working I thought, "Surely I'm missing something, it can't be this easy." The ease of integration with C or C++ makes it worth strongly considering when you need an embedded scripting language. But, as I alluded to, Lua as a language is pretty awful. Lua's tables are an abomination in my eyes. A few years ago I started a simple RPG game engine that uses Lua[0] as its scripting language. I never got very far with it but considering I had zero clue how to even begin approaching the problem when I started I'm pretty happy with how far I got before I lost interest. [0]: https://github.com/seaneshbaugh/SDL03 https://github.com/seaneshbaugh/SDL03
- ufo 10y agoWhat do you think is so bad about Lua tables? They have some unintuitive aspects (such as not being able to store `nil`) but in the end being able to use tables for everything considerably simplifies the language. I'd hardly consider that an abomination.
- danbolt 10y agoPersonally, I think Lua's widespread use in game programming stems from it's performant design, paradigm flexibility, and the fact that it's not hard to embed into an existing project. There are other languages that have this mindset too, but I think Lua's been able to capture enough mindshare to be quite sticky in the industry. I've met quite a few game programmers that don't like parts of Lua, and wish there was something that was closer to C++ rather than JavaScript.
- abhorrence 10y agoHave you seen Squirrel? [0] It does have a lot in common with Lua, but does have a bit more of a C++ feel to it. [0] http://www.squirrel-lang.org/ http://www.squirrel-lang.org/
- ludamad 10y agoIn addition to the other points, it's a very vanilla and unopinionated language. You can use it to match the style of your engine without much friction.
- catwell 10y agoI would say several things: - Its small size (the PUC Lua codebase is about 15000 lines of C and compiles to about 250 kB). PUC Lua is the reference implementation of Lua, as opposed to e.g. LuaJIT. - Its portability: PUC Lua is written in Clean C, the intersection of ANSI C and C++ 98. That makes it trivially portable to any architecture that matters in games. - Its performance. PUC Lua is already faster than most popular scripting languages and uses less memory. If you need extra performance you can switch to LuaJIT and come close to C on a lot of codebases. - The syntax is designed for data description, which makes it a very good language to implement DSLs for lots of things. Also the parser is very efficient so you can store data in Lua files. - Coroutines. They let you propose an API to users (scripters) that appears synchronous but actually runs in an asynchronous fashion. - The language is made to be embedded. Its C API is a central point of the design. The interpreter is reentrant so you can run several instances in threads without any problem. All of this made Lua very popular in the game industry, along with its use in pretty famous games (initially Grim Fandango, then lots of others including World of Warcraft).
- corysama 10y agoLua is a very simple yet very powerful language. I like to say it is the best of JavaScript without the warts of JavaScript. Lua is one of the best performing interpreted languages around. If you use LuaJIT, it competes well with the best JS jits. It also has a small memory footprint and reasonably controllable GC pauses. Lua is very easy to integrate into C/C++ projects. It is easy to write a debugger for Lua. Like everything else in Lua, debugging capabilities are libraries that can just as easily be invoked in Lua itself or in C. IMHO, very overlooked is that Lua is a batteries-optional language. It comes with a small standard library that keeps it's footprint and capabilities reasonable. If you want more, there are lots of open source libraries you can add. But, more importantly, almost all of the standard libs can be stripped out and Lua will still function just fine. Don't want your scripts to do file IO? Don't load the IO library.