LUA_INIT can replace require

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

LUA_INIT can replace require

Soni "They/Them" L.
[soniex2@soniex-pc lua]$ cat init.lua
local _require = require
require = function(...)
   print(...)
   return _require(...)
end
[soniex2@soniex-pc lua]$ LUA_INIT='@init.lua' lua -l init
init
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
 > ^C
[soniex2@soniex-pc lua]$

Is this intended?

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Coda Highland
On Sat, Feb 25, 2017 at 12:42 PM, Soni L. <[hidden email]> wrote:

> [soniex2@soniex-pc lua]$ cat init.lua
> local _require = require
> require = function(...)
>   print(...)
>   return _require(...)
> end
> [soniex2@soniex-pc lua]$ LUA_INIT='@init.lua' lua -l init
> init
> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>> ^C
> [soniex2@soniex-pc lua]$
>
> Is this intended?

It looks intended enough to me? This looks like the kind of thing
you'd use for debugging.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Soni "They/Them" L.


On 25/02/17 06:30 PM, Coda Highland wrote:

> On Sat, Feb 25, 2017 at 12:42 PM, Soni L. <[hidden email]> wrote:
>> [soniex2@soniex-pc lua]$ cat init.lua
>> local _require = require
>> require = function(...)
>>    print(...)
>>    return _require(...)
>> end
>> [soniex2@soniex-pc lua]$ LUA_INIT='@init.lua' lua -l init
>> init
>> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>>> ^C
>> [soniex2@soniex-pc lua]$
>>
>> Is this intended?
> It looks intended enough to me? This looks like the kind of thing
> you'd use for debugging.
>
> /s/ Adam
>

ldd for Lua?

https://en.wikipedia.org/wiki/Ldd_(Unix)

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Coda Highland
On Sat, Feb 25, 2017 at 4:11 PM, Soni L. <[hidden email]> wrote:

>
>
> On 25/02/17 06:30 PM, Coda Highland wrote:
>>
>> On Sat, Feb 25, 2017 at 12:42 PM, Soni L. <[hidden email]> wrote:
>>>
>>> [soniex2@soniex-pc lua]$ cat init.lua
>>> local _require = require
>>> require = function(...)
>>>    print(...)
>>>    return _require(...)
>>> end
>>> [soniex2@soniex-pc lua]$ LUA_INIT='@init.lua' lua -l init
>>> init
>>> Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>>>>
>>>> ^C
>>>
>>> [soniex2@soniex-pc lua]$
>>>
>>> Is this intended?
>>
>> It looks intended enough to me? This looks like the kind of thing
>> you'd use for debugging.
>>
>> /s/ Adam
>>
>
> ldd for Lua?
>
> https://en.wikipedia.org/wiki/Ldd_(Unix)
>
> --
> Disclaimer: these emails may be made public at any given time, with or
> without reason. If you don't agree with this, DO NOT REPLY.

I was thinking more like LD_PRELOAD than ldd.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Charles Heywood
In reply to this post by Soni "They/Them" L.
LUA_INIT is Lua code meant to run before other Lua code. If you wanted, you could probably nuke the entire standard library. I don't see why just because it can be "broken" it might be a misfeature.

On Sat, Feb 25, 2017 at 2:42 PM Soni L. <[hidden email]> wrote:
[soniex2@soniex-pc lua]$ cat init.lua
local _require = require
require = function(...)
   print(...)
   return _require(...)
end
[soniex2@soniex-pc lua]$ LUA_INIT='@init.lua' lua -l init
init
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
 > ^C
[soniex2@soniex-pc lua]$

Is this intended?

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


--
--

Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

彭 书呆
在 2017/2/26 11:51, Charles Heywood 写道:

> LUA_INIT is Lua code meant to run before other Lua code. If you wanted,you could probably nuke the entire standard library. I don't see why just because it can be "broken" it might be a misfeature.
>
> On Sat, Feb 25, 2017 at 2:42 PM Soni L. <[hidden email] <mailto:[hidden email]>> wrote:
>
>     [soniex2@soniex-pc lua]$ cat init.lua
>     local _require = require
>     require = function(...)
>        print(...)
>        return _require(...)
>     end
>     [soniex2@soniex-pc lua]$ LUA_INIT='@init.lua' lua -l init
>     init
>     Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
>      > ^C
>     [soniex2@soniex-pc lua]$
>
>     Is this intended?
>
>     --
>     Disclaimer: these emails may be made public at any given time, withor without reason. If you don't agree with this, DO NOT REPLY.
>
>
> --
> --
>
> Ryan <[hidden email] <mailto:[hidden email]>>
> Software Developer / System Administrator
> https://hashbang.sh

the environment variables are checked and loaded by the standalone interpreter, not the Lua core library.

for applications written to run via the standalone interpreter (instead of some host program embedding liblua),
arbitrary scripts can execute before the application, which may or may not cause problems.

maybe we can add a command line switch to disable environment variable processing?


--
the nerdy Peng / 书呆彭 /


Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Tony Papadimitriou
-----Original Message-----
From: 彭 书呆

>maybe we can add a command line switch to disable environment variable
>processing?

You mean like the -E switch since Lua v5.2?


Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

彭 书呆
在 2017/3/2 21:21, Tony Papadimitriou 写道:
> -----Original Message----- From: 彭 书呆
>
>> maybe we can add a command line switch to disable environment variable processing?
>
> You mean like the -E switch since Lua v5.2?
>
>

well, in my post I mean finer control over environment variables, e.g. I might want to skip the
processing of LUA_INIT but keep LUA_PATH/LUA_CPATH.

but I think the -E switch can be enough for most cases. How come I totally never know it before.


--
the nerdy Peng / 书呆彭 /

Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Soni "They/Them" L.


On 02/03/17 12:07 PM, 彭 书呆 wrote:

> 在 2017/3/2 21:21, Tony Papadimitriou 写道:
>> -----Original Message----- From: 彭 书呆
>>
>>> maybe we can add a command line switch to disable environment variable processing?
>> You mean like the -E switch since Lua v5.2?
>>
>>
> well, in my post I mean finer control over environment variables, e.g. I might want to skip the
> processing of LUA_INIT but keep LUA_PATH/LUA_CPATH.
>
> but I think the -E switch can be enough for most cases. How come I totally never know it before.
>
>

If you're gonna use the -E switch, what stops you from using the -e
"package.path = 'stuff here' .. package.path" switch?

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Charles Heywood
Literally nothing? I'm confused by this thread. If you don't want to use something, then *don't*.

On Thu, Mar 2, 2017 at 9:21 AM Soni L. <[hidden email]> wrote:


On 02/03/17 12:07 PM, 彭 书呆 wrote:
> 在 2017/3/2 21:21, Tony Papadimitriou 写道:
>> -----Original Message----- From: 彭 书呆
>>
>>> maybe we can add a command line switch to disable environment variable processing?
>> You mean like the -E switch since Lua v5.2?
>>
>>
> well, in my post I mean finer control over environment variables, e.g. I might want to skip the
> processing of LUA_INIT but keep LUA_PATH/LUA_CPATH.
>
> but I think the -E switch can be enough for most cases. How come I totally never know it before.
>
>

If you're gonna use the -E switch, what stops you from using the -e
"package.path = 'stuff here' .. package.path" switch?

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


--
--

Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

Soni "They/Them" L.


On 02/03/17 12:22 PM, Charles Heywood wrote:
> Literally nothing? I'm confused by this thread. If you don't want to
> use something, then *don't*.

It's called a rhetorical question, and you can read about them here:
https://en.wikipedia.org/wiki/Rhetorical_question

>
> On Thu, Mar 2, 2017 at 9:21 AM Soni L. <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>
>     On 02/03/17 12:07 PM, 彭 书呆 wrote:
>     > 在 2017/3/2 21:21, Tony Papadimitriou 写道:
>     >> -----Original Message----- From: 彭 书呆
>     >>
>     >>> maybe we can add a command line switch to disable environment
>     variable processing?
>     >> You mean like the -E switch since Lua v5.2?
>     >>
>     >>
>     > well, in my post I mean finer control over environment
>     variables, e.g. I might want to skip the
>     > processing of LUA_INIT but keep LUA_PATH/LUA_CPATH.
>     >
>     > but I think the -E switch can be enough for most cases. How come
>     I totally never know it before.
>     >
>     >
>
>     If you're gonna use the -E switch, what stops you from using the -e
>     "package.path = 'stuff here' .. package.path" switch?
>
>     --
>     Disclaimer: these emails may be made public at any given time,
>     with or without reason. If you don't agree with this, DO NOT REPLY.
>
>
> --
> --
> Ryan <[hidden email] <mailto:[hidden email]>>
> Software Developer / System Administrator
> https://hashbang.sh

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

nobody
In reply to this post by 彭 书呆
On 2017-03-02 16:07, 彭 书呆 wrote:
> well, in my post I mean finer control over environment variables,
> e.g. I might want to skip the processing of LUA_INIT but keep
> LUA_PATH/LUA_CPATH.

`LUA_INIT= lua <args>` should do the trick, setting a no-op LUA_INIT
(empty string/program) for that run and retaining LUA_(C)PATH.

Dropping LUA_(C)PATH is harder because of the many per-version
variations, but here `lua -E -e "dofile '${LUA_INIT:1}' <args>"` seems
to work with Bash. (If LUA_INIT points at a file, the ':1' drops the
leading @, leaving the path.)

-- nobody

Reply | Threaded
Open this post in threaded view
|

Re: LUA_INIT can replace require

彭 书呆
在 2017/3/3 9:59, nobody 写道:

> On 2017-03-02 16:07, 彭 书呆 wrote:
>> well, in my post I mean finer control over environment variables,
>> e.g. I might want to skip the processing of LUA_INIT but keep
>> LUA_PATH/LUA_CPATH.
>
> `LUA_INIT= lua <args>` should do the trick, setting a no-op LUA_INIT
> (empty string/program) for that run and retaining LUA_(C)PATH.
>
> Dropping LUA_(C)PATH is harder because of the many per-version
> variations, but here `lua -E -e "dofile '${LUA_INIT:1}' <args>"` seems
> to work with Bash. (If LUA_INIT points at a file, the ':1' drops the
> leading @, leaving the path.)
>
> -- nobody
>

thanks for the tips.

as I literally just got to know the -E switch, I didn't think through it.
now I realize I can just use -E to disable default environment processing
and use -e to manually handle what I need.

--
the nerdy Peng / 书呆彭 /