Re: require in another enviroment
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: require in another enviroment
- From: "Victor Bombi" <sonoro@...>
- Date: 2012年12月26日 14:19:23 +0100
If I do exactly that, then I get what I expect:
synth = [[
variable = 20
]]
blabla = [[
var2 = variable*2
]]
env = {}
chunk = loadstring(synth)
setfenv(chunk,env)
chunk()
print(env.variable)
chunk = loadstring(blabla)
setfenv(chunk,env)
chunk()
print(env.var2)
output is
10
20
Yes but the difference is that my code was using files and require
the files are:
---------------sc,synthdef.lua
variable = 1234
require"blabla"
more_things
--------------blabla.lua
variable2 = variable *3
------------------------
on the first
local f = assert(loadfile(_scscriptsdir.."synthdefsc.lua"))
setfenv(f, setmetatable(env, {__index = _G}))
f()
I get the complain
victor