Skip to main content
GameDev.net gamedev.net
🔒 Locked

A game implementation of Lua?

Started by Downsider Feb 1, 2011 at 2:18 AM 7 replies 2.8k views
Original Post
Downsider
Downsider
I want to implement Lua to handle weapons and certain things for the player in my game.

Frankly, I feel overwhelmed and I'm not quite sure where to start.

I'd also have to pass objects to the Lua script to be modified in the script, and BOOST is out of the question, so that limits my choice in libraries.

Can anybody help me out here? I have no idea where to start.
M4573R
M4573R

I want to implement Lua to handle weapons and certain things for the player in my game.

Frankly, I feel overwhelmed and I'm not quite sure where to start.

I'd also have to pass objects to the Lua script to be modified in the script, and BOOST is out of the question, so that limits my choice in libraries.

Can anybody help me out here? I have no idea where to start.


When I made my first attempt at binding Lua to one of my games, I used the latest version of Lunar from the Lua website. It's a single header file that lets you bind simple classes to Lua. It also lets you push objects to Lua once you've written the glue code. It doesn't support inheritance or anything fancy, but again, it worked for my purposes great. Each of my objects would have a list of scripts to run for it, and for each I would just push the object to Lua with the variable name "This" and then call the script. The script would then use the bound member functions on the "This" object. I did the same thing with my system singletons, except I just used Lunar to push them to Lua as globals on startup. If you don't need to do much, it works very nicely and simply . I modified the Lunar header so that it didn't require class constructors to take a lua_state because I was constructing all my objects on the c++ side.

Here is the link: http://lua-users.org...indingWithLunar
For learning to use Lua, everything I need was right here: http://www.lua.org/pil/
mrwonko
mrwonko
Why is Boost out of question? Luabind is a nice library for exposing C++ stuff to Lua, but it requires Boost.
Katie
Katie
Yeah second the concept of doing life management on the C++ side. It's much easier.
Downsider
Downsider
Thanks for all the suggestions, Lunar looks great for what I need.

Thanks a lot, guys!
AverageJoeSSU
AverageJoeSSU

[quote name='Downsider' timestamp='1296526691' post='4767767']
I want to implement Lua to handle weapons and certain things for the player in my game.

Frankly, I feel overwhelmed and I'm not quite sure where to start.

I'd also have to pass objects to the Lua script to be modified in the script, and BOOST is out of the question, so that limits my choice in libraries.

Can anybody help me out here? I have no idea where to start.


When I made my first attempt at binding Lua to one of my games, I used the latest version of Lunar from the Lua website. It's a single header file that lets you bind simple classes to Lua. It also lets you push objects to Lua once you've written the glue code. It doesn't support inheritance or anything fancy, but again, it worked for my purposes great. Each of my objects would have a list of scripts to run for it, and for each I would just push the object to Lua with the variable name "This" and then call the script. The script would then use the bound member functions on the "This" object. I did the same thing with my system singletons, except I just used Lunar to push them to Lua as globals on startup. If you don't need to do much, it works very nicely and simply . I modified the Lunar header so that it didn't require class constructors to take a lua_state because I was constructing all my objects on the c++ side.

Here is the link: http://lua-users.org...indingWithLunar
For learning to use Lua, everything I need was right here: http://www.lua.org/pil/
[/quote]

I did the exact same thing, its lightweight and works well. good luck


------------------------------ redwoodpixel.com
mokaschitta
mokaschitta
I haven't tried it yet, but I plan on using it in the future as a slim alternative to luabind:
http://code.google.com/p/oolua/
NicoG
NicoG
I would suggest AngelScript. I was struggling with LUA too, but with Angescript implementing Scripting is quite easy. It is well and understandable documented.
There is even a forum for it here .
And because AngelScript is OOP itself, it is more convinient to export your classes to it. Last time I checked, LUA did not have OOP by default you had to mess with tables. May have changed though.
If you say "pls", because it is shorter than "please", I will say "no", because it is shorter than "yes"
http://nightlight2d.de/
_the_phantom_
_the_phantom_
1) Lua NOT LUA. That's like saying PYTHON or ANGELSCRIPT

2) OOP != classes. Lua's 'do things via tables' is just as valid OOP as C++'s "classes' (in fact it's probably more so and it's certainly more flexible).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.