Python has dir (obj) and help (obj), is there an equivalent in Lua?

For anyone not familiar with these two methods in Python ...

dir returns a list of methods / properties of a particular object.

helpreturns doc string objects .

+3
source share
2 answers

Lua has no concept of a "document line".

All Lua objects are tables (or user data, but you cannot check user data from Lua code. Well, not in Lua 5.1, in 5.2 you can do this if the user who created the user data wants you). Therefore, you can simply use existing table methods to iterate over the contents of the table:

for k, v in pairs(obj) do
  --Do stuff with k(ey) and v(alue)
end

, , . , , , , , .

+3

:

function dir(obj)
    for k, v in pairs(obj) do print(k) end
end

"dir" python Lua.

0

All Articles