Log In  

I'd like to access the global table (_G in lua)

for i in all(_G) do

Obviously it doesn't work (maybe because of the way pico8 processes caps?)

P#11151 2015-06-06 16:05 ( Edited 2015-06-07 21:54)

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!

P#11152 2015-06-06 17:21 ( Edited 2015-06-06 21:22)

well it was indeed mostly for debugging purposes
but there are also some small tricks to do with the global table

P#11165 2015-06-07 08:00 ( Edited 2015-06-07 12:00)

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. :)

P#11171 2015-06-07 17:54 ( Edited 2015-06-07 21:54)

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.

P#92847 2021-05-31 16:56

There is _ENV in pico8 lua (use Ctrl-P to enable puny mode that lets us type small caps, required for this name)

P#92864 2021-06-01 01:45

Thank you! That's pretty cool. Now I've managed to finish the class implementation. Will hopefully be posting soon.

P#92878 2021-06-01 08:29

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-02-02 15:49:13 | 0.006s | Q:16