This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sewbacca's profile picture

Compile a program (Environment)

Started by Sewbacca, 16 September 2016 - 10:45 PM
Sewbacca #1
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
Bomb Bloke #2
Posted 17 September 2016 - 01:34 AM
load(sourceString, nameString, modeString, envTable)

https://www.lua.org/manual/5.2/manual.html#pdf-load

Note that ComputerCraft defaults to mode t and errors on anything else ("Binary chunk loading prohibited").
Edited on 16 September 2016 - 11:37 PM
Sewbacca #3
Posted 17 September 2016 - 11:26 AM
load(sourceString, nameString, modeString, envTable)

https://www.lua.org/...l.html#pdf-load

Note 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?
valithor #4
Posted 17 September 2016 - 06:02 PM
load(sourceString, nameString, modeString, envTable)

https://www.lua.org/...l.html#pdf-load

Note 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.
Sewbacca #5
Posted 17 September 2016 - 06:32 PM
load(sourceString, nameString, modeString, envTable)

https://www.lua.org/...l.html#pdf-load

Note 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 ^^