luatex original locale info

luigi scarso luigi.scarso at gmail.com
Thu Feb 22 00:44:15 CET 2024


On Wed, 21 Feb 2024 at 23:34, Karl Berry <karl at freefriends.org> wrote:

>     While LuaTEX is running if forces the following locale settings:
>     LC_CTYPE=C
>     LC_COLLATE=C
>     LC_NUMERIC=C
>
> No question those settings are needed, but luatex could also provide the
> original settings of those vars, just so programs can get the info if
> they want it. (LC_CTYPE_orig, or a separate table, or whatever.)
>
> Is it worth considering? Wdy(all)t? --thanks, karl.
>

In luainit.c we have this
 /*tex
        Get the current locale (it should be |C|) and save |LC_CTYPE|,
|LC_COLLATE|
        and |LC_NUMERIC|. Later |luainterpreter()| will consciously use
them.
    */
    old_locale = xstrdup(setlocale (LC_ALL, NULL));
    lc_ctype = NULL;
    lc_collate = NULL;
    lc_numeric = NULL;
    if (old_locale) {
        /*tex
            If |setlocale| fails here, then the state could be compromised,
and
            we exit.
        */
        env_locale = setlocale (LC_ALL, "");
        if (!env_locale && !lua_only) {
            fprintf(stderr,"Unable to read locale data: please check the
'locale' settings of your environment for consistency. Exiting now.\n");
            exit(1);
        }
        tmp = setlocale (LC_CTYPE, NULL);
        if (tmp) {
            lc_ctype = xstrdup(tmp);
        }
        tmp = setlocale (LC_COLLATE, NULL);
        if (tmp) {
            lc_collate = xstrdup(tmp);
        }
        tmp = setlocale (LC_NUMERIC, NULL);
        if (tmp) {
            lc_numeric = xstrdup(tmp);
        }
        /*tex
            Return to the previous locale if possible, otherwise it's a
serious
            error and we exit: we can't ensure a 'sane' locale for lua.
        */
        env_locale = setlocale (LC_ALL, old_locale);
        if (!env_locale) {
          fprintf(stderr,"Unable to restore original locale %s: exiting
now.\n",old_locale);
          exit(1);
        }
        xfree(old_locale);
    } else {
       fprintf(stderr,"Unable to store environment locale.\n");
    }
    /*tex make sure that the locale is 'sane' (for lua) */
    putenv(LC_CTYPE_C);
    putenv(LC_COLLATE_C);
    putenv(LC_NUMERIC_C);


%%test.tex
\directlua{
print()
print(status.lc_ctype,status.lc_collate,status.lc_numeric)
}
\end


$>luatex test.tex

See 10.2 The status library in luatex.pdf


--
luigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/tex-live/attachments/20240222/58e63414/attachment.htm>


More information about the tex-live mailing list.