Created
November 25, 2015 17:46
-
-
Save raingloom/85d4ac0d659f5d7bca37 to your computer and use it in GitHub Desktop.
path up until current module (usually the current directory)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local prefix = ... and (...):match '(.-%.?)[^%.]+$' or '' | |
print( prefix ) | |
--preserves last dot | |
--possible improvement: get module separator from package.config, usually not needed | |
--[[examples | |
require 'module.submodule' | |
module. | |
require 'long.path.to.submodule' | |
long.path.to. | |
dofile 'module.lua' | |
--prints empty string, fault tolerant | |
]] | |
require( prefix..'othersubmodule' ) | |
--won't blow up if (...) is nil | |
--does not need extra dot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment