io.type()

Type Function
Library io.*
Return value String
Revision Release 2022.3683
Keywords io, type, file
See also io.open()

Overview

Checks whether obj is a valid file handle. Returns the string "file" if obj is an open file handle, "closed file" if obj is a closed file handle, or nil if obj is not a file handle.

Syntax

io.type( obj )
obj (required)

Object. Object to be tested.

Example

local fh
print( io.type( fh ) )  --> nil
 
local path = system.pathForFile( "Icon.png", system.ResourceDirectory )
fh = io.open( path )
print( io.type( fh ) )  --> "file"
 
io.close( fh )
print( io.type( fh ) )  --> "closed file"