8000 upvalues in global functions to local variables not restored properly · Issue #29 · fnuecke/eris · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

upvalues in global functions to local variables not restored properly #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
payonel opened this issue Feb 21, 2018 · 4 comments
Open

Comments

@payonel
Copy link
payonel commented Feb 21, 2018

When investigating a bug report of OpenComputers I found that some lua code can behave incorrectly between loads (restoring the world after closing it)

MightyPirates/OpenComputers#2598

The summary of the problem is:

The issue appears to be that local values captured (upvalue) in global functions do not restore the same reference, the local scope gets a new object, and the global function has its own. It's like its own global upvalue. In fact, all global functions share the same upvalue, and all local functions share the same upvalue, those being 2 separate upvalues.

Here is a simple repro

local value = 0
local sync = true

function g_fp()
  value = value + 1
  if not sync then
    print("out of sync")
  end
end

function g2(given_value)
  if given_value ~= value then
    sync = false
  end
end

while true do
  -- read here just to delay/slow the loop for observation
  io.read()
  local before_call = value
  g_fp()
  if before_call < value then
    print("value increased", value)
  else
    g2(value)
  end
end
@payonel
Copy link
Author
payonel commented Feb 21, 2018

as mentioned in my last comment on the OC bug report, I also want to add that:

This isn't an issue with all local values captured in global functions
In my same examples, if I also make a local table and capture it in the functions (globals and locals), suddenly the bug is not hit -- it seems more is packed and correctly restored when there is a table to share

@payonel
Copy link
Author
payonel commented Feb 23, 2018

I'm testing this with eris and the bug is not repro'ing
There must be something more happening in OpenComputers. I'll continue to investigate and report

@payonel
Copy link
Author
payonel commented Feb 27, 2018

This still appears to be an eris issue to me, but i did test this in "eeprom" (sangar will understand) and it DOES NOT repro. There is a lot more loading (i.e. lua's load) between eeprom and a user script, so, it'll take more time to pin down a sample script that repro's more easily

@ptwohig
Copy link
ptwohig commented Jun 13, 2018

@payonel Do you have a workaround for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0