ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Re: interfaces.implement for key-value list
       [not found] ` <26911a7c-45a2-4e2a-9b2a-69ecc42f7fab@gmail.com>
@ 2025-07-03 17:53   ` Henning Hraban Ramm
  0 siblings, 0 replies; only message in thread
From: Henning Hraban Ramm @ 2025-07-03 17:53 UTC (permalink / raw)
  To: ntg-context

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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-07-03 18:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <657d6892-01e9-466e-a3e0-bb175636d55b@fiee.net>
     [not found] ` <26911a7c-45a2-4e2a-9b2a-69ecc42f7fab@gmail.com>
2025-07-03 17:53   ` [NTG-context] Re: interfaces.implement for key-value list Henning Hraban Ramm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).