It looks like you're new here. If you want to get involved, click one of these buttons!
In my program it would be very helpful to have a function that would do the following:
--the function I want is wantedFunction()
mt={}
t=setmetatable({},mt)
t2=setmetatable({},mt)
wantedFunction(mt) --should return {t,t2}
In other words, if i have a table which is a metatable, is there any way to write a function to find all of the tables it is a metatable for?
Also, I'm new to this forum, so any info as to how to make my posts better is appreciated.
Comments
http://codea.io/talk/discussion/275/faq-please-read#latest
@Jmv38 Thanks, that helped a lot! I was able to make my question much clearer.
@time4coding - try this, it's a bit of a kludge because it loops through every object in memory to get the list - but it is fast. The variable _G is worth exploring, it is a table holding absolutely everything.
Precision: _G holds everything that is *top level* : it doesnt see local variables, or objects recorded inside tables only. (@Ignatz: i know you know).
You probably want to access only some special metatables, corresponding to some class you've created? If so you can simply record each object when it is created:
here
example
variable is the metatable of every object you create withexample("xx")
, so it looks pretty much like what you wanted (a list of all objects with this metatable).Both of these methods work great! Thanks for introducing me to _G too.
@time4coding - welcome to the forum, by the way. :-h
@Jmv38 thanks for that, I was able to use it for resetting all my buttons when a popup occured
@time4coding welcome to the forum indeed