Lua Script Logistics Questions

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Re: Lua Script Logistics Questions

Post by Vectrex »

The only things I have against Python is all the frigging 'self.' everywhere. I use scripting to type LESS, not more. Also 'def'? why? and __init__ etc why?
About the tabbing, at first I thought it was totally stupid, but if it makes {}'s redundant then I think it's a good idea since I tab everything properly anyway :)

I'm looking into using MONO and C# for scripting and I'm liking what I see. I'm done with learning new hoky little languages ;)
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Re: Lua Script Logistics Questions

Post by nullsquared »

VictorMoran wrote: You will be surprised as to how many AAA games use C and CPP for scripting.
Oh yeah? How many, exactly?
it did not have the ability to deal with floats, this is a real fact.
Perhaps because "Float f = 1.1" is not actual Lua syntax :roll:
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Lua Script Logistics Questions

Post by nikki »

On the topic of whether the Ogre interface should be exposed to Lua, I'd suggest you decide first what you want to script.

For example, I've decided that I'd script my game from Python, not the lower level mechanics, so I expose stuff like 'openDoor'.
User avatar
wacom
Gnome
Posts: 350
Joined: Sun Feb 10, 2008 2:07 pm

Re: Lua Script Logistics Questions

Post by wacom »

VictorMoran wrote: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.
You're still talking nonsense.

To quote the Lua History:
Initially, Lua language had seven types: numbers (implemented as floats), strings, (associative) tables, nil (a type with a unique value also called nil), userdata (a generic C pointer to represent C structures inside Lua), Lua functions, and C functions. (After eight years of continuous evolution, the only change in Lua types was the unification of Lua functions and C functions into a single function type.)
Perhaps you tried something else, and not Lua.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Re: Lua Script Logistics Questions

Post by haffax »

Eventhough the point has already been made diffusely, I'd like to highlight it:

LUA is made for embedding, Python is not. Python can be embedded but the Python's C-API is really awkward, complex and verbose. LUA being made for embedding has an extremely simple and well designed C-API. When you understand the stack and tables, you're mostly done.
A simple API reduces implementation costs and is easier to use by novice programmers.#


But thanks Victor Moran for again drawing a thread away from its useful topic, by an overreaching uneducated remark... :(
team-pantheon programmer
creators of Rastullahs Lockenpracht
VictorMoran
Greenskin
Posts: 137
Joined: Thu Jul 12, 2007 7:04 pm

Re: Lua Script Logistics Questions

Post by VictorMoran »

haffax wrote:But thanks Victor Moran for again drawing a thread away from its useful topic, by an overreaching uneducated remark... :(
Well excuse me if offended you, I did not know I needed your permission to state an opinion.
Who would know such simple comment was going to open such a can of worms, and made so many people so angry.
Let us just say, you continue making great application with Lua while I am continue making crappy application using Python.

I missed the part where you listed all the Accredited Universities using Lua as embedding programming Language.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Lua Script Logistics Questions

Post by jacmoe »

VictorMoran wrote:I missed the part where you listed all the Accredited Universities using Lua as embedding programming Language.
List of games where Lua is used as a scripting language

Crawl out from under the rock you're living. :)
Lua is widely used, not only in games, but in a lot of applications as well.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Re: Lua Script Logistics Questions

Post by haffax »

VictorMoran wrote:I missed the part where you listed all the Accredited Universities using Lua as embedding programming Language.
And I missed the part where this was even mentioned before, but I now also miss where you list all the accredited universities using Python as embedded programming language.

I also miss the part, where you either rebut the arguments made or where you concede the point. You just can't lose, can you? ;)
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Re: Lua Script Logistics Questions

Post by Zeal »

Ahhh lua Vs python... which to use..

The answer - use both. If you think about it, there is no real reason why your engine (written in c) should care WHO is controlling it. So start with lua (easier to get started imo), then down the road if you want to add python support, it should (in theory) be a simple matter of 'pythonizing' all your 'c to lua' connections. You will have all the needed code/logic inplace, it will just be monotonous grunt work at that point (replacing lua bindings with python ones).

I say that the free market should apply to scripting languages!
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Re: Lua Script Logistics Questions

Post by Vectrex »

VictorMoran wrote: Who would know such simple comment was going to open such a can of worms, and made so many people so angry.
people get angry I think when you could have literally googled 'lua float' and have a hundred pages come up about lua floats... :roll:
ps I only don't like python because of it's syntax. Technically it's very good.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Lua Script Logistics Questions

Post by Kojack »

Ok, I got a little out of control before, language wars can do that. Sorry. :)
(Thinking calm thoughts...)

It's possible to rebuild Lua with a different datatype for number. Some people do it with int, because the default lua type is actually a double (because a double gives you both fractional numbers, and it can accurately represent every value in a 32 bit int. A float can't, it doesn't have enough digits in the mantissa). So this "Motivate" you tried might have used a custom build with integer only support. But that's not true Lua. I've been a Lua coder for around 9 years now, and it's always had floating point as the primary number data type.
The same can be done to Ogre, you could redefine ogre's Real type as an int if you want, but it's not ogre's fault if it doesn't work properly any more.
I missed the part where you listed all the Accredited Universities using Lua as embedding programming Language.
Well, I can't speak for other places, but here's one for the list: Qantm. I know this because I do the Lua teaching. :)
I also use it not just for the degree students but for afternoon mini-classes with high school kids, we can get them from never programming before to having a working game written in Lua in about 2-3 hours.

Back on the original question... I used to use LuaBind, but I found it tended to make Lua too much like C++, whereas I thought one of the strengths of Lua was how unlike c++ it was. So I do all binding manually. It's not really hard once you get used to it. But a lot of people love Luabind.
Using raw Lua also made it very easy to swap to Falcon, which has a very similar (but better) api to Lua, but no Luabind style system (yet).

Back on Lua features, a dot product was mentioned. Here's a vector3 class with constructor and dot product in lua:

Code: Select all

Vector3 = function(xx,yy,zz) return {x=xx, y=yy, z=zz, dot = function(self, v) return self.x*v.x+self.y*v.y+self.z*v.z; end} end
Now we can do stuff like this:

Code: Select all

v1 = Vector3(1,2,3)
v2 = Vector3(4,5,6)
d = v1:dot(v2)
x = v2.x
etc.
Pretty similar to doing it in c++, and fully float compatible.
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: Lua Script Logistics Questions

Post by Klaim »

At work, I needed a scripting language.

Python binary (be it stackless or not) don't fit in a NDS game. Lua does. Choice done.


At home I had a little project I needed a scripting language for.
The binding was simple and the project lightweight.
Lua is easier to embed simply than Python. Choice done. --that said, with knowledge and experience with Boost.Python at the time I might have use it. I don't know.

Currently I got a game that requires a rich and flexible embedding language, with Python or Ruby like language but that can be embedded easily. Before I wanted to use Lua but I'd like another syntax to help with OO programming in scripts (the scripts can be complex).
So I almost chose Python, but instead I'm giving a try to Falcon that fits better on the paper. For instance it seems a good choice -- it's still young but it's working right in my project.

VictorMoran we know a lot about scripting languages here, there are some discussions on other scripting languages in the forum, you should search.


By the way, the wikipage with games using lua is far from being complete. I suspect more than the half of the games of the last 10 years using scripting use lua. They say that some japanese comanies don't use scripting language, but I don't have any information or experience on this.
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Re: Lua Script Logistics Questions

Post by volca »

nullsquared wrote:
VictorMoran wrote: You will be surprised as to how many AAA games use C and CPP for scripting.
Oh yeah? How many, exactly?
For example Dark Engine (Thief I,II games and System Shock 2) used this. They had dynamically loaded .dll files named .osm which contained "scripts" (classes) that listen to in-game events. Thanks to the compiled nature of them, everything was pretty fast although being complex. It makes the porting/rewrite of the engine harder though, as we'll have to rewrite these as well (python chosen for that task).
I doubt that Dark Engine was the only one...
Image
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: Lua Script Logistics Questions

Post by syedhs »

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 think the overhead is definitely there, but Luabind shorten the process and make it easy. Probably you may want to use Lua when all other aspects of your engine has finished, and you have time to tweak here and there - just my opinion/
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.)?
My usage with lua is this:
1) Bind only several basic Ogre classes like Quaternion, Vector3, ParticleSystem, ParticleAffector, ParticleEmitter to lua. Dont bind everything.
2) Bind your game's classes. For an example, you are building a car racing game, and probably will want to use lua in this way:-

Code: Select all

function Car_OnCollideEnter(objectCollided)
   if objectCollided== "blah blah" the ...

   if car:getVelocity() > 100 then blah blah blah...

   car:attachWheelParticle("Ogre/Smoke")
   local emitter = car:getParticleEmitter(0) -- get the first emitter from out wheel particle above
   emitter:setParameter("halflife", "yyy") -- and then modify the half-life
   local affector = car:getParticleAffector(0) -- get the first affector
   affector:setParameter("..", "...") -- modify affector..
end
So you can see that it is pretty much high-level functions because car:getVelocity() is probably extracted from your physics library.
Is it more advantageous in the long run to use classes in Lua scripts, or just stick with functions?
My taste is I will stick to functions because those lua programmers should be junior level programmers or even someone with only basic programming skill (but great design skill probably). Classes (and all of the advantages) are good only for us - the geek programmers :)
I've seen examples of the use of strings for referencing objects in scripts; however, is there a way to use pointers with Lua?
Yes, you can.
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Re: Lua Script Logistics Questions

Post by nullsquared »

volca wrote: For example Dark Engine (Thief I,II games and System Shock 2) used this. They had dynamically loaded .dll files named .osm which contained "scripts" (classes) that listen to in-game events. Thanks to the compiled nature of them, everything was pretty fast although being complex. It makes the porting/rewrite of the engine harder though, as we'll have to rewrite these as well (python chosen for that task).
I doubt that Dark Engine was the only one...
Yeah but you really have to question whether DLLs would count as scripting. By that theory, making a mod for Half-Life 2, for example, would be considered scripting instead of programming.
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Re: Lua Script Logistics Questions

Post by volca »

That totally depends on how you define the term "scripting"... In the engine I mention, the scripts are a sort of "behavior definitions" (more here for example), which looks like it would fit the term. HL2 mod, on the other hand, handles much more than object behavior.
Anyway sorry for the offtopic :)
Image
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Lua Script Logistics Questions

Post by nikki »

You couldn't do that from an in-console-interpretter. ;)

There's CINT from ROOT if you want C++-ish scripting, but why anyway?
User avatar
volca
Gnome
Posts: 393
Joined: Thu Dec 08, 2005 9:57 pm
x 1
Contact:

Re: Lua Script Logistics Questions

Post by volca »

The probable reason was speed. Dark Engine is heavily scripted, even things like weapon events are passed through scripts to gain in-game world meaning. It was written with the first Pentium(75Mhz or such) in mind, so interpreted language was not a viable option back then.
Image
Post Reply