Skip to content
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

Accidentally setting engine method breaks engine until matron restart #656

Closed
rwhaling opened this issue Nov 25, 2018 · 0 comments · Fixed by #667
Closed

Accidentally setting engine method breaks engine until matron restart #656

rwhaling opened this issue Nov 25, 2018 · 0 comments · Fixed by #667
Labels

Comments

@rwhaling
Copy link

While working through the studies, I accidentally ran engine.cutoff = 100 in a script, which I rapidly fixed.

However, that created a numeric field named cutoff in the engine table, which means that when I correctly ran engine.cutoff(100), I got a attempt to call a number value (field 'cutoff') error.

Surprisingly - the error persisted even after removing the bad assignment, since the engine table itself does not appear to be re-initialized upon script load - I had to restart . Huge thanks to @catfact for figuring this out.

After a bit more testing, I've confirmed that this issue persists even after loading a different script, that uses a different engine - I believe due to the way the engine object itself persists across loading/unloading particular engines

I think this is a pretty big potential footgun for Lua novices (like me), so worth fixing. I'm still wrapping my head around how script-loading works, but I think two ways to fix would be:

  1. Disable metatable sets by raising an error from engine's __newindex method
  2. Re-initialize engine upon script load, which seems generally like a good idea, but more architecturally invasive.

Small script to repro:

engine.name = "TestSine"

function init()
  engine.hz(math.random(10)*50+100)
end

function key(n,z)
  -- engine.hz = n * 200 -- comment/uncomment this line to test
  engine.hz(n * 200)
end

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

Successfully merging a pull request may close this issue.

2 participants