I'd like to access the global table (_G in lua)
for i in all(_G) do print(i) end |
Obviously it doesn't work (maybe because of the way pico8 processes caps?)
It's currently broken in two places -- one is because of not supporting caps, and the other is that all() expects only an integer-indexed array.
I plan to review the way all() works, and could possibly also alias _G to _g. Out of curiosity, what kind of thing would you use it for? Might be useful for debugging, but apart from that I imagined pico-8 would be too limited to do anything fancy with it!
well it was indeed mostly for debugging purposes
but there are also some small tricks to do with the global table
I wanted to use it for game state management, with generated function names before I discovered that it doesn't work. Something like _G[statename+"_init"](), _G[statename+"_update"]() etc. so i don't need to hold references for those functions just adhere to a naming convention.
I don't know how much sense that would make anyway, I just don't like the way I currently doing this, and that was one of the ideas how to change it. :)
I wanted to have _G because I was working on a class implementation for PICO-8 and needed to generate a function which represents the constructor.
There is _ENV in pico8 lua (use Ctrl-P to enable puny mode that lets us type small caps, required for this name)
Thank you! That's pretty cool. Now I've managed to finish the class implementation. Will hopefully be posting soon.
[Please log in to post a comment]