Page 1 of 2
Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 7:20 pm
by corn
Hello,
I'm hoping that some of the more experienced Lua script integrators can offer some advice for me. I'm working on adding scripting support with Lua. I know there are a number of other scripting languages available, but I'd like to stick with Lua for now for the students. I understand how to call Lua functions from C++, and how to call C++ functions from Lua so far, but I'd like to wrap a large amount of the main Ogre functions for the kids to work with via scripting. However, before I begin, I'd like to make sure I'm doing it in a way that will work well in the long run. Therefore, I need your advice:
What's the overhead of using LuaBind or other binding libraries? Is it worth it, or would you recommend just plain Lua?
I'd like to expose as much of the Ogre library as possible to the scripting engine for the students to work with. Would you suggest wrapping each function individually? Has someone done this already in a clean efficient manner and made it available for the Ogre community? Or is there any easier way to wrap most of Ogre's main classes so they are all available (Entity, SceneNode, Light, Camera, etc.)?
Is it more advantageous in the long run to use classes in Lua scripts, or just stick with functions?
I've seen examples of the use of strings for referencing objects in scripts; however, is there a way to use pointers with Lua?
Thank you for your advice -- it may save me many hours of work!
Re: Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 7:31 pm
by nullsquared
corn wrote:
What's the overhead of using LuaBind or other binding libraries? Is it worth it, or would you recommend just plain Lua?
LuaBind's overhead is mostly compile-time and I highly suggest it when integrating Lua with a C++ project (and I suggest compiling Lua itself as C++ instead of C so you can use exceptions safely).
I'd like to expose as much of the Ogre library as possible to the scripting engine for the students to work with. Would you suggest wrapping each function individually? Has someone done this already in a clean efficient manner and made it available for the Ogre community? Or is there any easier way to wrap most of Ogre's main classes so they are all available (Entity, SceneNode, Light, Camera, etc.)?
I *really* don't suggesting wrapping Ogre for use with Lua. I see no benefit over simply using Ogre from C++, using it from Lua won't make it any more "friendly" because it was written with C++ in mind.
Is it more advantageous in the long run to use classes in Lua scripts, or just stick with functions?
Technically, Lua doesn't have classes. Though you can fake them (especially with LuaBind), and that makes interfacing with C++ much easier.
I've seen examples of the use of strings for referencing objects in scripts; however, is there a way to use pointers with Lua?
Yeah, it's called "user data".
Re: Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 7:41 pm
by corn
Thank you for the advice.
I *really* don't suggesting wrapping Ogre for use with Lua. I see no benefit over simply using Ogre from C++, using it from Lua won't make it any more "friendly" because it was written with C++ in mind.
It would seem useful for students to be able to use Ogre functions at run-time without having to recompile to tweak things. Any thoughts on this?
Re: Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 7:49 pm
by Fire Lancer
You might want to look at
http://www.pythonogre.com/
Re: Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 7:53 pm
by wacom
Re: Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 9:44 pm
by _tommo_
I would recommend to use Lua and scripting in general ONLY if you don't manage/write the lua part; meaning that you are on a team of 3+ peoples and/or you have an heavy mod support in mind...
You have to build and manage a wrapper layer; you have to keep in mind paradigm differences between C++ and Lua all the time; you add to your project tons of dependencies or tons of code.
And all of this to get a downpowered sandbox where you have to struggle to get to the C++ base you wrote yourself.
And this not accounting performance hit and difficult debugging.
I'm not just talking here - i removed
completely Lua support from my game because it actually slowed me down... and the "funny" thing was that I reimplemented 3-months worth of Lua code this afternoon.
So, before to jump in the scripting bandwagon, think if you *really* need it

Re: Lua Script Logistics Questions
Posted: Tue Sep 01, 2009 11:03 pm
by PaddyWagon
You don't mention what you're trying to teach, (programming, art, design?) or at what level. Have you looked at teaching tools like Alice?
http://www.alice.org/
Re: Lua Script Logistics Questions
Posted: Wed Sep 02, 2009 1:51 am
by corn
Thank you for all of the suggestions and points. Your input is much appreciated.
Re: Lua Script Logistics Questions
Posted: Wed Sep 02, 2009 3:55 am
by NoodlesOnMyBack
When i first started integrating Lua + Luabind to my project (first time i tried to do scripting) i run into a lot of problems, but now im really happy of how im doing things, this is saving me so much time spent into compile times that i would use luabind just for that reason.
I think that scripting has to be simple as top priority, for that reason i would only recomend binding Ogre functionality for basic things, like scene nodes, cameras, etc.
As you can see here i only let the user to access my manager classes and very basic Ogre stuff.
Take this from a novice user, im not saying this is the best way, this worked fine for me.
Good luck.
Code: Select all
--The name of the template
katana = {}
ITEM_DEFAULT_SOUND = "../Media/Sounds/Sword hit.wav"
PARTICLE_WEAPON = "katana_particle"
PARTICLE_WEAPON_SCRIPT = "example_010"
katana["OnWeaponItemMenuStartDrag"] = function(obj)
end
katana["OnWeaponItemMenuFinishDrag"] = function(obj)
end
katana["OnWeaponInventoryActivate"] = function(obj)
SoundManager:play(ITEM_DEFAULT_SOUND)
end
katana["OnWeaponPick"] = function(obj)
SoundManager:play(ITEM_DEFAULT_SOUND)
ParticleManager:stopParticle(PARTICLE_WEAPON)
end
katana["OnWeaponDrop"] = function(obj)
SoundManager:play(ITEM_DEFAULT_SOUND)
ParticleManager:startParticle(PARTICLE_WEAPON)
end
katana["OnComponentCreateStart"] = function(obj)
end
katana["OnComponentCreateFinish"] = function(obj)
render = nil
render = LuaStateManager:getRenderComponent(obj)
weapon = nil
weapon = LuaStateManager:getWeaponComponent(obj)
if(render and weapon) then
ParticleManager:createParticle(PARTICLE_WEAPON,PARTICLE_WEAPON_SCRIPT) --"example_01_A"
nodeParticle = nil
nodeParticle = OgreManager:createChildSceneNode(render:getNode(),"katana_particle")
ParticleManager:attachParticleToNode(PARTICLE_WEAPON,nodeParticle)
ParticleManager:startParticle(PARTICLE_WEAPON)
nodeTip = nil
nodeTip = OgreManager:createChildSceneNode( render:getNode(),"katana_child_tip")
trans = Vector3.ZERO
trans = Vector3(0,0,-9)
nodeTip:translate(trans,Node.TS_PARENT)
weapon:setRibbonTrailNodeTip(nodeTip)
nodeBase = nil
nodeBase = OgreManager:createChildSceneNode( render:getNode(),"katana_child_base")
weapon:setRibbonTrailNodeBase(nodeBase)
weapon:setRibbonTrailMaterial("swordMaterial")
initColor = ColourValue.Red
weapon:setSegmentStartInitialColor(initColor)
endColor = ColourValue.Red
weapon:setSegmentEndInitialColor(endColor)
end
pos = Vector3.ZERO
SoundManager:createSingleSound(SOUND_FX_REVERB, ITEM_DEFAULT_SOUND, pos, false )
end
katana["OnStartUpdate"] = function( obj )
end
katana["OnFinishUpdate"] = function( obj )
end
katana["OnComponentDestroy"] = function( obj )
end
Re: Lua Script Logistics Questions
Posted: Wed Sep 02, 2009 6:19 am
by Vectrex
I use 'MOgre' and CSharp while teaching. It's a good mix of c++ish syntax coding and ease.
Although I don't really like Python much, I think PYOgre would also be good. The main reason I use C# and MOgre is because visual studio helps so much with students. So any syntax difficulty is offset by the good ide. If you can get a great python IDE it would probably be ever nicer for beginners.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 2:00 pm
by VictorMoran
Vectrex wrote:I use 'MOgre' and CSharp while teaching. It's a good mix of c++ish syntax coding and ease.
Although I don't really like Python much
This is one of those mysteries that have always puzzled me.
Python is such a proffesional powerful and flexible scripting language, cross platform and easy to use.
Yet it had been overlooked by the game community in favor on such amateur tools like Lua, Small C, and so other limited pseudo scripting languages.
It does not make sense.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 2:25 pm
by dv_
VictorMoran wrote:
Yet it had been overlooked by the game community in favor on such amateur tools like Lua, Small C, and so other limited pseudo scripting languages.
It does not make sense.
Please enlighten us how Lua is a "limited pseudo scripting language".
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 4:01 pm
by VictorMoran
Well for once, try doing this in Lua
> Float F = 1.1
This simple do not work and special coding is need it. At least last time I was searching for scripting language I tried Lua and it could not deal with simple float math.
I move on to Python and it can handle every normal programming task including some level of Object scripting.
This simple Limitation in Lua force any app to result to a huge proliferation of trivial functions like calculation dot products and stuff like that, that can be implement in script code.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 4:16 pm
by wacom
VictorMoran wrote:Well for once, try doing this in Lua
> Float F = 1.1
Nobody who knows the language would try that. The correct syntax is:
> F = 1.1
or
>local F = 1.1
So what are your problems with dot product?
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 4:34 pm
by VictorMoran
No problem, anyone who wishes using Lua, can use Lua.
I just stated my opinion about Phyton.
Phyton can give C# and Java a run for its money in performance and efficiency in code size,
and it is still an interpreted language that can serve as a scripting system with all the power and glory of a full Object Oriented Language.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 4:36 pm
by wacom
So you admit you just were talking gibberish?
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 5:10 pm
by Kojack
Yet it had been overlooked by the game community in favor on such amateur tools like Lua, Small C, and so other limited pseudo scripting languages.
At least last time I was searching for scripting language I tried Lua and it could not deal with simple float math.
Are you sure you actually tried lua and didn't just dream the whole thing? Because the claim that Lua can't handle simple float math is utter bullshit or a really poor troll attempt.
I just stated my opinion about Phyton
Phyton can give C# and Java a run for its money
I'm sure
phyton rocks, but I thought we were talking about python?

Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 5:25 pm
by mkultra333
I've added Lua to one of my projects. I can give an opinion, uninformed perhaps, as to why I chose Lua and not Python. Basically, Lua seemed small, tight and simple, while Python seemed large and over complicated. I wasa a bit scared of python. The thing about spaces being part of the language seemed weird too. Plus, Lua sounded like it was faster. That impression wasn't based on much actual use, although I did try a few small python experiments. Mainly it was just based on reading lots of internet debates.
I don't want to say that python isn't good, I really don't know, I just wanted to give an impression as to what made me chose one way or another.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 6:10 pm
by VictorMoran
mkultra333 wrote:... Basically, Lua seemed small, tight and simple, while Python seemed large and over complicated.
You could say the exact same thing about C and Cpp, but my guess is that Cpp, by far, is used by more programmers.
Like I said I am not a Phyton or Lua evangelizer and it does not bother me if people use one or the other.
Everyone here is free to go with what they like better, but the question was posted In relation to teaching other people who are not making that decision.
The question you have to ask yourself is: would you hire a fresh graduate with a resume saying he knows Lua script or one saying he has experience with Python scripting.
I tested Lua and Small C and neither one come close to Phyton.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 6:39 pm
by DanielSefton
VictorMoran wrote:You could say the exact same thing about C and Cpp, but my guess is that Cpp, by far, is used by more programmers.
That analogy is void - we're talking about
scripting here. One of the main reasons for using scripting is to make programming your game easier, something which perhaps artists can chip into, and for fast prototyping. Python to me is more of a full-blown language and most of it's features are
unnecessary. There's nothing wrong with using Python as a scripting language, but just because it's "more powerful" doesn't suddenly make it the end-all scripting solution. It's down to the user's preference and requirements.
VictorMoran wrote:would you hire a fresh graduate with a resume saying he knows Lua script of one saying he has experience with Python scripting.
It depends what that graduate is applying for and the language the company uses. I'm not an industry expert, but I know that Lua is a highly valued, and in some cases not knowing it can loose you the job.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 6:46 pm
by nullsquared
VictorMoran wrote:Well for once, try doing this in Lua
> Float F = 1.1
Buddy have you even tried Lua? Or did you dream all of this, to quote Kojack?

Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 6:49 pm
by CABAListic
I have never used scripting languages so far, myself, but I did investigate some for future reference. While I like Python as a programming language, it would not be my first choice as an embedded scripting language. There are several reasons, one of them is that the embedding API seemed rather awkward and complicated to me, and while Boost.Python would most probably be a help there, it seems focused more on extending Python than embedding it. Also, Python's interpreter is rather huge as a dependency.
The other problem, perhaps surprisingly, is actually Python's standard library and feature set. While those make Python great as a programming library and would certainly be nice to have in scripts sometimes, they create severe security risks. When I think scripting, I'm thinking about exposing a certain set of functionality to be used in the scripts - but Python can do so much more. I'd have to worry about stopping it from exposing file system functionality etc., and I frankly have no idea how hard that would be.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 6:52 pm
by jacmoe
VictorMoran wrote:I tested Lua and Small C and neither one come close to Phyton.
Exactly.
That's by design.
Python is more geared towards writing everything in it, not being embedded in C++.
It's mostly the other way around.
It's not comparable to using Lua as a scripting language embedded in C++.
<edit>
CABAListic has got it right: Python is rarely used as an embedded scripting language.
It's fairly common to extend Python, though. And that is the kosher way of using it.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 7:02 pm
by VictorMoran
DanielSefton wrote:VictorMoran wrote:You could say the exact same thing about C and Cpp, but my guess is that Cpp, by far, is used by more programmers.
That analogy is void - we're talking about
scripting here. One of the main reasons for using scripting is to make programming your game easier, something which perhaps artists can chip into, and for fast prototyping.
Ohh. Void you say? You will be surprised as to how many AAA games use C and CPP for scripting. what would you say to them?
And we do not use Lua, when I tried few years ago for a library called Motivate, it did not have the ability to deal with floats, this is a real fact.
If it does now it must be because it was added to a newer version.
Re: Lua Script Logistics Questions
Posted: Thu Sep 03, 2009 7:06 pm
by jacmoe
VictorMoran wrote:Ohh. Void you say? You will be surprised as to how many AAA games use C and CPP for scripting. what would you say to them?
I would say that they're being abused by a troll in a
Lua Script topic.