
Hi, I’m trying to get a simple function with a variable number of parameters working: """ \startluacode interfaces.implement { name = "Autoren", public = true, arguments = { "hash" }, actions = function(t) logs.report('Autoren', 'interface got table of length ' .. #t) end } \stopluacode \starttext Info: \Autoren[text=Hans,melody=Hraban] \stoptext """ The table t has always length 0. Where’s my error? And is there documentation on interfaces.implement anywhere? Hraban

Am 03.07.2025 um 16:04 schrieb Henning Hraban Ramm:
Hi, I’m trying to get a simple function with a variable number of parameters working:
""" \startluacode interfaces.implement { name = "Autoren", public = true, arguments = { "hash" }, actions = function(t) logs.report('Autoren', 'interface got table of length ' .. #t) end } \stopluacode
\starttext
Info: \Autoren[text=Hans,melody=Hraban]
\stoptext """
The table t has always length 0. Where’s my error?
Do you see the difference? \starttext \startluacode a = { "one", "two", "three" } b = { x = "one", y = "two", z = "three" } context("Table a: " .. #a) context.par() context("Table b: " .. #b) \stopluacode \stoptext Wolfgang

Am 03.07.25 um 16:34 schrieb Wolfgang Schuster:
Am 03.07.2025 um 16:04 schrieb Henning Hraban Ramm:
Hi, I’m trying to get a simple function with a variable number of parameters working:
""" \startluacode interfaces.implement { name = "Autoren", public = true, arguments = { "hash" }, actions = function(t) logs.report('Autoren', 'interface got table of length ' .. #t) end } \stopluacode
\starttext
Info: \Autoren[text=Hans,melody=Hraban]
\stoptext """
The table t has always length 0. Where’s my error?
Do you see the difference?
\starttext
\startluacode
a = { "one", "two", "three" }
b = { x = "one", y = "two", z = "three" }
context("Table a: " .. #a) context.par() context("Table b: " .. #b)
\stopluacode
\stoptext
Wolfgang
Oops, yes: #count is not for string indices. Thus I shouldn’t break if #t==0. BTW is there a function for printing a table (like pprint.pprint in Python)? The other problem was I had a return instead of context(). Thank you for the hint! Hraban

Am 03.07.2025 um 19:53 schrieb Henning Hraban Ramm:
Am 03.07.25 um 16:34 schrieb Wolfgang Schuster:
Am 03.07.2025 um 16:04 schrieb Henning Hraban Ramm:
Hi, I’m trying to get a simple function with a variable number of parameters working:
""" \startluacode interfaces.implement { name = "Autoren", public = true, arguments = { "hash" }, actions = function(t) logs.report('Autoren', 'interface got table of length ' .. #t) end } \stopluacode
\starttext
Info: \Autoren[text=Hans,melody=Hraban]
\stoptext """
The table t has always length 0. Where’s my error?
Do you see the difference?
\starttext
\startluacode
a = { "one", "two", "three" }
b = { x = "one", y = "two", z = "three" }
context("Table a: " .. #a) context.par() context("Table b: " .. #b)
\stopluacode
\stoptext
Wolfgang
Oops, yes: #count is not for string indices.
Thus I shouldn’t break if #t==0.
BTW is there a function for printing a table (like pprint.pprint in Python)?
table.serialize(...) Wolfgang

Am 03.07.25 um 20:12 schrieb Wolfgang Schuster:
Am 03.07.2025 um 19:53 schrieb Henning Hraban Ramm:
BTW is there a function for printing a table (like pprint.pprint in Python)?
table.serialize(...)
Am 03.07.25 um 20:12 schrieb Thomas A. Schmitz:
print (inspect (table))
It's a module in Lua that is integrated into the ConTeXt Lua interpreter.
Thank you both! (The difference, as fair checked: table.serialize shows the name of the table variable, where inspect says "table".) Hraban
participants (3)
-
Henning Hraban Ramm
-
Thomas A. Schmitz
-
Wolfgang Schuster