> On 19 Aug 2025, at 15:25, Henning Hraban Ramm <te...@fiee.net> wrote:
> 
> Hi Bruce,
> 
> Am 19.08.25 um 03:35 schrieb Bruce Horrocks:
>>> On 18 Aug 2025, at 18:34, Henning Hraban Ramm <te...@fiee.net> wrote:
>>> 
>>> I guess that was what I was asking for, but not what I needed.
>> I'm still confused as to what you're actually trying to do!
> 
> In a module, I want to accept paths that contain ~ (=$HOME) or other shell 
> variables.
> 
> For my current needs, I only need to expand ~, but I’m trying to learn to do 
> things in Lua that I know in Python.

The expansions that wordexp() does are documented here:
<https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html#tag_19_06>

If you only need "~" for now then I suggest creating a pure Lua function that 
does that only. You can add to its capabilities over time as more is needed and 
what you end up with will be more secure than wrapping wordexp() because you 
can skip things like command substitution.

> $TEXMFsomething was a bad example since the TeX variables contain a list of 
> directories.
> 
> An OS independent solution would be best – since it’s %HOME% on Windows, 
> AFAIK.
> 
>> 1) Do you want a list of all environment variables that are set? If so and 
>> your target system is Unix-like, then there is the command `printenv` that 
>> you could call via os.execute("printenv").
> 
> no
> 
>> 2) Do you want process a string containing a file path where some of the 
>> components might be environment variables and you want to expand them the 
>> way the shell would?
> 
> yes
> 
>> If so then there is a Posix function `wordexp` (man 3 wordexp) which does 
>> that. You'll need to wrap it in a C API call.
> 
> wordexp looks like the right thing, but I don’t speak C – would I need to 
> write & compile some C code for that? It looks like that in the Lua manual.

You would need to write some C.

The problem you will have in learning how to do this is that most of the 
examples on-line assume you are starting with a larger C program that has a Lua 
engine embedded in it, and the Lua is calling a routine defined in that larger 
C program.

This is not the case with Context since Context or rather LuaMetaTeX is that 
larger C program, and so you would need to add your code to it or somehow load 
a dynamic library. Not impossible but life would be a lot easier if Hans 
accepted a patch that added it alongside those extra Lua helper functions that 
are already in there.

Regards,
—
Bruce Horrocks
Hampshire, UK

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to