Skip to content

Instantly share code, notes, and snippets.

@raingloom
Created November 25, 2015 17:46
Show Gist options
  • Save raingloom/85d4ac0d659f5d7bca37 to your computer and use it in GitHub Desktop.
Save raingloom/85d4ac0d659f5d7bca37 to your computer and use it in GitHub Desktop.
path up until current module (usually the current directory)
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