There are already have ways to detect global variable accesses at compile time
Notice that current tools won't help you here:your chunk is embedded as a bytecode string (or maybe a source string), and therefore contains no variable, global or local. You could probably modify an existing tool to recursively check strings constants starting with "\027Lua", though.