[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: setfenv, how to...
- From: "Kevin Baca" <lualist@...>
- Date: Thu, 13 Nov 2003 11:33:59 -0800
tab = {}
for k,v in pairs( _G ) do
tab[ k ] = v
end
-- Remove restricted functions
tab.rawget = nil
tab.rawset = nil
tab.setmetatable = nil
...
Basically, populate a table with the subset of functions that are not
restricted.
Also, search for "sandbox" in the archives for some interesting
discussions.
-Kevin
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of
> Leandro Candido
> Sent: Thursday, November 13, 2003 10:38 AM
> To: Lua list
> Subject: Re: setfenv, how to...
>
>
> 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.
> > >
> >
> >
>