summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/pythonimmediate/pythonimmediate_helper.lua
blob: 8590233242c07c320063ca35a08f7f90376228fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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