lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


if ... then print"this is used by require" end

> On 12/05/2021 1:01 PM Paul Ducklin <pducklin@outlook.com> 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?
> 
> Thanks.