Choice of processor
Philip Taylor
P.Taylor at Hellenic-Institute.Uk
Wed Mar 5 12:59:19 CET 2025
On 05/03/2025 11:50, Joseph Wright wrote:
>
> The above [snipped] relies on various other bits of Lua as LaTeX does
> various bits
> of emulation and tracks things. For a one-off use, you could go with
>
> \directlua{
> local t = lua.get_functions_table()
> local minus_tok = token.new(string.byte('-'), 12)
> local zero_tok = token.new(string.byte('0'), 12)
> local one_tok = token.new(string.byte('1'), 12)
> t[1] = function()
> local first = token.scan_string()
> local second = token.scan_string()
> if first < second then
> token.put_next(minus_tok, one_tok)
> else
> token.put_next(first == second and zero_tok or one_tok)
> end
> end
> }
> \luadef\strcmp 1 %
> \strcmp{A}{A}
> \strcmp{A}{B}
> \strcmp{B}{A}
> \bye
>
> which hard-codes that we are using a known Lua function - done like
> this, \strcmp has the same behaviour as a primitive.
Thank you very much, Joseph — much appreciated. But could I trouble to
explain the "\luadef\strcmp 1 % " part ? Does that in some way bind
\strcmp to the preceding \directlua code ?
--
/** Phil./
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/texhax/attachments/20250305/fce9f388/attachment.htm>
More information about the texhax
mailing list.