I'm trying to use the 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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With