Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_REQUIREDNAME always nil

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?

like image 600
David Brown Avatar asked May 19 '10 22:05

David Brown


1 Answers

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).

like image 124
interjay Avatar answered Nov 12 '22 05:11

interjay