Last active
August 29, 2015 13:56
-
-
Save dsimunic/9297989 to your computer and use it in GitHub Desktop.
Test if a lua file is runnnig standalone or is it required
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
-- Obviously, if a standalone file is called with an argument that corresponds to a loaded file, it will think it's required. | |
-- For example: | |
-- lua caller_test.lua _G | |
-- will choose the else branch. | |
-- For our purposes, though, this is good enough. | |
if not _G.package.loaded[...] then | |
print("Running standalone") | |
else | |
print("Required") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment