[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Equivalent to __name__ == “_main__”?
- From: Victor Bombi <sonoro@...>
- Date: Mon, 6 Dec 2021 20:14:39 +0100 (CET)
if ... then print"this is used by require" end
> On 12/05/2021 1:01 PM Paul Ducklin <firstname.lastname@example.org> wrote:
> Excuse my ignorance, but is there a “official” (read: preferred/reliable) way to detect that you have run a module directly as a program instead of loading it with require()?
> Like the “name == main” trick in Python?
> I have seen suggestions to use debug.getinfo() to probe the call stack depth, and testing whether the stack is too shallow to be inside a call to require(). Does that work? Is there a better way?