ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] unprotecting when defining in Lua
@ 2024-04-29 15:22 Pablo Rodriguez via ntg-context
  2024-04-29 16:04 ` [NTG-context] " Wolfgang Schuster
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-04-29 15:22 UTC (permalink / raw)
  To: ConTeXt users; +Cc: Pablo Rodriguez

Dear list,

I have the following sample:

  \starttext
  \startluacode
    function document.test(str)
      context(str)
    end

    interfaces.definecommand {
      name = "testing",
      protected = false,
      macro = document.test,
    }
  \stopluacode

  \meaningfull\testing

  \def\test#1{#1}

  \meaningfull\test
  \stoptext

Which is the right way to use "interfaces.definecommand" to get a simple
command as in standard TeX?

I mean, no a non \permanent or non \protected command.

Many thanks for your help,

Pablo
___________________________________________________________________________________
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] 5+ messages in thread

* [NTG-context] Re: unprotecting when defining in Lua
  2024-04-29 15:22 [NTG-context] unprotecting when defining in Lua Pablo Rodriguez via ntg-context
@ 2024-04-29 16:04 ` Wolfgang Schuster
  2024-04-29 16:21   ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2024-04-29 16:04 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez via ntg-context
  Cc: Pablo Rodriguez

Pablo Rodriguez via ntg-context schrieb am 29.04.2024 um 17:22:
> Dear list,
>
> I have the following sample:
>
>    \starttext
>    \startluacode
>      function document.test(str)
>        context(str)
>      end
>
>      interfaces.definecommand {
>        name = "testing",
>        protected = false,
>        macro = document.test,
>      }
>    \stopluacode
>
>    \meaningfull\testing
>
>    \def\test#1{#1}
>
>    \meaningfull\test
>    \stoptext
>
> Which is the right way to use "interfaces.definecommand" to get a simple
> command as in standard TeX?
>
> I mean, no a non \permanent or non \protected command.

You can't create unprotected command with interfaces.definecommand but 
this not a problem
because you can just use interfaces.implement to create your command 
which is then unprotected
by default. Using implement instead of definecommand doesn't matter 
because definecommand
is just a wrapper for the implement function with the option to create a 
environment.

Wolfgang

___________________________________________________________________________________
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] 5+ messages in thread

* [NTG-context] Re: unprotecting when defining in Lua
  2024-04-29 16:04 ` [NTG-context] " Wolfgang Schuster
@ 2024-04-29 16:21   ` Pablo Rodriguez via ntg-context
  2024-04-29 17:32     ` Wolfgang Schuster
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-04-29 16:21 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 4/29/24 18:04, Wolfgang Schuster wrote:
> Pablo Rodriguez via ntg-context schrieb am 29.04.2024 um 17:22:
>> [...]
>> Which is the right way to use "interfaces.definecommand" to get a simple
>> command as in standard TeX?
>>
>> I mean, no a non \permanent or non \protected command.
>
> You can't create unprotected command with interfaces.definecommand
> but this not a problem because you can just use interfaces.implement
> to create your command which is then unprotected by default. Using
> implement instead of definecommand doesn't matter because
> definecommand is just a wrapper for the implement function with the
> option to create a environment.

Many thanks for your fast reply, Wolfgang.

I’m reading it now in cld-mkiv.pdf.

Is \protected the same as \unexpanded?

Many thanks for your help again,

Pablo
___________________________________________________________________________________
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] 5+ messages in thread

* [NTG-context] Re: unprotecting when defining in Lua
  2024-04-29 16:21   ` Pablo Rodriguez via ntg-context
@ 2024-04-29 17:32     ` Wolfgang Schuster
  2024-04-29 18:21       ` Pablo Rodriguez via ntg-context
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfgang Schuster @ 2024-04-29 17:32 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez via ntg-context
  Cc: Pablo Rodriguez

Pablo Rodriguez via ntg-context schrieb am 29.04.2024 um 18:21:
> On 4/29/24 18:04, Wolfgang Schuster wrote:
>> Pablo Rodriguez via ntg-context schrieb am 29.04.2024 um 17:22:
>>> [...]
>>> Which is the right way to use "interfaces.definecommand" to get a simple
>>> command as in standard TeX?
>>>
>>> I mean, no a non \permanent or non \protected command.
>> You can't create unprotected command with interfaces.definecommand
>> but this not a problem because you can just use interfaces.implement
>> to create your command which is then unprotected by default. Using
>> implement instead of definecommand doesn't matter because
>> definecommand is just a wrapper for the implement function with the
>> option to create a environment.
> Many thanks for your fast reply, Wolfgang.
>
> I’m reading it now in cld-mkiv.pdf.
>
> Is \protected the same as \unexpanded?

Yes they are the same (\protected is the primitive and \unexpanded is a 
copy) but this wasn't always the case.

Original TeX didn't provide a mechanism to create protected commands and 
creators of macro packages
had to create their own mechanism for this, the ConTeXt solution was 
\unexpanded. With the etex extensions
the \protected primitive was added and \unexpanded uses the new 
primitive when you used a engine
which supported it.

Wolfgang

___________________________________________________________________________________
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] 5+ messages in thread

* [NTG-context] Re: unprotecting when defining in Lua
  2024-04-29 17:32     ` Wolfgang Schuster
@ 2024-04-29 18:21       ` Pablo Rodriguez via ntg-context
  0 siblings, 0 replies; 5+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2024-04-29 18:21 UTC (permalink / raw)
  To: ntg-context; +Cc: Pablo Rodriguez

On 4/29/24 19:32, Wolfgang Schuster wrote:
> Pablo Rodriguez via ntg-context schrieb am 29.04.2024 um 18:21:
>> Is \protected the same as \unexpanded?
>
> Yes they are the same (\protected is the primitive and \unexpanded is a
> copy) but this wasn't always the case.
>
> Original TeX didn't provide a mechanism to create protected commands
> and creators of macro packages had to create their own mechanism for
> this, the ConTeXt solution was \unexpanded. With the etex extensions
> the \protected primitive was added and \unexpanded uses the new
> primitive when you used a engine which supported it.

Many thanks for your fast reply and your explanation, Wolfgang.

Pablo

___________________________________________________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2024-04-29 18:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 15:22 [NTG-context] unprotecting when defining in Lua Pablo Rodriguez via ntg-context
2024-04-29 16:04 ` [NTG-context] " Wolfgang Schuster
2024-04-29 16:21   ` Pablo Rodriguez via ntg-context
2024-04-29 17:32     ` Wolfgang Schuster
2024-04-29 18:21       ` Pablo Rodriguez via ntg-context

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).