lua-users home
lua-l archive

Re: How can a module intentionally fail to load?

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


On 2018年08月07日 01:26 AM, Daurnimator wrote:
On 7 August 2018 at 14:19, Sean Conner <sean@conman.org> wrote:
But ...
print(package.loaded['org.conman.nfl.tls'])
userdata: 0x8064634
I think the userdata is the .so file (because each userdata in the TLS
module has a __tostring() method assigned to it), which is an unexpected
result.
Nope. It's a hack by lua5.1 to detect require loops. It was removed in
5.2 (yet another reason to upgrade!)
$ lua5.1 -e 'package.preload.foo=function() error("foo") end;
pcall(require,"foo"); print(package.loaded.foo)'
userdata: 0x4216d4
$ lua5.2 -e 'package.preload.foo=function() error("foo") end;
pcall(require,"foo"); print(package.loaded.foo)'
nil
you *could* do it like this:
$ lua5.1 -e 'package.preload.foo=function() package.loaded.foo=nil; error("foo") end; pcall(require,"foo"); print(package.loaded.foo)'
nil

AltStyle によって変換されたページ (->オリジナル) /