You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Disable metatable sets by raising an error from engine's __newindex method
Re-initialize engine upon script load, which seems generally like a good idea, but more architecturally invasive.
Small script to repro:
engine.name="TestSine"functioninit()
engine.hz(math.random(10)*50+100)
endfunctionkey(n,z)
-- engine.hz = n * 200 -- comment/uncomment this line to testengine.hz(n*200)
endfunctionredraw() end
The text was updated successfully, but these errors were encountered:
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 theengine
table, which means that when I correctly ranengine.cutoff(100)
, I got aattempt 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 enginesI 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:
engine
's__newindex
methodengine
upon script load, which seems generally like a good idea, but more architecturally invasive.Small script to repro:
The text was updated successfully, but these errors were encountered: