lua-users home
lua-l archive

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


That's it! Thanks a lot!

Bye Eva

Alex Queiroz wrote:
Hallo,

On 3/21/07, Eva Schmidt <es@sol-3.de> wrote:

I want to execute a little script from another script using loadfile(). Because of the fact that I cannot make sure that this script doesn't contain code I don't want to be executed (like os.exit() or something) I tried to just allow
certain functions using an environment like that:


    -- create local environment for loadstring()
    local fenv = {}
    fenv.print = _G.print

    setfenv (loadstring, fenv)

    result, error = loadstring (s)

With this environment it should be possible to just call the printing function within the chunk to be loaded. Maybe this approach is too naive - Lua forbits
changing the environment for the function loadstring() ;-(


    You are changing the environment of the loadstring function. You
should change the environment of the loaded function:

result = setfenv(result, fenv)

Cheers,

--

--

  \ /           Sol-3 GmbH & Co. KG             Eva Schmidt
 --o-- Sol-3    Eltviller Straße 2              Phone: ++49 (0) 6123 7029 23
  / \           D-65399 Kiedrich                Fax:   ++49 (0) 6123 7029 29
                USt-ID:   DE 204978307          eMail: es@sol-3.de
                Register: WI HRA 6607
                Komplementär:    Sol-3 Verwaltungs GmbH
                Register:        WI HRB 117786
                Geschäftsführer: Norbert Geus, Dirk Zoller