Debian Codegraph @

texmf-dist/tex/lualatex/lua-ul/docstrip-luacode.sty

raw
1 %% Copyright (C) 2020-2024 by Marcel Krueger
2 %%
3 %% This file may be distributed and/or modified under the
4 %% conditions of the LaTeX Project Public License, either
5 %% version 1.3c of this license or (at your option) any later
6 %% version. The latest version of this license is in:
7 %%
8 %% http://www.latex-project.org/lppl.txt
9 %%
10 %% and version 1.3 or later is part of all distributions of
11 %% LaTeX version 2005/12/01 or later.
12
13 \NeedsTeXFormat{LaTeX2e}
14 \ProvidesPackage
15 {docstrip-luacode}
16 [2021/05/12 v0.1.4 Directly execute Lua code from DocStrip files]
17 \RequirePackage{iftex}
18 \RequireLuaTeX
19 \expanded{%
20 \def\noexpand\docstrip@luacode@argscanner#1\directlua{
21 tex.sprint(\the\catcodetable@string, "\string\\end{docstrip-luacode}")
22 local scanner = token.create'docstrip@luacode@argscanner'
23 local file = lpeg.Ct((lpeg.P'\csstring\%' * (1-lpeg.P'\string\r')^0 + lpeg.C((1-lpeg.P'\string\r')^0) * '\string\r')^0)/function(s)return table.concat(s,'\string\n')end
24 local func = luatexbase.new_luafunction'docstrip-luacode'
25 token.set_lua('docstrip-luacode', func, 'protected')
26 lua.get_functions_table()[func] = function()
27 local name = token.scan_string()
28 tex.catcodetable = \the\catcodetable@string
29 tex.setcatcode(32, 12)
30 token.put_next(scanner)
31 token.scan_token()
32 package.preload[name], msg = loadstring(file:match(token.scan_string()))
33 end
34 }{\relax{#1}\noexpand\end{docstrip-luacode}}}
35 \endinput