lua-users home
lua-l archive

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


> Unfortunately, the conclusion was that there seems to be no fail-proof method.

I already suggested a method earlier that works with Lua 5.1+ and
handles command line parameters as well as require/dofile calls:

if pcall(debug.getlocal, 4, 1) then
  print("package")
else
  print("main script")
end

Paul.

On Sat, Feb 24, 2018 at 11:36 AM, Tony Papadimitriou <tonyp@acm.org> wrote:
> This method will fail if there are command line parameters.
>
> Unfortunately, the conclusion was that there seems to be no fail-proof
> method.
>
> This is a very important feature but there is zero interest from the Lua
> team to provide a reliable method.
>
>> You mean like this?
>> ...
>> Here's my "module":
>>
>> if ... then
>>  print("I was included as a module")
>>  return {}
>> end
>>
>> print("I was executed as a program")
>
>
>