Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
what should the value of an emptied table be? — Gideros Forum

what should the value of an emptied table be?

piepie Member
edited October 2015 in General questions
Hi, I am facing a small issue with string indexed arrays.

I need to "intercept" a table (t, loaded from json), remove one or more entries (according to their index), and pass it through the next step of code if there is some entry left (there could be some).

I thought I could just nil the entries (as in example below) and later detect if t is empty to proceed:
the problem is that t is not empty, and I can't use the lenght operator # as a parameter because indexes are strings.

How do I check if t is "empty"? Or how do I remove the entries I need to remove from it, to leave t empty (if there are no other entries left) ?
t = { 
m = {1,3,4,5,"pp"},
n= {"foo"}
}
 
 
t["n"] = nil
t["m"] = nil
 
print("T", t, t == {}) -- t == {} is false, why?
 
for i,v in pairs(t) do
print(i,v)
	for j,k in pairs(v) do
		print(j,k)
	end
end
Thank you :)

[edit: I noticed that I get nil if I use getmetatable (t) on the empy table, that seems to solve my problem ]

Comments

Sign In or Register to comment.