lua-users home
lua-l archive

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


On 09/25/2014 08:57 AM, Rena wrote:
On Wed, Sep 24, 2014 at 10:48 AM, Peng Zhicheng <pengzhicheng1986@gmail.com <mailto: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.

yes, you are right.
sorry for my previous reply with wrong infomation.

I didn't use `module` for very long. I don't remember what `module` exactly does.
I just vaguely recall it has something to do with `setfenv`.

but anyway, `module` is 5.1; I don't think checking the `_NAME` field is a reliable
solution for OP's problem.