Lua conditionals fail inside \starttexdefinition
Hi, I discovered strange behaviour concerning Lua conditionals within texdefinitions. ConTeXt complains: 'then' expected near 'thenelseend'. I guess it has something to do with how the content of a texdefinitions is grabbed. Seems like a bug or is this by design? % This works fine \def\mycmd{% \startluacode if true then else end \stopluacode} % This one fails % \starttexdefinition mycmd % \startluacode % if true then % else % end % \stopluacode % \stoptexdefinition \startluacode userdata = userdata or { } function userdata.myfun() if true then else end end \stopluacode % This also works fine \starttexdefinition mycmd \luacode{userdata.myfun()} \stoptexdefinition \mycmd Marco
Am 04.09.2012 um 14:21 schrieb Marco Patzer
Hi,
I discovered strange behaviour concerning Lua conditionals within texdefinitions.
ConTeXt complains: 'then' expected near 'thenelseend'.
I guess it has something to do with how the content of a texdefinitions is grabbed. Seems like a bug or is this by design?
When you use the texdefinition environment to create a command the end of line character which results normally in a space is ignored sees “thenelseend” as a single string, in such a case you can add a space and put a comment sign at the end of the line.
% This one fails % \starttexdefinition mycmd % \startluacode % if true then % else % end % \stopluacode % \stoptexdefinition
\starttexdefintion mycmd \startluacode if true then % else % end \stopluacode \stoptexdefinition Wolfgang
On Tue, 4 Sep 2012, Wolfgang Schuster wrote:
Am 04.09.2012 um 14:21 schrieb Marco Patzer
: Hi,
I discovered strange behaviour concerning Lua conditionals within texdefinitions.
ConTeXt complains: 'then' expected near 'thenelseend'.
I guess it has something to do with how the content of a texdefinitions is grabbed. Seems like a bug or is this by design?
When you use the texdefinition environment to create a command the end of line character which results normally in a space is ignored sees “thenelseend” as a single string, in such a case you can add a space and put a comment sign at the end of the line.
% This one fails % \starttexdefinition mycmd % \startluacode % if true then % else % end % \stopluacode % \stoptexdefinition
\starttexdefintion mycmd \startluacode if true then % else % end \stopluacode \stoptexdefinition
Why does adding semicolon not work? Aditya
Am 04.09.2012 20:44, schrieb Marco Patzer:
On 2012-09-04 Wolfgang Schuster
wrote: Why does adding semicolon not work?
Do you have a example?
\starttext \startluacode if true then; context("true") else; context("false") end \stopluacode \stoptext
that is no Lua syntax Herbert
On 2012-09-04 Herbert Voss
\starttext \startluacode if true then; context("true") else; context("false") end \stopluacode \stoptext
that is no Lua syntax
if true then; print("true") else; print("false") end This snippet fed into a standalone Lua interpreter prints “true” on the terminal. I admit, I did not look up the syntax in the manual, but I have in mind that semicolons can be used to separate statements that are on one line. Marco
On Tue, Sep 4, 2012 at 9:05 PM, Marco Patzer
On 2012-09-04 Herbert Voss
wrote: Hi Herbert,
\starttext \startluacode if true then; context("true") else; context("false") end \stopluacode \stoptext
that is no Lua syntax
if true then; print("true") else; print("false") end
This snippet fed into a standalone Lua interpreter prints “true” on the terminal.
Not in my lua interpreter: saving the snippet into test.lua $>lua test.lua gives lua: test.lua:1: unexpected symbol near ';'
-- luigi
Am 04.09.2012 21:05, schrieb Marco Patzer:
if true then; print("true") else; print("false") end
This snippet fed into a standalone Lua interpreter prints “true” on the terminal.
I admit, I did not look up the syntax in the manual, but I have in mind that semicolons can be used to separate statements that are on one line.
voss@shania:~/ConTeXt> lua zzz.lua lua: zzz.lua:1: unexpected symbol near ';' voss@shania:~/ConTeXt> lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio Herbert
On 2012-09-04 Herbert Voss
voss@shania:~/ConTeXt> lua zzz.lua lua: zzz.lua:1: unexpected symbol near ';'
marco@homerow:/tmp$ lua t.lua true
voss@shania:~/ConTeXt> lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
marco@homerow:/tmp$ lua -v Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio Marco
Am 04.09.2012 21:35, schrieb Marco Patzer:
On 2012-09-04 Herbert Voss
wrote: voss@shania:~/ConTeXt> lua zzz.lua lua: zzz.lua:1: unexpected symbol near ';'
marco@homerow:/tmp$ lua t.lua true
voss@shania:~/ConTeXt> lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
marco@homerow:/tmp$ lua -v Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio
the syntax changes, see http://www.lua.org/manual/5.2/manual.html#9 Herbert
On 2012-09-04 Herbert Voss
voss@shania:~/ConTeXt> lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
marco@homerow:/tmp$ lua -v Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio
the syntax changes, see http://www.lua.org/manual/5.2/manual.html#9
You're totally right. LuaTeX uses does not use lua 5.2 and therefore the semicolon syntax is wrong. I also get an “unexpected symbol” with lua5.1 Thanks for the clarification Marco
On Tue, Sep 4, 2012 at 9:35 PM, Marco Patzer
On 2012-09-04 Herbert Voss
wrote: voss@shania:~/ConTeXt> lua zzz.lua lua: zzz.lua:1: unexpected symbol near ';'
marco@homerow:/tmp$ lua t.lua true
voss@shania:~/ConTeXt> lua -v Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
marco@homerow:/tmp$ lua -v Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio
Because in Lua 5.2 there is the empty statements http://www.lua.org/manual/5.2/manual.html#3 """ 3.3.1 – Blocks A block is a list of statements, which are executed sequentially: block ::= {stat} Lua has empty statements that allow you to separate statements with semicolons, start a block with a semicolon or write two semicolons in sequence: stat ::= ‘;’ """ So stat ::= if exp then block {elseif exp then block} [else block] end means that if exp then ; else ; end is valid. Luatex still uses lua 5.1.4 -- luigi
On Tue, 4 Sep 2012, Herbert Voss wrote:
Am 04.09.2012 20:44, schrieb Marco Patzer:
On 2012-09-04 Wolfgang Schuster
wrote: Why does adding semicolon not work?
Do you have a example?
\starttext \startluacode if true then; context("true") else; context("false") end \stopluacode \stoptext
that is no Lua syntax
I thought that semicolons were optional in lua are equal to end of lines. Aditya
On Tue, Sep 4, 2012 at 9:05 PM, Aditya Mahajan
On Tue, 4 Sep 2012, Herbert Voss wrote:
Am 04.09.2012 20:44, schrieb Marco Patzer:
On 2012-09-04 Wolfgang Schuster
wrote: Why does adding semicolon not work?
Do you have a example?
\starttext \startluacode if true then; context("true") else; context("false") end \stopluacode \stoptext
that is no Lua syntax
I thought that semicolons were optional in lua are equal to end of lines.
Aditya
______________________________**______________________________** _______________________ 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 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/http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ______________________________**______________________________** _______________________
http://www.lua.org/manual/5.1/manual.html#2.4.4 """ The unit of execution of Lua is called a chunk. A chunk is simply a sequence of statements, which are executed sequentially. Each statement can be optionally followed by a semicolon: : : 2.4.4 - Control Structures The control structures if, while, and repeat have the usual meaning and familiar syntax: stat ::= while exp do block end stat ::= repeat block until exp stat ::= if exp then block {elseif exp then block} [else block] end """ (as conseguence if exp then; block else; block end is not valid ) -- luigi
Am 04.09.2012 21:22, schrieb luigi scarso:
http://www.lua.org/manual/5.1/manual.html#2.4.4 """ The unit of execution of Lua is called a chunk. A chunk is simply a sequence of statements, which are executed sequentially. Each statement can be optionally followed by a semicolon: : : 2.4.4 - Control Structures
The control structures if, while, and repeat have the usual meaning and familiar syntax:
stat ::= while exp do block end stat ::= repeat block until exp stat ::= if exp then block {elseif exp then block} [else block] end """ (as conseguence if exp then; block else; block end is not valid )
yes, see also: http://www.lua.org/manual/5.1/manual.html#8 Herbert
On 4-9-2012 20:44, Marco Patzer wrote:
On 2012-09-04 Wolfgang Schuster
wrote: Why does adding semicolon not work?
Do you have a example?
\starttext \startluacode if true then; context("true") else; context("false") end \stopluacode \stoptext
\ctxlua{context(tostring(some condition)} given that the condition returns true/false ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (6)
-
Aditya Mahajan
-
Hans Hagen
-
Herbert Voss
-
luigi scarso
-
Marco Patzer
-
Wolfgang Schuster