Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between implicit and explicit io namespace functions in Lua

Tags:

lua

What is exact difference between implicit functions and explicit function in lua ? I came across these terms while reading about file operations in Lua.Implicit functions are preceded by io.like io.read()whereas explicit functions look something like file:read().I am clueless about the difference though the book says

The difference between the two is that implicit functions work on the default file as provided by the io namespace, whereas explicit functions work with a file handle provided from a previous operation,such as io.open

Any better explanation, please ?

like image 646
S Khurana Avatar asked Jan 25 '26 14:01

S Khurana


1 Answers

io.read reads from the default input file.

The default input file is stdin, but you change it by calling io.input.

You can also open a file explicitly with io.open and the use the returned handle in method calls, such as f:read().

io.read() is equivalent to io.input():read().

See also http://www.lua.org/manual/5.2/manual.html#6.8.

like image 82
lhf Avatar answered Jan 29 '26 01:01

lhf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!