[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Proposal: Virtualization of Filesystem Operations for Lua 5.2.
- From: HyperHacker <hyperhacker@...>
- Date: Wed, 2 Nov 2011 16:54:01 -0600
On Wed, Nov 2, 2011 at 16:29, Petite Abeille <email@example.com> wrote:
> On Nov 2, 2011, at 11:11 PM, Patrick Rapin wrote:
>> This apart, I like very much that proposal. If such a file system
>> visualization existed in 5.1, I could have used it to load modules
>> from a ZIP file, instead of patching Lua source code.
>> And I could have written a driver for our printer firmware pseudo file
>> system, instead of removing the "io" library and writing a custom
> FWIW, I like Georg Lehner proposal as well :)
> That said, one could easily "virtualize/overload" the existing io module to suit its need.
> For example:
> local io = require( 'io' )
> local ioopen = io.open
> io.open = function( filename, mode, ... )
> -- do stuff depending on mode
> -- or default back to the standard implementation
> return ioopen( filename, mode )
One of my favourite features of Lua is you can replace anything. You
could add support for reading zip files transparently by replacing
io.open and friends with your own wrappers, for example. Talk about
"drivers" that seem to be meant to define how functions behave seems a
bit redundant when you can change their behaviour already by replacing
Also, I'd definitely want "chdir" rather than "cd". Readability is good.
Sent from my toaster.