_REQUIREDNAME always nil
I'm trying to use t开发者_JS百科he method for naming a lua package after the filename mentioned here, however _REQUIREDNAME
is never defined. For example I have these two files
samplePackage.lua:
print("_REQUIREDNAME: ", _REQUIREDNAME)
return nil;
packageTest.lua:
require "samplePackage"
And when I run packageTest.lua it outputs > _REQUIREDNAME: nil
I also couldn't find any mention of _REQUIREDNAME in the Lua 5.1 Refrence manual, so was this removed from the language, or am I missing something?
The way that packages and modules work underwent some major changes in Lua 5.1, making the first edition of Programming in Lua mostly obsolete regarding that subject.
In 5.1, the module name is passed as an argument to the module by require
. You can access it with ...
:
print("Module name: ", ...)
The second edition of Programming in Lua covers Lua 5.1. It isn't free, but the chapter about packages and modules is available as a sample (PDF).
精彩评论