lua-users home
lua-l archive

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

> > The documentation for luaL_loadfilex specifies that it'll return
> > LUA_ERRFILE when the file has the wrong mode:
> >
> >     "This function returns the same results as lua_load, but it has an
> >     extra error code LUA_ERRFILE if it cannot open/read the file or the
> >     file has a wrong mode."
> >
> > Sadly, this does not seem to be the case as the error code
> > LUA_ERRSYNTAX is returned instead.
> >
> > Here we attempt to load the empty file 'test.lua' in binary mode:
> >
> >     int status = luaL_loadfilex(L, "test.lua", "b");
> >
> > Since 'test.lua' is not a valid Lua bytecode binary file, I would've
> > expected the status code to be LUA_ERRFILE as documented. Is this a
> > documentation error by any chance?
> >
> > I've attached a sample program that demonstrates this behaviour.
> >
> > Thanks!
> I think the 'mode' referred to is the actual 'mode' of the file on the
> disk (like what is returned by `stat`).
> e.g. if you call luaL_loadfilex on a directory, it will return LUA_ERRFILE

That is correct. As the "FILE" in "LUA_ERRFILE" hints, this code is used
only for file-related problems. We will try to make that clearer in the

-- Roberto