Sign in to follow this  

Scripting my game with LUA

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...)

Share this post


Link to post
Share on other sites

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this