ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Escaping in LuaTeX
@ 2011-01-02  1:04 Fulvio Satta
  2011-01-02  8:30 ` Wolfgang Schuster
  2011-01-02 12:27 ` Fulvio Satta
  0 siblings, 2 replies; 3+ messages in thread
From: Fulvio Satta @ 2011-01-02  1:04 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 863 bytes --]

I have a problem with Lua and the "#" operator.
If I execute the following code I receive an error.

\def\luacode%
{\startluacode
    local t = {1, 2, 3}
    tex.print(#t)
\stopluacode}

\starttext
    \luacode
\stoptext

ConTeXt give me the message:

! Illegal parameter number in definition of \luacode.
<to be read again> 
                   t
l.4     tex.print(#t
                    )

And if I execute the "H" command I get:

You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I''m going to assume that you meant ##.

I've tryed with ##t, whit \#t, with \string#t, with \ctxlua instread of 
\startluacode and \stopluacode, and I've obtained some other errors, but 
ConTeXt always give me an error.

Maybe should I escape in another manner the "#" operator?

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Escaping in LuaTeX
  2011-01-02  1:04 Escaping in LuaTeX Fulvio Satta
@ 2011-01-02  8:30 ` Wolfgang Schuster
  2011-01-02 12:27 ` Fulvio Satta
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Schuster @ 2011-01-02  8:30 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 02.01.2011 um 02:04 schrieb Fulvio Satta:

> I have a problem with Lua and the "#" operator.
> If I execute the following code I receive an error.
> 
> \def\luacode%
> {\startluacode
>    local t = {1, 2, 3}
>    tex.print(#t)
> \stopluacode}
> 
> \starttext
>    \luacode
> \stoptext
> 
> ConTeXt give me the message:
> 
> ! Illegal parameter number in definition of \luacode.
> <to be read again> 
>                   t
> l.4     tex.print(#t
>                    )
> 
> And if I execute the "H" command I get:
> 
> You meant to type ## instead of #, right?
> Or maybe a } was forgotten somewhere earlier, and things
> are all screwed up? I''m going to assume that you meant ##.
> 
> I've tryed with ##t, whit \#t, with \string#t, with \ctxlua instread of 
> \startluacode and \stopluacode, and I've obtained some other errors, but 
> ConTeXt always give me an error.
> 
> Maybe should I escape in another manner the "#" operator?

You can replace the # with \letterhash but you method is wrong, the first thing is that
\luacode is already defined in the core and it can be used as replacement for \ctxlua
and second it’s better to separate a lua function and the call to the function.

Instead of writing the function in a luacode environment you can also put it
in a external file which is then loaded in your document/module. You should
also use a namespace for your functions.

\startluacode

userdata        = userdata        or { }
userdata.fulvio = userdata.fulvio or { }

function userdata.fulvio.size()
    local t = {1, 2, 3}
    tex.print(#t)
end

\stopluacode

\def\SizeOne{\ctxlua {userdata.fulvio.size()}}
\def\SizeTwo{\luacode{userdata.fulvio.size()}}

\starttext

\startluacode
   local t = {1, 2, 3}
   tex.print(#t)
\stopluacode

\starttabulate
\NC ctxlua  \EQ \SizeOne \NC\NR
\NC luacode \EQ \SizeTwo \NC\NR
\stoptabulate

\stoptext

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Escaping in LuaTeX
  2011-01-02  1:04 Escaping in LuaTeX Fulvio Satta
  2011-01-02  8:30 ` Wolfgang Schuster
@ 2011-01-02 12:27 ` Fulvio Satta
  1 sibling, 0 replies; 3+ messages in thread
From: Fulvio Satta @ 2011-01-02 12:27 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: Text/Plain, Size: 1089 bytes --]

Il domenica 02 gennaio 2011 02:04:46 Fulvio Satta ha scritto:
> I have a problem with Lua and the "#" operator.
> If I execute the following code I receive an error.
> 
> \def\luacode%
> {\startluacode
>     local t = {1, 2, 3}
>     tex.print(#t)
> \stopluacode}
> 
> \starttext
>     \luacode
> \stoptext
> 
> ConTeXt give me the message:
> 
> ! Illegal parameter number in definition of \luacode.
> <to be read again>
>                    t
> l.4     tex.print(#t
>                     )
> 
> And if I execute the "H" command I get:
> 
> You meant to type ## instead of #, right?
> Or maybe a } was forgotten somewhere earlier, and things
> are all screwed up? I''m going to assume that you meant ##.
> 
> I've tryed with ##t, whit \#t, with \string#t, with \ctxlua instread of
> \startluacode and \stopluacode, and I've obtained some other errors, but
> ConTeXt always give me an error.
> 
> Maybe should I escape in another manner the "#" operator?

In the previous mail I foget to say my ConTeXt version. I use ConTeXt minimals 
2010.12.31 08:59.

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-02 12:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-02  1:04 Escaping in LuaTeX Fulvio Satta
2011-01-02  8:30 ` Wolfgang Schuster
2011-01-02 12:27 ` Fulvio Satta

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