lua-users home
lua-l archive

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


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..



-----Original Message-----
From: [] 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 <> 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


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

for k,_ in pairs(_G) do

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 :-)

-- Pierre-Yves

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