From: Ihor Radchenko <yantar92@posteo.net>
To: "Rudolf Adamkovič" <rudolf@adamkovic.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-lua: Support all types and multiple values in results
Date: Fri, 26 Apr 2024 13:40:49 +0000 [thread overview]
Message-ID: <87pluctf6m.fsf@localhost> (raw)
In-Reply-To: <m2pluereit.fsf@adamkovic.org>
[-- Attachment #1: Type: text/plain, Size: 657 bytes --]
Rudolf Adamkovič <rudolf@adamkovic.org> writes:
> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> May you create a test for this with expected failure?
>
> Sure! Here is one:
>
> (should
> (equal "{B}"
> (org-test-with-temp-text
> "src_lua{return string.match('A {B} C', '%b{}')}"
> (org-babel-execute-src-block))))
>
> The return value from 'string.match' is the substring "{B}", which Babel
> misjudges to be a list and signals the error:
>
> (user-error "Inline error: list result cannot be used")
Maybe something like the attached.
(I am a casual lua user, so better double check)
[-- Attachment #2: 0001-ob-lua-Fix-edge-case-when-output-is-string.patch --]
[-- Type: text/x-patch, Size: 1840 bytes --]
From bfe0fa3d78cc13b84dec33c230755c9f4693a685 Mon Sep 17 00:00:00 2001
Message-ID: <bfe0fa3d78cc13b84dec33c230755c9f4693a685.1714138810.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 26 Apr 2024 16:39:07 +0300
Subject: [PATCH] ob-lua: Fix edge case when output is {string}
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lisp/ob-lua.el (org-babel-lua-wrapper-method): Make sure that string
result is enclosed in "...", so that Org mode does not try to guess
the output type heuristically.
* testing/lisp/test-ob-lua.el (test-ob-lua/types): New test.
Co-authored-by: Rudolf Adamkovič <rudolf@adamkovic.org>
---
lisp/ob-lua.el | 2 ++
testing/lisp/test-ob-lua.el | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 041abfabc..afe88065d 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -282,6 +282,8 @@ (defvar org-babel-lua-wrapper-method
end
end
return result
+ elseif type(it) == 'string' then
+ return '\"' .. it .. '\"'
else
return tostring(it)
end
diff --git a/testing/lisp/test-ob-lua.el b/testing/lisp/test-ob-lua.el
index 0a60c68ca..398ab761d 100644
--- a/testing/lisp/test-ob-lua.el
+++ b/testing/lisp/test-ob-lua.el
@@ -158,6 +158,12 @@ (ert-deftest test-ob-lua/types ()
(equal "hello world"
(org-test-with-temp-text "src_lua{return 'hello world'}"
(org-babel-execute-src-block))))
+ ;; Edge case: string matching list syntax.
+ (should
+ (equal "{B}"
+ (org-test-with-temp-text
+ "src_lua{return string.match('A {B} C', '%b{}')}"
+ (org-babel-execute-src-block))))
(should
(equal 0
(string-match "table: 0x[0-9A-F]+"
--
2.44.0
[-- Attachment #3: Type: text/plain, Size: 224 bytes --]
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
next prev parent reply other threads:[~2024-04-26 13:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 16:44 [PATCH] ob-lua: Support all types and multiple values in results Rudolf Adamkovič
2024-04-23 17:05 ` Rudolf Adamkovič
2024-04-24 14:20 ` Ihor Radchenko
2024-04-24 13:05 ` Ihor Radchenko
2024-04-24 15:01 ` Rudolf Adamkovič
2024-04-26 13:40 ` Ihor Radchenko [this message]
2024-04-27 10:57 ` Max Nikulin
2024-04-27 16:33 ` Rudolf Adamkovič
2024-04-28 12:36 ` Ihor Radchenko
2024-04-29 15:57 ` Rudolf Adamkovič
2024-04-29 20:26 ` Rudolf Adamkovič
2024-04-30 10:24 ` Ihor Radchenko
2024-05-02 15:57 ` Rudolf Adamkovič
2024-05-02 15:58 ` Rudolf Adamkovič
2024-05-02 16:02 ` Rudolf Adamkovič
2024-05-01 11:05 ` Max Nikulin
2024-05-02 16:00 ` Rudolf Adamkovič
2024-05-02 16:41 ` Ihor Radchenko
2024-06-09 20:54 ` Rudolf Adamkovič
2024-06-14 17:41 ` Rudolf Adamkovič
2024-06-14 17:48 ` Rudolf Adamkovič
2024-06-14 17:58 ` Ihor Radchenko
2024-06-14 20:13 ` Rudolf Adamkovič
2024-06-14 20:18 ` Ihor Radchenko
2024-06-14 20:37 ` Rudolf Adamkovič
2024-06-14 21:20 ` Rudolf Adamkovič
2024-06-15 13:08 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pluctf6m.fsf@localhost \
--to=yantar92@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=rudolf@adamkovic.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.