[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Privately patching strings lib in Lua 5.2
- From: Andrew Starks <andrew.starks@...>
- Date: Sat, 21 Dec 2013 07:54:37 -0600
On Saturday, December 21, 2013, steve donovan wrote:
On Sat, Dec 21, 2013 at 3:54 AM, Hisham <h@hisham.hm> wrote:
> ...but that introduces a global change to your environment, anyway.
It's a valid tactic if you're fully in control of your application,
although redefining _existing_ functions is the kind of
monkey-patching that gave Ruby a bad name (because it changes the
semantics of any loaded libraries).
In Penlight, I let people choose whether they want to bring the
extended string functions pl.stringx into string itself, so people can
use them with a colon. Personally I only do this when writing scripts,
not programs.
(An idea that has been floating around: tying string/function/etc
metatable resolution to the environment, so one can write modules as
one pleases without messing with everyone else's modules. But this
does not necessarily lead to nice clear self-evident code ;))
I think that this would be a decent enough idea for the strings table, but it's not a big issue. As it is, it leads me to choose between a completely pure environment existing outside of my heavily patched sandbox and one with a modified string table.
The only negative concequence being that I need something like "stringx" to keep it pure, which isn't so bad.
Of course, there might be other use cases for ENV scoped metatables on base types... I haven't pondered that...
-Andrew