[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Detecting an "empty" script?
- From: Ando Sonenblick <ando@...>
- Date: Thu, 21 Aug 2003 11:30:37 -0700
Thanks guys, especially for correcting me about "main" getting set.
Here is what I'm ultimately trying to accomplish:
I have a product where the user creates many (say, several hundred) widgets.
When instantiated each widget has about 10 lua stub scripts pre-assigned to
them. For example:
-- Executes in response to the user moving the mouse.
-- self [entity object]: this entity
-- x [number]: the new mouse x window position
-- y [number]: the new mouse y window position
-- dx [number]: the horizontal change
-- dy [number]: the vertical change
function main(self, x, y, dx, dy)
So, if we have 300 widgets each with 10 scripts, that's 3000 scripts - quite
a bit of memory taken up by them.
So I want to detect if the scripts actually do anything or not - and in my
case it's ok if the global "main" is reset - because I want to release any
scripts that are considered "empty."
I expect that at most 1 in 20 scripts will actually get defined by the user
and so it'll be a huge savings to release the memory of the other 19.
I can't just compare the script text with the originally provided text as a
user could mod the text but still have it do nothing.
Same with a dirty flag.
So, I'm looking to definitively determine if a script does any work (again,
other than defining main, as that is intentionally shared between all
>> For example, this script does nothing:
>> "function main(arg)
>> While this one does:
>> "x = 4"
> Basically both scripts re-define the values of global variables; whether
> they are set to 4 or an empty function is beside the point.