Scripting my game with LUA
Hello,
I would like to know how people designs a game engine, to embedding a scritping language in it. For example, say you have enemies, the players, etc... where do you define this game clases (that dependes on every game) in the C++ Game code? in LUA code?, and how do they interact?.
Thanks in advance,
HexDump.
This really depends on how much you want to expose to scripts.
My suggestion is to build a system of classes that you instantiate from LUA scripts and provide functions to alter the data in the scripts.
I've done this with a program that builds GUI windows from scripts. It works well. I don't see how it could not work for a game.
My suggestion is to build a system of classes that you instantiate from LUA scripts and provide functions to alter the data in the scripts.
I've done this with a program that builds GUI windows from scripts. It works well. I don't see how it could not work for a game.
The engine exposes some functions and then your game entities hook into them. This is because native functions like collisions, math, etc. need to be fast. You could also put that into scripts but the game engine usually does these things because things like pvs, bsp, etc. are inside the engine. What you can also do for things that need to be done fast is to create a dll for them and give that to the modders who then modify those dlls or write new ones. You can combine that with scripts for less frequent parts of game. So dlls for fast code and scripts for slow code for example. I tried Lua and it's different from C++. You can create objects in the script and also invoke engine functions. AngleScript which is like C/C++, lets you define game objects in dlls or engine and expose them to the script. I think it's easier to use than the lua stack method. AS has functions and data in script and I think aggregates are coming next. Take a look at squirrel which is based on lua but deals with GC better and is streamlined lang.
Typically people use the scripting language to alter the game code, not run it, per se. Usually you bind a C/C++ function to a scripting function so that in the script you have access to the C/C++ function, but the real code is executed in the lower level language (C/C++).
It really depends on the level of scriptability you want and what you want to do outside your source code and compiles. Also, what you'd want modders, and other people to do with your game.
If you're using LUA with C++, you'll run into the problem of trying to expose classes and their members to Lua (lua only natively allows you to bind plain C functions, not C++ members). So you might want to look into tolua++ or luabind if using class members is essential to you (it shouldn't be required ever, but people seem to really like to do it that way...)
It really depends on the level of scriptability you want and what you want to do outside your source code and compiles. Also, what you'd want modders, and other people to do with your game.
If you're using LUA with C++, you'll run into the problem of trying to expose classes and their members to Lua (lua only natively allows you to bind plain C functions, not C++ members). So you might want to look into tolua++ or luabind if using class members is essential to you (it shouldn't be required ever, but people seem to really like to do it that way...)
"Creativity requires you to murder your children." - Chris Crawford
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement