Lua Script Logistics Questions
-
corn
- Gnoblar
- Posts: 16
- Joined: Sat Feb 07, 2009 8:28 pm
Lua Script Logistics Questions
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!
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!
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Re: Lua Script Logistics Questions
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).corn wrote: What's the overhead of using LuaBind or other binding libraries? Is it worth it, or would you recommend just plain Lua?
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.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.)?
Technically, Lua doesn't have classes. Though you can fake them (especially with LuaBind), and that makes interfacing with C++ much easier.Is it more advantageous in the long run to use classes in Lua scripts, or just stick with functions?
Yeah, it's called "user data".I've seen examples of the use of strings for referencing objects in scripts; however, is there a way to use pointers with Lua?
-
corn
- Gnoblar
- Posts: 16
- Joined: Sat Feb 07, 2009 8:28 pm
Re: Lua Script Logistics Questions
Thank you for the advice.
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?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.
-
Fire Lancer
- Gnoblar
- Posts: 4
- Joined: Tue Aug 11, 2009 12:07 pm
Re: Lua Script Logistics Questions
You might want to look at http://www.pythonogre.com/
- wacom
- Gnome
- Posts: 350
- Joined: Sun Feb 10, 2008 2:07 pm
- _tommo_
- Gnoll
- Posts: 677
- Joined: Tue Sep 19, 2006 6:09 pm
- x 5
- Contact:
Re: Lua Script Logistics Questions
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
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
-
PaddyWagon
- Halfling
- Posts: 94
- Joined: Fri Jul 17, 2009 4:39 am
- x 1
Re: Lua Script Logistics Questions
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/
-
corn
- Gnoblar
- Posts: 16
- Joined: Sat Feb 07, 2009 8:28 pm
Re: Lua Script Logistics Questions
Thank you for all of the suggestions and points. Your input is much appreciated.
- NoodlesOnMyBack
- Goblin
- Posts: 200
- Joined: Tue Feb 05, 2008 4:14 am
- Location: Buenos Aires, Argentina
- Contact:
Re: Lua Script Logistics Questions
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.
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

-
Vectrex
- Ogre Magi
- Posts: 1266
- Joined: Tue Aug 12, 2003 1:53 am
- Location: Melbourne, Australia
- x 1
- Contact:
Re: Lua Script Logistics Questions
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.
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.
-
VictorMoran
- Greenskin
- Posts: 137
- Joined: Thu Jul 12, 2007 7:04 pm
Re: Lua Script Logistics Questions
This is one of those mysteries that have always puzzled me.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
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.
-
dv_
- Gnoblar
- Posts: 1
- Joined: Thu Sep 03, 2009 2:24 pm
Re: Lua Script Logistics Questions
Please enlighten us how Lua is a "limited pseudo scripting language".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.
-
VictorMoran
- Greenskin
- Posts: 137
- Joined: Thu Jul 12, 2007 7:04 pm
Re: Lua Script Logistics Questions
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.
> 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.
- wacom
- Gnome
- Posts: 350
- Joined: Sun Feb 10, 2008 2:07 pm
Re: Lua Script Logistics Questions
Nobody who knows the language would try that. The correct syntax is:VictorMoran wrote:Well for once, try doing this in Lua
> Float F = 1.1
> F = 1.1
or
>local F = 1.1
So what are your problems with dot product?
-
VictorMoran
- Greenskin
- Posts: 137
- Joined: Thu Jul 12, 2007 7:04 pm
Re: Lua Script Logistics Questions
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.
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.
- wacom
- Gnome
- Posts: 350
- Joined: Sun Feb 10, 2008 2:07 pm
- Kojack
- OGRE Moderator

- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 538
Re: Lua Script Logistics Questions
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.
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.At least last time I was searching for scripting language I tried Lua and it could not deal with simple float math.
I just stated my opinion about Phyton
I'm sure phyton rocks, but I thought we were talking about python?Phyton can give C# and Java a run for its money
- mkultra333
- Gold Sponsor

- Posts: 1894
- Joined: Sun Mar 08, 2009 5:25 am
- x 116
Re: Lua Script Logistics Questions
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.
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.
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.
-
VictorMoran
- Greenskin
- Posts: 137
- Joined: Thu Jul 12, 2007 7:04 pm
Re: Lua Script Logistics Questions
You could say the exact same thing about C and Cpp, but my guess is that Cpp, by far, is used by more programmers.mkultra333 wrote:... Basically, Lua seemed small, tight and simple, while Python seemed large and over complicated.
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.
- DanielSefton
- Ogre Magi
- Posts: 1235
- Joined: Fri Oct 26, 2007 12:36 am
- Location: Mountain View, CA
- x 10
- Contact:
Re: Lua Script Logistics Questions
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:You could say the exact same thing about C and Cpp, but my guess is that Cpp, by far, is used by more programmers.
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.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.
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Re: Lua Script Logistics Questions
Buddy have you even tried Lua? Or did you dream all of this, to quote Kojack?VictorMoran wrote:Well for once, try doing this in Lua
> Float F = 1.1
-
CABAListic
- OGRE Retired Team Member

- Posts: 2903
- Joined: Thu Jan 18, 2007 2:48 pm
- x 58
- Contact:
Re: Lua Script Logistics Questions
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.
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.
- jacmoe
- OGRE Retired Moderator

- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: Lua Script Logistics Questions
Exactly.VictorMoran wrote:I tested Lua and Small C and neither one come close to Phyton.
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.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
-
VictorMoran
- Greenskin
- Posts: 137
- Joined: Thu Jul 12, 2007 7:04 pm
Re: Lua Script Logistics Questions
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?DanielSefton wrote: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.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.
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.
- jacmoe
- OGRE Retired Moderator

- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: Lua Script Logistics Questions
I would say that they're being abused by a troll in a Lua Script topic.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?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.