luapath.lua - or whatever you want to call it
This allows plugin authors to have the lua directory for their plugins added to the lua search path
findfile.lua - or whatever you want to call it
I use it like this:
Searches for a file given a path, useful for dofile and not having to worry about where the actual file is.
Bast
plugin_path = string.match(GetPluginInfo(GetPluginID(), 6), "(.*)\.*$") .. "\lua\"
package.path = plugin_path .. "?;" .. plugin_path .. "?.lua;" .. package.path
This allows plugin authors to have the lua directory for their plugins added to the lua search path
findfile.lua - or whatever you want to call it
-- this finds a file searching from path including all subdirectories
function scan_dir_for_file (path, tfile)
-- find all files in that directory
local t = assert (utils.readdir (path .. "\*"))
for k, v in pairs (t) do
if not v.hidden and
not v.system and
k:sub (1, 1) ~= "." then
-- recurse to process file or subdirectory
if v.directory then
found = scan_dir_for_file (path .. "\" .. k, tfile)
if found then
return found
end
elseif k == tfile then
return path .. "\" .. k
end -- if
end -- if
end -- for
return false
end
I use it like this:
require "filefind"
nfile = scan_dir_for_file (GetInfo(60), "telnet_options.lua")
if nfile then
-- pull in telnet option handling
dofile (nfile)
else
print("Could not load telnet_options.lua, please copy it to your plugins directory")
end
Searches for a file given a path, useful for dofile and not having to worry about where the actual file is.
Bast