Global variables within the "whole script"?

Scope depends on where & how the variable is declared.

What you just did would indeed be accessible from anywhere in main.lua - as well as any other file you imported in your tool.

If you had declared it as local s =renoise.song(), then it would be accessible_only_within main.lua, but not other files.

If you had declared it aslocal s =renoise.song()within the scope of some function, it would only be accessible within that scope/function.

So, as you might understand it’s actually bad practice not to prefix things with local, unless you want to risk variables clashing with each other

(it gets tricky to keep the overview once you split code into multiple files…)

PS: If you’re planning to keep a single reference to renoise.song(), you definitely want to renew this variable once the song gets replaced

by attaching a notifier to this

renoise.tool().app_new_document_observable