Package Path

lua-users home
wiki

When you type

whatever = require "whatever"       

Lua tries to find a package named whatever in many places, mostly having whatever somewhere in their names. If none of these is found, Lua gives an error message listing them all, something like

stdin:1: module 'whatever' not found:
	no field package.preload['whatever']
	no file '/usr/local/share/lua/5.2/whatever.lua'
	no file '/usr/local/share/lua/5.2/whatever/init.lua'
	no file '/usr/local/lib/lua/5.2/whatever.lua'
	no file '/usr/local/lib/lua/5.2/whatever/init.lua'
	no file './whatever.lua'
	no file '/usr/local/lib/lua/5.2/whatever.so'
	no file '/usr/local/lib/lua/5.2/loadall.so'
	no file './whatever.so'
stack traceback:
	[C]: in function 'require'
	stdin:1: in main chunk
	[C]: in ?

A schematic representation of that list is kept in the variable package.path. For the above list, that variable contains

/usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.lua

RecentChanges · preferences
edit · history
Last edited February 23, 2013 3:21 pm GMT (diff)