Can I see if a row matches a table name?
For example: I know that there is a table named "os" and I have the string "os" . Is there any way to do this:
x="os" if type(x)=="table" then print("hurra, the string is a table") end
Of course, this example does not work as I want, because
type(x)
just return the string.
The reason I want to do this is only because I want to list all the existing Lua tables, so I made this piece of code:
alphabetStart=97 alphabetEnd=122 function findAllTables(currString, length) if type(allTables)=="nil" then allTables={} end if type(currString)=="table" then allTables[#allTables+1]=currString end if #currString < length then for i=alphabetStart, alphabetEnd do findAllTables(currString..string.char(i), length) end end end findAllTables("", 2) for i in pairs(allTables) do print(i) end
I would not be surprised if there is an easier way to list all the existing tables, I just do it for fun in the Lua learning process.
lua
Michelrandahl
source share