Posted 27 September 2016 - 11:01 AM
Hey guys,
i wanna load a constructor with different environments. First, i thought something like that:
My next idea was:
Is there any possibility to use the first mentioned option without editing the string?
So:
local object = constructor(tEnv)
Sewbacca
P.S. I don't want to use setfenv, because Lua 5.2 doesn't support setfenv
i wanna load a constructor with different environments. First, i thought something like that:
local sData = File.readAll()
sData = '_ENV = ...\n' .. sData
local constructor = load(sData, sName, 't', _)
local object = constructor(setmetatable({}, { __index = _ENV}))
but would brake with binary constructors. It is an advantage that the program has to read and compile the string one time.My next idea was:
local sData = File.readAll()
local constructor = function (tEnv)
return load(sData, sName, 't', tEnv)
end
Now, the program won't be decreased by reading the hard disk, but by compiling the string again and again.Is there any possibility to use the first mentioned option without editing the string?
So:
local object = constructor(tEnv)
Sewbacca
P.S. I don't want to use setfenv, because Lua 5.2 doesn't support setfenv
Edited on 28 September 2016 - 01:53 PM