Re: ipairs and metamethods in 5.3
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: ipairs and metamethods in 5.3
- From: Dirk Laurie <dirk.laurie@...>
- Date: 2017年7月27日 14:05:05 +0200
2017年07月27日 12:40 GMT+02:00 Pierre Chapuis <catwell@archlinux.us>:
> I tried to do something like this:
>
> local mp = require "MessagePack"
> local pretty = require "pl.pretty"
> pretty.dump(mp)
>
> the Penlight code does something like:
>
> for _ in ipairs(mp.packers) do end
>
> and it fails with:
>
> lua: /usr/share/lua/5.3/MessagePack.lua:46: pack '1' is
> unimplemented
>
> because of a metamethod on the `packers` table [1].
>
> How would you keep the feature of raising an error on direct access, but
> still make it work with `ipairs`?
Choose one.
1. Tell the developers of the two modules to get their act together.
2. Modify the copy of Penlight on your machine.
3. Redefine the global 'ipairs' (pl.pretty does not cache it locally)