Advertisement

Examples of Lua?

Started by May 10, 2011 08:31 PM
5 comments, last by ddn3 13 years, 6 months ago
Hey everyone, I hope this is the right place to post this.

I've currently been learning and getting used to Lua and I'm loving it. I've tried many different languages and Lua is the only one that I am really enjoying. But I was wondering, what is Lua acctually used for? I know it's been used in lots of major games and you can create cool add ons in WoW or SCII, but what is it used for in another type of game? I've heard it's used for small things, but what exactly are those small things?


I hope someone can help! Thanks.
Pretty much anytting. A good example of somehting that might be scipted (doesn't have to be lua) is AI/UI. I use lua for my AI, for my UI and to handle some of my game states. You could write the majority of the game in it if you really wanted to. You could use it for initialisation, just to store data. I have a single lua script that gets run, which in turn runs other scripts, sets up locations of resources and so on. Its great because you don't have to recompile your code to make changes.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Advertisement
I wrote a description of how I'm using Lua in my current game in my journal here. I use it slightly differently than I used to when I first started with it. Once upon a time, I implemented the main "guts" of my games in C++, and only called Lua functions for things such as AI functions, trigger actions, and so forth. Now, though, the bulk of my game sits in Lua, and I only call into C++ for things that need to run very efficiently: rendering, path-finding, collision detection, etc....

Outside of Goblinson Crusoe, I use Lua very extensively for my all-purpose, general-use experimentation and prototype language. For instance, I use it when experimenting with procedural generation. In this journal post I include a link to a binary build of my general-purpose tool. It is a Lua command-line interpreter with my own extensions built in to it and exposed via tolua. The build includes scripts for the Minecraft-style level generation system I tinkered with, described in this journal post.

Lua is extremely useful, both as a scripting/configuration tool, and as a standalone language.
Many games are entirely written in Lua (excluding the game engine code).
Thanks for the replies!

I was thinking of this 2D game idea which is actually very basic and I wanted to use C++ with Lua for it. So I would use C++ for the things like Collision Detection, Game Menus, Character Movement and then use Lua for shooting (like a bullet), power ups, AI, UI, etc. ?

I would prefer to do almost all of the game in Lua, the only reason I'm using C++ is so I can use Lua within the game :P
I ended up using Lua in my game/engine for data files. I wanted them to be human-writable, so instead of using horrible XML I now have things like:


entities = {
player = {
prefab = "prefabs/player.nspf",
pos = "0 10.1 50"
}
}


A prefab is what I call a blueprint for an entity. Eventually I'll have a way to "compile" data files into a binary form. But leaving them as Lua for now has another benefit: you can write code in your data files. Recently I added the ability for trees to go transparent if they block the view. To test it I wanted a bunch of trees, so I wrote a function to create the trees and just called it a bunch of times to make a row of them.
Advertisement
If your target platform is PC, LuaJit 2.0 + FFI interface is fast enough to do it all in Lua now... Though be aware programming in a dynamic language like Lua is different than C++ which is much more structured and static.. Creating a C DLL interface to give LuaJit + FFI direct access to the low level stuff, you have the flexibility of Lua + the absolute speed of C. Basically its a game changer. Good Luck!

-ddn

This topic is closed to new replies.

Advertisement