summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua')
-rw-r--r--macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua20
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