lua-users home
lua-l archive

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


Pierre,

This is a simpler and more elegant version of what I implemented yesterday afternoon, which also seemed to do the job, albeit with more fuss..  I'm definitely going to upgrade to your code today..

Thanks,

Ricky

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Pierre-Yves Gérardy
Sent: 24 March 2010 19:27
To: Lua list
Subject: Re: Cleaning up specific lua scripts

On Wed, Mar 24, 2010 at 12:30, Ricky Haggett <ricky@honeyslug.com> wrote:
> Yep, we could store a table of all of the functions / tables within a
> specific level script, but it would be awkward for the designers to
> maintain, and a potential source of error...

You could also do it the other way around:
after you've loaded your global scripts do

globals={}

function cleanLevel()
    for k,_ in pairs(_G) do
        if not globals[k] then _G[k] = nil
    end
end

for k,_ in pairs(_G) do
    globals[k]=true
end

globals will index all globals present at that point (including itself
and cleanlevel() ), and cleanLevel() will only delete the globals not
referenced there. Case solved :-)

Cheers,
-- Pierre-Yves

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.791 / Virus Database: 271.1.1/2767 - Release Date: 03/24/10 07:33:00