Jump to content




Compile a program (Environment)


  • You cannot reply to this topic
4 replies to this topic

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 16 September 2016 - 11:45 PM

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 by Sewbacca, 17 September 2016 - 09:56 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 17 September 2016 - 12:34 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").

Edited by Bomb Bloke, 17 September 2016 - 12:37 AM.


#3 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 17 September 2016 - 10:26 AM

View PostBomb Bloke, on 17 September 2016 - 12:34 AM, said:

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?

#4 valithor

  • Members
  • 1,053 posts

Posted 17 September 2016 - 05:02 PM

View PostSewbacca, on 17 September 2016 - 10:26 AM, said:

View PostBomb Bloke, on 17 September 2016 - 12:34 AM, said:

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.

#5 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 17 September 2016 - 05:32 PM

View Postvalithor, on 17 September 2016 - 05:02 PM, said:

View PostSewbacca, on 17 September 2016 - 10:26 AM, said:

View PostBomb Bloke, on 17 September 2016 - 12:34 AM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users