Log In  


I know this is kind of lazy, and you could just loop over a table with "pairs" and collect all of the keys, but is there a built in function that will return a table of any given table's keys? If not, then I'll implement my own, but I don't want to waste tokens where unnecessary.

Cheers in advance!

1


I can see how that'd be useful, but it's niche enough that it hasn't (to my knowledge) been implemented in PICO-8's "cozy" little API.

(I think even in regular Lua there's no helper for that, but I could be wrong.)

I'd probably just do it manually, as you indicated yourself:

for k in pairs(a) do b[#b+1]=k end

1

you could even implement it as an iterator so that you can use it like all():

function keys(t)
	local ks={}
	local i=0
	for k in pairs(t) do
		add(ks,k)
	end

	return function()
		i+=1
		if(i<=#ks)return ks[i]
	end
end

Then you can do for k in keys(obj) do...



[Please log in to post a comment]