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

Don't put getfenv(0) as a tab's env!

Started by skwerlman, 27 May 2014 - 06:14 AM
skwerlman #1
Posted 27 May 2014 - 08:14 AM
I didn't know where to put this, so it's going in general.

This isn't stated anywhere I saw, either on the wiki or the forums, and it's rather important info to know. multishell.launch() accepts an environment variable, like os.run(). However, unlike os.run(), setting the environment to getfenv(0) results in an instant 'loop in gettable' error (so descriptive!). This info should probably go somewhere (the wiki?), but I'm not sure where. Also, maybe a check in multishell itself might help? (if env == _G then error() end)
theoriginalbit #2
Posted 27 May 2014 - 08:26 AM
not completely sure how that's the case, multishell.launch uses os.run… how can you state that it breaks with one, but not the other…
skwerlman #3
Posted 28 May 2014 - 06:21 AM
Actually, now that I go back through with simpler testing code, the issue doesn't exist. The weirdest part that the error in the more complex code (which is still occurring) is listed as happening at the second line of a valid block comment. So the issue is somewhere else, but I have no idea where…
Maybe its a CC bug… I'll see if I can't find enough info about it to actually warrant a report (as in what causes it, or even when it happens)
theoriginalbit #4
Posted 28 May 2014 - 06:56 AM
how about you post your code, there's a 98% chance its not a CC bug.
skwerlman #5
Posted 28 May 2014 - 08:04 AM
how about you post your code, there's a 98% chance its not a CC bug.
I'm actually reworking someone else's code to run in 1.6. There's like 20 files, and I'd rather not hand copy all the code into separate spoilers. Besides, so long as I don't use getfenv(0) in multishell.launch, there's no issue. If it becomes a problem, or if it becomes 99.999% certain it's a CC or LuaJ bug, I'll post more info.
ardera #6
Posted 28 May 2014 - 08:20 PM
"loop in gettable" ocurrs when a table metadata __index refers to the table itself in any way. If LuaJ wouldn't detect this, you would be stuck in an infinite loop. Example:


local t1 = {}
local t2 = {}

setmetatable(t1, {__index = t2})
setmetatable(t2, {__index = t1})

t1["something"] -- will cause the "loop in gettable" error

I think you may have set some invalid __index to your environment.
I don't think its a LuaJ or CC bug.
skwerlman #7
Posted 29 May 2014 - 07:53 AM
I think you may have set some invalid __index to your environment.
Unless a fresh, unedited environment has an invalid __index, I doubt this is the case.
I'm setting the environment of a program to 0 (_G), so unless that's invalid, there shouldn't be an issue.
theoriginalbit #8
Posted 29 May 2014 - 07:57 AM
I think you may have set some invalid __index to your environment.
Unless a fresh, unedited environment has an invalid __index, I doubt this is the case.
I'm setting the environment of a program to 0 (_G), so unless that's invalid, there shouldn't be an issue.
the fact that this happens with the big program, but not the smaller one, sounds to me like someone has done something to create the recursive loop with __index