[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modules with standalone main program
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 24 Feb 2018 22:37:04 +0200
2018-02-24 21:46 GMT+02:00 Paul K <paul@zerobrane.com>:
>> Unfortunately, the conclusion was that there seems to be no fail-proof method.
I don't need a fail-proof method. I need a method that works for a
one-file module of which I know the name by which it will be required.
> 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
It does not do what I want.
$ lua
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
> dofile"lmodules/mod.lua"
package
I.e. "doflile" is treated just like "require'.
I want "require" to return and all other ways of running the file to continue.