[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: file:write() fails silently for read-only files
- From: Josh Simmons <simmons.44@...>
- Date: Tue, 6 Sep 2011 17:25:24 +1000
On Tue, Sep 6, 2011 at 5:21 PM, startx <startx@plentyfact.org> wrote:
> On Tue, 6 Sep 2011 01:12:07 -0600
> HyperHacker <hyperhacker@gmail.com> wrote:
>
>>> On Tue, Sep 6, 2011 at 01:10, startx <startx@plentyfact.org> wrote:
>> > hm, when i do that ( on linux ) i _do_ get an error
>> >
>> > lua: filer.lua:2: attempt to index global 'f' (a nil value)
>> > stack traceback:
>> > filer.lua:2: in main chunk
>> > [C]: ?
>> >
>> > startx
>> >
>> >
>
>>
>> You'd need to create a file "foo.foo" first...
>>
>
> yes, you are correct.
>
> however, you do something like
>
> f = io.open('foo.foo', 'r')
> success = f:write('ffd')
> f:close()
>
> success will be NIL if the file cannot be written to.
> one one hand i see your point that it could throw an error instead, but
> then again ...
>
> startx
>
>
>
>
Lua's general policy is to throw errors when there's programmer error
(like 'coroutine.wrap(7)', and return nil+error message for
environmental issues (like files missing or bad permissions).