diff options
author | Norbert Preining <norbert@preining.info> | 2023-03-08 03:03:20 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-03-08 03:03:20 +0000 |
commit | a0867c71356c67c442bdebc0de39b7996f847bf7 (patch) | |
tree | 744a3932d78fb03b904b3355ea7b59abd0678055 /macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua | |
parent | 4f55c9271affed648c1a939790a73083043752f5 (diff) |
CTAN sync 202303080303
Diffstat (limited to 'macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua')
-rw-r--r-- | macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua b/macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua new file mode 100644 index 0000000000..8590233242 --- /dev/null +++ b/macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua @@ -0,0 +1,20 @@ +return function(cmd) + local process = io.popen(cmd, "w") + + local function_table=lua.get_functions_table() + + -- https://tex.stackexchange.com/questions/632408/how-can-i-exclude-tex-macros-when-counting-a-strings-characters-in-lua/632464?noredirect=1#comment1623008_632464 this only work in Lua 5.3 or assume it's allocated sequentially + local send_content_index=#function_table+1 + function_table[send_content_index]=function() + process:write(token.scan_string()) + process:write("\n") + process:flush() + end + + local close_index=#function_table+1 + function_table[close_index]=function() + process:close() + end + + tex.print([[\protected \luadef \_pythonimmediate_send_content:e ]] .. send_content_index .. [[\protected \luadef \_pythonimmediate_close_write: ]] .. close_index .. [[\relax]]) + end |