lua-users home
lua-l archive

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


On Wed, Sep 24, 2014 at 10:48 AM, Peng Zhicheng <pengzhicheng1986@gmail.com> wrote:
On 09/22/2014 08:22 PM, zzf wrote:

in lua module
if _NAME == nil then
    test()
end
equals
if __name__ == “__main__”:

like this:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require('md5')
> print(md5._NAME)
md5
>

No, you have taken it wrong -- the _NAME field of the module is set by the module itself, not by Lua.
if the module does not set it, it won't be there.

if you check your md5.lua, you would probably see something like this:

~~~
module("md5", package.seeall)
_NAME = "md5"
_VERSION = <...>
_COPYRIGHT = <...>
<...>
~~~





Doesn't module() set M._NAME?

--
Sent from my Game Boy.