@@ -1779,12 +1779,53 @@ When called interactively, switch to the process buffer."
17791779 (set-marker lua-region-end (or arg (point ))))
17801780
17811781(defun lua-send-string (str )
1782- " Send STR plus a newline to Lua subprocess.
1782+ " Load STR plus a newline into Lua subprocess.
17831783
17841784If `lua-process' is nil or dead, start a new process first."
1785- (unless (string-equal (substring str -1 ) " \n " )
1786- (setq str (concat str " \n " )))
1787- (process-send-string (lua-get-create-process) str))
1785+ (let ((tmp-file (make-temp-file " luamode" nil " .tmp" ))
1786+ (lua-process (lua-get-create-process)))
1787+ ; ; write data into temporary file
1788+ (with-temp-buffer
1789+ (insert (if (string-equal (substring str -1 ) " \n " )
1790+ str
1791+ (concat str " \n " )))
1792+ (write-file tmp-file))
1793+ ; ; evaluate data in the temporary file and then remove it
1794+ (process-send-string
1795+ lua-process
1796+ (format (concat
1797+ " \n "
1798+ " local tmp = '%s';"
1799+ " local res, e = pcall(function () "
1800+ " local do_loadstring = loadstring or load;"
1801+ " "
1802+ " local f, e = io.open(tmp, 'r');" ; open temporary file
1803+ " if e then "
1804+ " os.remove(tmp);"
1805+ " error(e);"
1806+ " return;"
1807+ " end "
1808+ " "
1809+ " local cont, e = f:read('*all');" ; read all data
1810+ " if e then "
1811+ " os.remove(tmp);"
1812+ " error(e);"
1813+ " return;"
1814+ " end "
1815+ " "
1816+ " f:close(); f = nil;" ; close and remove file
1817+ " os.remove(tmp);"
1818+ " "
1819+ " local f, e = do_loadstring(cont);" ; handle chunk
1820+ " if e then "
1821+ " error(e);"
1822+ " return;"
1823+ " end "
1824+ " "
1825+ " return f();" ; execute chunk
1826+ " end);"
1827+ " if e then _, _ = os.remove(tmp); error(e); end" ; handle error, if any
1828+ " \n " ) tmp-file))))
17881829
17891830(defun lua-send-current-line ()
17901831 " Send current line to Lua subprocess, found in `lua-process' .
0 commit comments