Can’t it be set to inherit from Object? then it would be global to everything. You should look at the library that has the for-loop and for-each macros in them.
Sorry I can’t help with the error. Again I’d suggest looking at for-loop and for-each since it doesn’t seem like you’re doing anything particularly different than what they are doing.
GarnerP57 makes a good point about this setup and the dangers when interacting with latent function though.