Skip to content

Instantly share code, notes, and snippets.

@dsimunic
Last active August 29, 2015 13:56
Show Gist options
  • Save dsimunic/9297989 to your computer and use it in GitHub Desktop.
Save dsimunic/9297989 to your computer and use it in GitHub Desktop.
Test if a lua file is runnnig standalone or is it required
-- 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