Function: org-babel-lua-evaluate-session
org-babel-lua-evaluate-session is a byte-compiled function defined in
ob-lua.el.gz.
Signature
(org-babel-lua-evaluate-session SESSION BODY &optional RESULT-TYPE RESULT-PARAMS)
Documentation
Pass BODY to the Lua process in SESSION.
If RESULT-TYPE equals output then return standard output as a
string. If RESULT-TYPE equals value then return the value of the
last statement in BODY, as Emacs Lisp.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-lua.el.gz
(defun org-babel-lua-evaluate-session
(session body &optional result-type result-params)
"Pass BODY to the Lua process in SESSION.
If RESULT-TYPE equals `output' then return standard output as a
string. If RESULT-TYPE equals `value' then return the value of the
last statement in BODY, as Emacs Lisp."
(let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0.005)))
(dump-last-value
(lambda
(tmp-file pp)
(mapc
(lambda (statement) (insert statement) (funcall send-wait))
(if pp
(list
"-- table to string
function t2s(t, indent)
if indent == nil then
indent = \"\"
end
if type(t) == \"table\" then
ts = \"\"
for k,v in pairs(t) do
if type(v) == \"table\" then
ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \\n\" ..
t2s(v, indent .. \" \")
else
ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \" ..
t2s(v, indent .. \" \") .. \"\\n\"
end
end
return ts
else
return tostring(t)
end
end
"
(concat "fd:write(_))
fd:close()"
(org-babel-process-file-name tmp-file 'noquote)))
(list (format "fd=io.open(\"%s\", \"w\")
fd:write( _ )
fd:close()"
(org-babel-process-file-name tmp-file
'noquote)))))))
(input-body (lambda (body)
(mapc (lambda (line) (insert line) (funcall send-wait))
(split-string body "[\r\n]"))
(funcall send-wait)))
(results
(pcase result-type
(`output
(mapconcat
#'org-trim
(butlast
(org-babel-comint-with-output
(session org-babel-lua-eoe-indicator t body)
(funcall input-body body)
(funcall send-wait) (funcall send-wait)
(insert org-babel-lua-eoe-indicator)
(funcall send-wait))
2) "\n"))
(`value
(let ((tmp-file (org-babel-temp-file "lua-")))
(org-babel-comint-with-output
(session org-babel-lua-eoe-indicator nil body)
(let ((comint-process-echoes nil))
(funcall input-body body)
(funcall dump-last-value tmp-file
(member "pp" result-params))
(funcall send-wait) (funcall send-wait)
(insert org-babel-lua-eoe-indicator)
(funcall send-wait)))
(org-babel-eval-read-file tmp-file))))))
(unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results)
(org-babel-result-cond result-params
results
(org-babel-lua-table-or-string results)))))