lua-users home
lua-l archive

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


On Wed, Dec 26, 2012 at 1:52 PM, Victor Bombi <sonoro@telefonica.net> wrote:
> ---------------sc,synthdef.lua
> variable = 1234
> require"blabla"
> more_things
> --------------blabla
> variable2 = variable *3

Ah, sorry - now I see the situation.  The way to avoid polluting _G is
to load both of these files using the same environment (untested code)

env = {}
chunk = loadstring('sc.synthdef.lua')  -- compile
setfenv(chunk,env)  -- set environment
chunk()  -- execute

-- now variable is defined in env

chunk = loadstring('blabla.lua')
setfenv(chunk,env)
chunk()  -- should work

steve d.