463 posts
Location
Star Wars
Posted 17 September 2016 - 12:45 AM
Hey guys,
I have following problem:
load(sBinary, 'b')
loads a binary string with _G as his environment,
but I want to load it with a specific environment.
I tested:
load(sBinary, 'b', tEnv)
and
load(sBinary, 'b', 'Binary chunk', tEnv)
Can somebody help me with the arguments?
Sewbacca
P.S. I can't use setfenv and getfenv cause of Lua 5.2 compatibilities.
Edited on 17 September 2016 - 08:56 AM
7083 posts
Location
Tasmania (AU)
Posted 17 September 2016 - 01:34 AM
load(sourceString, nameString, modeString, envTable)
https://www.lua.org/manual/5.2/manual.html#pdf-loadNote that ComputerCraft defaults to mode t and errors on anything else ("Binary chunk loading prohibited").
Edited on 16 September 2016 - 11:37 PM
463 posts
Location
Star Wars
Posted 17 September 2016 - 11:26 AM
load(sourceString, nameString, modeString, envTable)
https://www.lua.org/...l.html#pdf-loadNote that ComputerCraft defaults to mode t and errors on anything else ("Binary chunk loading prohibited").
load(sBinary, 'b') work
load(sBinary, 'BinaryChunk', 'b', tEnv) not.
Why?
1023 posts
Posted 17 September 2016 - 06:02 PM
load(sourceString, nameString, modeString, envTable)
https://www.lua.org/...l.html#pdf-loadNote that ComputerCraft defaults to mode t and errors on anything else ("Binary chunk loading prohibited").
load(sBinary, 'b') work
load(sBinary, 'BinaryChunk', 'b', tEnv) not.
Why?
The second argument is the nameString. The third is the mode. When the third argument is anything but nil or "b" it will error as bomb said.
load(sBinary, 'b') –# sBinary is the first argument, 'b' is the second, third is nil so it works.
load(sBinary, 'BinaryChunk', 'b', tEnv) –# sBinary is the first argument, 'binaryChunk' is the second, 'b' is the third and it is not 't' or nil so it won't work.
463 posts
Location
Star Wars
Posted 17 September 2016 - 06:32 PM
load(sourceString, nameString, modeString, envTable)
https://www.lua.org/...l.html#pdf-loadNote that ComputerCraft defaults to mode t and errors on anything else ("Binary chunk loading prohibited").
load(sBinary, 'b') work
load(sBinary, 'BinaryChunk', 'b', tEnv) not.
Why?
The second argument is the nameString. The third is the mode. When the third argument is anything but nil or "b" it will error as bomb said.
load(sBinary, 'b') –# sBinary is the first argument, 'b' is the second, third is nil so it works.
load(sBinary, 'BinaryChunk', 'b', tEnv) –# sBinary is the first argument, 'binaryChunk' is the second, 'b' is the third and it is not 't' or nil so it won't work.
Thanks ^^