lua-users home
lua-l archive

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


Hello,

    Thank you, but this is what I'm trying to avoid ;-), I don't want to
allow access
to the global enviromment, only to tab, what I want is to protect the global
table.
    My intent is to make tab.afunc use as global table tab, but switch to
real global table when calling
print. Of course, when afunc call print, it's tab.print but i want to it
call the real print. Really, at momment it's a hard task, or impossible to
do.

                                                                        The
God's Peace,


Leandro.

----- Original Message -----
From: "Kevin Baca" <lualist@aidiastudios.com>
To: "'Lua list'" <lua@bazar2.conectiva.com.br>
Sent: Monday, November 10, 2003 8:41 PM
Subject: RE: setfenv, how to...


> tab = setmetatable( {}, { __index = _G } )
>
> > ... Let a function with an enviromment call another with
> > other enviromment?
> > Example:
> > -- block
> >     tab = {}
> >     function tab.afunc()
> >         print("Inside tab.afunc");
> >     end
> >     setfenv(tab.afunc, tab);
> > -- end block
> >
> >     The code above raise an error with "attempt to call
> > global 'print' (a nil value)". Yes, I know that the code is
> > trying to call tab.print, but how to set it to call the real
> > print? (Please, I know too that I can write tab.print =
> > print; but this isn't what I want).
> >
> >
> >           The God's Peace,
> >
> >
> > Leandro.
> >
>
>