lua-users home
lua-l archive

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


It was thus said that the Great Viacheslav Usov once stated:
> On Wed, Nov 16, 2022 at 8:13 PM Sean Conner <sean@conman.org> wrote:
> 
> >   Perhaps I'm unwise in following "play stupid games, win stupid prizes"
> > (i.e. trusting a programmer to not nil out __gc metamethods) but I really
> > have to wonder how much of an issue this really is.  Do you have actual code
> > this breaks?  Or is this more of a "hypothetical, someone might, possibly,
> > break some code I wrote" type of issue?  (and am I asking for trouble for
> > asking for an actual example?  Am I stupid for not thinking this is an
> > issue?  Should every Lua module written in C do the same as Lua's io
> > library?)
> 
> I found it surprising, in the old discussion, and, apparently, in the
> ensuing discussion, how something obviously wrong was being declared
> no big deal or even desirable. 

  The difference is of opinion.  I do not think this is obviously wrong, nor
have I been convinced that it's even wrong.  I think that monkeypatching [1]
is wrong, and I will try to disuade people from doing it ("play stupid
games" and all that), but I do admit that it is sometimes desirable to do
[2] and won't try to make it impossible.

  -spc

[1]	Changing the behavior of a language or system at runtime.  It's
	quite popular in Ruby for instance.

[2]	I've done it.  I've added a "_tofd" function [3] to Lua's metatable
	for files to obtain the underlying Unix file descriptor to relieve
	the programmer from having to do this each time they want to add a
	file to my select() wrapper [4].  I have the same method in my
	network wrapper [5].

[3]	https://github.com/spc476/lua-conmanorg/blob/c8c4068f913e6995050c3315cec3780620764673/src/fsys.c#L1365

[4]	https://github.com/spc476/lua-conmanorg/blob/master/src/pollset.c

[5]	https://github.com/spc476/lua-conmanorg/blob/c8c4068f913e6995050c3315cec3780620764673/src/net.c#L1470