[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: What's wrong with this Lua code?
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 17 Jun 2017 07:31:13 +0200
2017-06-16 21:45 GMT+02:00 Soni L. <firstname.lastname@example.org>:
> I have this Lua code:
> local string = "" print(string.format("%X", 16777216))
> And it works perfectly, but I was told it's wrong? What's wrong with it? Why
> shouldn't I do this?
You have had two thorough replies from people I respect a lot,
but an overriding problem with cute code like that is that it redefines
a global to something that is not backward compatible.
Before you did that, one could add useful PERLy methods to 'string'.
Several articles on the Wiki, e.g. StringTrim. After you did that, you
must add them to 'getmetatable"".__index'.
I.e. your code is not wrong, but the trick should only be used on
purpose to discourage custom extensions to the string library.