lua-users home
lua-l archive

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


On Tue, Oct 23, 2012 at 5:43 AM, Konstantinos Asimakis
<inshame@gmail.com> wrote:
> Sorry for the double post. I forgot to remove the triple ___ in some places,
> remove those before trying the code.
>
>
> On Tue, Oct 23, 2012 at 12:41 PM, Konstantinos Asimakis <inshame@gmail.com>
> wrote:
>>
>> --This goes somewhere very early in your code, before opening any file.
>> do
>>     local files={}
>>     local oldopen=io.open
>>     function io.open(f,m)
>>         local r=oldopen(f,m)
>>         ___files[r]=m
>>         return r
>>     end
>>     function io.getmode(handle)
>>         return ___files[handle]
>>     end
>> end
>>
>>
>> t=io.open("/dev/random","r")
>> --This will print "r".
>> print(io.getmode(t))
>> --And probably this would also work but I haven't tested it: t:getmode()
>
>

You would also want to return the error message from oldopen if any,
and set files as a weak table.

-- 
Sent from my Game Boy.