lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2014-01-21 11:18, Luiz Henrique de Figueiredo wrote:
A call to io.read() between the two loadfile()() statements fixes
the problem (Linux again).

Same here, Mac OS X (10.7.5).

,,io.read()'' clears (by ,,g_read()'') end-of-file indicator using
,,clearerr()''. This is why I proposed ,,clearerr()'' function as a
solution to the problem: the method exists, although elsewhere. IMO,
,,io.read()'' is too heavy to use it as a ,,caller stub'' of
,,clearerr()''. Besides that it clears EOF _before_ any IO is made, thus
it is possible to return to the invalid state:

==============
loadfile()()
^Z
io.read()
^Z
loadfile()()
--
stdin:1: attempt to call a nil value
stack traceback:
stdin:1: in main chunk
[C]: in ?
stdin:1: unexpected symbol near '-'
==============

Although, ,,io.read()'' cleared EOF indicator of ,,stdin'', it has been
set on again by ,,^Z/^D''. IMO inserting ,,clearerr()'' into
,,luaL_loadfilex()'' directly (as in ,,g_read()'') works fine as for now.

--
-- best regards

Cezary H. Noweta