lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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)

end
"

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
scripts, etc).

Thx,
ando

>> For example, this script does nothing:
>> 
>> "function main(arg)
>> 
>> end"
>> 
>> 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.
>