Why embed lua in a game engine?

I am creating a basic game engine from scratch and after compiling a list of functions common to other engines, one of the biggest things is the fact that they have a built-in scripting language such as lua or python.

My question is how the built-in scripting language is superior to just creating a header file (or something similar) that the user can include in a C ++ file that gives them access to many functions and states. I am sure that there is a very good answer, I have not yet stumbled upon it.

Also, why is it necessary, which languages ​​are used as lua for things like game engines?

+4
source share
3 answers

Lua is a much simpler language than C ++, and all you need to change is a text editor. This enables scripting events and / or high-level game logic in the hands of your designers and end users. Dynamic typing and garbage collection allows them to write very concise code that focuses on the logic of the game, and not on all homework at the system level that you get in C ++. It is also much easier for the sandbox.

Lua is a popular choice because it is a small portable hacked ANSI C code base; it is easy to integrate, expand, and, most importantly, for game developers - it has a minimum runtime (one of the fastest interpreted languages). It is also a great combination of easy-to-use / read / write syntax, but with powerful features like coroutines that can be very useful in games.

+6
source

The reason for enabling the scripting language is to allow users to customize the behavior without having to recompile the code.

I am not sure what you are asking in the second part of the question. Are you asking what other languages ​​are used, or are you asking in what ways languages ​​like Lua are used?

If you asked which other languages ​​are suitable for this, one of these languages ​​is Tcl. Tcl was designed from the ground up to be a built-in scripting language, and is very mature and reliable and easily recognizable by non-technical people.

As for which scripting languages ​​are suitable for ... configuration files, this is one way. Using a programming language rather than a text file with name / value pairs, it allows users to add logic to their startup files. For example, you might be allowing users to assign different functions to the keys on the keyboard; with a programming language, they can add different functions for different computers. Or, if you create the game as an RPG, perhaps you can assign different keys to different character classes. If you play as a mage, F12 may be a spell, but if you play as a f12 warrior, you may have to take the final blow.

There are many ways to use scripting languages ​​and many different languages. It all boils down to allowing your users to customize the behavior of the game without recompiling the code.

+2
source

You can find this article by the game developer, useful for understanding why built-in languages ​​are used.

http://www.grimrock.net/2012/07/25/making-of-grimrock-rapid-programming/

Another good reason: if you don’t share your source code with game users, and they are all C programmers, languages ​​like lua allow users to extend the game, for example, look at World of Warcraft.

+2
source

All Articles