lua-users home
lua-l archive

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


Hey Enrico,

How would I go about loading the level script into a table?

I support both compiled and uncompiled lua, so I load my levels with:

error = luaL_loadbuffer(lua, buffer, length, filename);
lua_pcall (lua, 0, 0, 0);

.. if they're compiled or:

error = luaL_dostring(lua, scriptString);

if they're uncompiled...

Also, if I used setfenv to change the environment, aren't I just moving the
problem? If I then have to add global functions to this same table, how will
I differentiate them from the level functions when I need to clean up?

I am thinking maybe my solution is going to be (shallow) copying _G before
loading a level, then comparing the copy with _G after the level load. Any
objects which don't exist in the copy, but do exist in _G should be the
level-specific ones
Cheers,

Ricky

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Enrico Colombini
Sent: 24 March 2010 11:47
To: Lua list
Subject: Re: Cleaning up specific lua scripts

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 load the level into a table, use setfenv to have level 
functions see this table as 'global', and add true global functions to 
the table when you load a level.

   Enrico