-
Notifications
You must be signed in to change notification settings - Fork 145
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
stop the globalocalypse #425
Comments
yeah, i see a bunch more. typing
in the REPL (on a fresh start), yields this list of suspects: repl out (long)
obviously some come from lua core ( |
well a lot of them are c functions defined in matron. I don't actually know if there's a way to collect these in a table from c. If not maybe they should at least have a special naming convention |
can't we just use lint to detect unsanctioned globals in the scripts? |
perhaps c functions can use a preceding underscore? most of the rest of the globals can be cleaned up and put into the |
obfuscated names would help for sure. better still would be not to pollute the namespace at all. i'm not up on how the c/lua integration works but my hunch is there's got to be a way to specify an env that's not finally, assuming we can't make the globals go away we could consider tailoring the env used in scripts to hide or protect access to globals. (poc started in #426.) |
a forward pointer for anyone following along (who like me doesn't know their way around quite yet): Line 186 in d6c4f94
looking at the lua manual, i see there's a bunch of suggestively named stuff in the C API ( (caveat: just browsing around and haven't actually tried anything yet.) |
ok, i think the solution would use lua_pushcfunction and lua_setfield ( to register C functions as fields in a single table) |
btw i am checking out this book, which is a little tedious but seems to have many useful nuggets |
user trickyflemming was just hit by this on lines:
the lvm reset fixes that are in flight would make this a little better (i think |
i have LVM reset working now! it's great. just trying to prune unneeded code now |
that's cool - but a word of caution - resetting the LVM isn't actually a solution for the main failure case we've seen so far - which is users accidentally overwriting system globals. e.g. this problem: https://llllllll.co/t/norns-development/14073/214?u=zebra resetting the LVM seems useful for two reasons:
but for the case where someone makes a global script variable called the idea from the forum of adding norns sysgtem globals to maiden syntax highlighting, also seems like a smart thing to do and not too difficult. |
i am confused how resetting the LVM wouldn't fix a mistaken renaming of of course it's not going to fix the broken script, but this to me seems a different issue entirely. either we explicitly require every single script to that said, #436 seems very elegant, and doesn't have the issue of my current LVM reset PR (re: device detection). is there any downside to #436? if not we should just go with that and abandon this LVM reset business. i should still make an attempt to refine the script loading (which i did in the LVM reset PR) |
to be sure i understand correctly, i'm looking at PR #448 and running a script now seems to go like this:
let's say the startup script assigns the only way out of this is not letting user scripts overwrite system globals. |
anyway yes, i think PR #436 seems more apropos to the problem at hand, i don't see any downside, and i have other concerns about the lua reset. (see new issue.) re: dev detect, yes would simply need a new facility in weaver to explicitly request a report of all connected devices. |
there are way too many globals and they aren't defined in any particular place. it's a recipe for disaster. not even just in user scripts but when we want to extend or maintain the system.
in the beginning, there was the
norns
table, and it was global. it had to be, so that the C API glue could see it and call its fields.then, there were more globals added for convenient usage in scripts and REPL. this was controvesial, but at least they were collected in one place (
globals.lua
) and commented withldoc.
now, i don't know what happened to
globals.lua
but the definition of globals has gone everywhere- many are instartup.lua
, which makes sense:https://github.com/monome/norns/blob/master/lua/startup.lua#L9-L31
but many are in
script.lua
(i think? can't tell! that's the whole problem in a nutshell)https://github.com/monome/norns/blob/master/lua/startup.lua#L9-L31
and probably elsewhere. this is really bonkers because
script.lua
is otherwise structured as a module!The text was updated successfully, but these errors were encountered: