lua-users home
lua-l archive

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




On Thursday, July 9, 2015, Soni L. <fakedme@gmail.com> wrote:


On 09/07/15 02:54 AM, Daurnimator wrote:
On 9 July 2015 at 15:40, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2015-07-09 5:57 GMT+02:00 Soni L. <fakedme@gmail.com>:
On 08/07/15 11:12 PM, Luiz Henrique de Figueiredo wrote:
Use
         debug.setmetatable(nil, {__index = {}})

I should make a library for this that doesn't require debug.
Why are many Lua programmers reluctant to use the debug library?

Lua 5.3.1 Reference Manual on the debug library:

| This library provides the functionality of the debug interface (§4.9)
| to Lua programs. You should exert care when using this library.
| Several of its functions violate basic assumptions about Lua code
| (e.g., that variables local to a function cannot be accessed from
| outside; that userdata metatables cannot be changed by Lua code;
| that Lua programs do not crash) and therefore can compromise
| otherwise secure code. Moreover, some functions in this library
| may be slow.

This is daunting, certainly, but it used to be worse.

Lua 5.1.5 Reference Manual on the debug library:

| The functions provided here should be used exclusively for debugging
| and similar tasks, such as profiling. Please resist the temptation to use
| them as a usual programming tool

By reading these together, one can draw the conclusion that the Lua
developers no longer feel that the debugging library is only there for
debugging, profiling etc, and that it is now OK to use its functions
as
a usual programming tool provided that you exert care.

So why are we still squeamish about it?

It's sort of a 'here be dragons' indication:
Once the debug library is in use, it can break many assumptions.

Furthermore, in this *particular* instance, a global behaviour change
is being made.
Any well made library should generally have no global side effects.

And if it causes a metamethod yield it could have unintended consequences.

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.


I think that it is largely because its name is "debug". 

Picking off key methods and setting debug to nil is safe, but if you're dreaming of writing reusable code that is used in a module, it might be considered good policy to not count on debug being there. 

-Andrew