![](https://secure.gravatar.com/avatar/be49110e195f5eac47c04570251121c1.jpg?s=120&d=mm&r=g)
In the TeX to Lua interface with \def\Macro#1{\directlua{luafunction("#1")}} the transfer from TeX to Lua is by string. However what to do at the Lua end when calling \Macro{}? As I understand it, then on the Lua side an empty argument and an empty string are indistinguishable. This is not always wanted, for example when one needs to place either a nil or an empty string into a Lua table. I am running in trouble when to t.key set to \Macro{} should become nil or when it should become "". Is there some common understanding about how to handle this situation? dr. Hans van der Meer
![](https://secure.gravatar.com/avatar/c5ae4f9aa0d3a9bd5376e92b322c3e50.jpg?s=120&d=mm&r=g)
On Mon, 9 Aug 2021, Hans van der Meer via ntg-context wrote:
In the TeX to Lua interface with
\def\Macro#1{\directlua{luafunction("#1")}}
the transfer from TeX to Lua is by string. However what to do at the Lua end when calling \Macro{}? As I understand it, then on the Lua side an empty argument and an empty string are indistinguishable.
That is not the case: $ echo 'print("" == nil)' | lua false
This is not always wanted, for example when one needs to place either a nil or an empty string into a Lua table. I am running in trouble when to t.key set to \Macro{} should become nil or when it should become "".
If you call luafunction(""), the string is empty and not nil. \startluacode userdata = userdata or {} function userdata.macro(str) if str == nil then context("Argument is nil") elseif str == "" then context("Argument is empty") else context("Argument is %s", str) end end \stopluacode \define[1]\Macro{\ctxlua{userdata.macro([==[#1]==])}} \starttext \startlines \Macro{} \Macro{ABC} \ctxlua{userdata.macro()} \stoplines \stoptext Aditya
![](https://secure.gravatar.com/avatar/d4db251f6da966f841fc5b1a9822eb56.jpg?s=120&d=mm&r=g)
On 9 Aug 2021, at 22:05, Aditya Mahajan via ntg-context
wrote: On Mon, 9 Aug 2021, Hans van der Meer via ntg-context wrote:
In the TeX to Lua interface with
\def\Macro#1{\directlua{luafunction("#1")}}
the transfer from TeX to Lua is by string. However what to do at the Lua end when calling \Macro{}? As I understand it, then on the Lua side an empty argument and an empty string are indistinguishable.
On the TeX side, these are always indistinguishable (as TeX doesn’t have ’strings’) so depending on the called macro, you could just assume str == "” actually means nil? But a clearer example of where you run into trouble would be helpful. Best wishes, Taco — Taco Hoekwater E: taco@bittext.nl genderfluid (all pronouns)
![](https://secure.gravatar.com/avatar/46562c7d27388490d62e8d7a5bc960dd.jpg?s=120&d=mm&r=g)
On 8/10/2021 9:23 AM, Taco Hoekwater via ntg-context wrote:
On 9 Aug 2021, at 22:05, Aditya Mahajan via ntg-context
wrote: On Mon, 9 Aug 2021, Hans van der Meer via ntg-context wrote:
In the TeX to Lua interface with
\def\Macro#1{\directlua{luafunction("#1")}}
the transfer from TeX to Lua is by string. However what to do at the Lua end when calling \Macro{}? As I understand it, then on the Lua side an empty argument and an empty string are indistinguishable.
On the TeX side, these are always indistinguishable (as TeX doesn’t have ’strings’) so depending on the called macro, you could just assume str == "” actually means nil?
indeed, just check for "" Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (4)
-
Aditya Mahajan
-
Hans Hagen
-
Hans van der Meer
-
Taco Hoekwater