[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Lua on the PlayStation2
- From: Chris Chapman <Chris.chapman@...>
- Date: Thu, 23 Oct 2003 16:42:55 +0100
Okay, as an addendum to this, we've been using Lua 5.0 quite happily for a
few weeks now, and have seen no major problems. Garbage collection is much
nicer, and I'm almost feeling brave enough to start tying Lua tables to our
dynamic map/character segments so that I can delete them when C game data is
But I'm tracking down a sneaky bug that was introduced with the change. We
implement a 'pending-function' interface to our scripts which allows us to
store a function with some parameters for calling at a later time (after the
script which stored it has finished and returned control to the game
engine). We implemented this in Lua 4.0.1 by calling lua_ref(L, true) to
pull a reference to the function and lock it so it doesn't accidentally get
garbage collected. To call the function, the game engine uses the reference
by calling lua_getref, calls the pending function, and then calls lua_unref
to clean up.
All well and good, and under 4.0.1 it worked fine. However one of our script
writers sneakily put a recursive pending function in - i.e. a function
called after some time which registers a pending function to itself. So the
order of operations looks like:
StartupFunction: (time = 0)
PendingRef = lua_ref(SomePendingFunction)
HandlePendingFunctionCalls: (time = x)
SomePendingFunction: (time = x)
PendingRef2 = lua_ref(SomePendingFunction)
HandlePendingFunctionCalls: (time = y)
I understand by looking at the implementation now that 5.0 stores
SomePendingFunction into a table (LUA_REGISTRYINDEX) and the reference
returned by lua_ref is an index into that table. The PendingRef2 that is
returned is the same as PendingRef - almost as if the call recognised that
there was already an entry for SomePendingFunction. However, the second time
I call lua_getref, I get nil back. How would this case be handled in 4.0.1?
And is there a simple tweak I can apply to make it work under 5.0?
NB: The function should not have been garbage collected, because it is
simply declared at the global scope once and is never reassigned/redeclared.
From: Jeff [mailto:firstname.lastname@example.org]
Sent: 06 October 2003 14:25
To: Lua list
Subject: Re: Lua on the PlayStation2
Hi Chris, I haven't got any tips for you, but if you get other feedback from
anywhere other than this Lua list, please post it! I'm looking into using
Lua in a similar environment (PS2, XBox, PC) and would be very interested to
hear what you find out.
(The double thing was the first one I noticed, and like you I'm not sure of
the implications of changing it - mainly cos I haven't yet checked!)
----- Original Message -----
From: "Chris Chapman" <Chris.email@example.com>
Sent: Monday, October 06, 2003 1:45 PM
Subject: Lua on the PlayStation2
> I realise this is probably best suited to newsgroups for PS2 compilers, so
> I'll be posting it there as well; however I'd be interested to hear from
> other developers using Lua in a PS2 environment - what did you have to
> to get Lua a) working and b) fast?
> When we ran our game through the Performance Analyser, Lua showed up as
> worst single culprit for performance..........