lua-users home
lua-l archive

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


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