bug-bash
[Top][All Lists]
Advanced

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

Re: Patch for autoload.v3 to allow export of function


From: Chet Ramey
Subject: Re: Patch for autoload.v3 to allow export of function
Date: Mon, 14 Aug 2017 10:30:49 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 8/11/17 6:55 PM, Matthew Persico wrote:

> What I propose to do between steps 2 and 3 is
> 
> 2.1 - After sourcing the function in, type the function to get its text
> 2.2 - type appears to pretty print function code. No matter how sloppy or
> compact your function is on disk, type presents it to you in a particular
> format. To wit, for a function 'foo'
> 
> foo is a function
> foo ()
> {
>     first line of code
>     ....
> }
> 
> That's regular. Therefore it can be parsed.
> 
> 2.3 - With the output of the type command, I strip out line 1 and after
> line 3, I add the text
> 
> local AUTOLOADED='foo'
> 
> 2.4 - evaling the modified code updates the function to include that line
> 
> 2.5 - Determining if a function is autoloaded is as simple as executing
> (something like)
> 
> $ type foo | grep 'local AUTOLOADED='foo'.
> 
> which is REALLY REALLY fast, even under Cygwin on Windows 10. Yeah, that's
> one of the environments I'm using for testing.
> 
> No more unexportable arrays and hashes. Self documenting. And 'AUTOLOADED'
> can be changed to something less likely to clash with existing code. And we
> document that any function you are going to autoload must avoid using the
> variable AUTOLOADED, or whatever it is eventually.
> 
> So, before I post code here, what say you all? Is the idea of doing this
> code injection so hideous that it would never be accepted, or is it worth
> submitting the code for perusal?

Of course it's worth submitting the code for folks to look at. It might be
possible to add a couple more checks to insulate it against possible future
changes to the `type' output.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]