Open cosme12 opened 1 month ago
Running this code in LuaRT Studio will show all object instances types as a "table"
when using the type()
function, because LuaRT Studio keeps compatibility with all Lua 5.4 compatible interpreters.
If you run this example from the command line, it will work as expected (it will print "File" or "Directory" as expected)
To check instances type, it's better to use the is()
function (working in LuaRT Studio and from the command line) :
for entry in each(sys.Directory("."):list("*.*")) do
if is(entry, sys.File) then
print(entry.name)
else -- entry is a directory
print(entry.fullpath:match("\\.*\\([%w%p]+)$").."\\")
end
end
Hi, I was trying to list all files in a directory. Looking at the documentation example here: Directory.list() when the
type()
is checked it always returnstable
. For both, the type of File and Directory istable
, so everything falls under theelse
condition. Hope I explained myself.Any idea how I could check the "real" type? Thanks!