Calling Lua function from an external package
Hello, I have the following problem. Let's have T~.lua file which defines a function: --- function F2() context("draw (0,0)--(5cm,0)") end print("T~OK!") --- Let's have MP-02.ctx ConTeXt source file: --- \starttext AAA \startluacode function F() context("draw (0,0)--(2cm,0)") end require("T~") context.startMPcode() F() -- F2() context.stopMPcode() \stopluacode \stoptext --- Such code works OK - produces .pdf with a text "AAA" and a horizontal line. You can find the text "T~OK!" in the compilation log - that means T~.lua was successfully loaded. When I remove comment marks in front of F2() (which is defined in T~.lua), so I get: --- \starttext AAA \startluacode function F() context("draw (0,0)--(2cm,0)") end require("T~") context.startMPcode() F() F2() context.stopMPcode() \stopluacode \stoptext --- the compilation to .pdf fails with the following error message: --- MTXrun | run 1: luatex --fmt="c:/ConTeXt/tex/texmf-cache/luatex-cache/context/f53042fa2e1c106bc7e3383ec8c3a00c/formats/cont-en" --lua="c:/ConTeXt/tex/texmf-cache/luatex-cache/context/f53042fa2e1c106bc7e3383ec8c3a00c/formats/cont-en.lui" --backend=pdf "./MP -02.ctx"This is LuaTeX, Version beta-0.63.0-2010090921 (rev 3873) \write18 enabled. (MP-02.ctx jobcontrol > resuming randomizer with 0.40830713827937 ConTeXt ver: 2010.09.22 12:33 MKIV fmt: 2010.9.22 int: english/english system : cont-new loaded (c:/ConTeXt/tex/texmf-context/tex/context/base/cont-new.tex systems : beware: some patches loaded from cont-new.tex (c:/ConTeXt/tex/texmf-context/tex/context/base/cont-new.mkiv)) system : cont-fil loaded (c:/ConTeXt/tex/texmf-context/tex/context/base/cont-fil.tex loading : ConTeXt File Synonyms ) system : cont-sys.rme loaded (c:/ConTeXt/tex/texmf-context/tex/context/user/cont-sys.rme (c:/ConTeXt/tex/texmf-context/tex/context/base/type-def.mkiv) (c:/ConTeXt/tex/texmf-context/tex/context/base/type-lua.mkiv) (c:/ConTeXt/tex/texmf-context/tex/context/base/type-siz.mkiv) (c:/ConTeX t/tex/texmf-context/tex/context/base/type-otf.mkiv)) system : cont-err loaded (c:/ConTeXt/tex/texmf-context/tex/context/base/cont-err.tex systems : no file 'cont-sys.tex', using 'cont-sys.rme' instead ) system : MP-02.top loaded (MP-02.top) fonts : preloading latin modern fonts {c:/ConTeXt/tex/texmf/fonts/map/dvips/lm/lm-math.map}{c:/ConTeXt/tex/texmf/fonts/map/dvips/lm/lm-rm.map}{c:/ConTeXt/tex/texmf-context/fonts/map/pdftex/context/mkiv-base.map} bodyfont : 12pt rm is loaded language : language en is active publications : loading formatting style from bxml-apa (c:/ConTeXt/tex/texmf-context/tex/context/base/bxml-apa.mkiv) systems : begin file MP-02.ctx at line 1 T~OK! mplib : initializing instance 'metafun' using format 'metafun' mplib : loading 'metafun.mp' (experimental metapost version two) ! mp terminal: ! Extra tokens will be flushed. <to be read again> addto draw->addto .currentpicture.if.picture(EXPR0):also(EXPR0)else:doublepath(EXPR... <to be read again> ; <*> draw (0,0)--(2cm,0)draw (0,0)--(5cm,0); . system > error on line 4 in file MP-02.ctx: mp terminal: ! Extra tokens will be flushed. <to be read again> addto draw->addto .currentpicture.if.picture(EXPR0):also(EXPR0)else:doublepath(EXPR... <to be read again> ; <*> draw (0,0)--(2cm,0)draw (0,0)--(5cm,0); ... 1 \starttext 2 AAA 3 4 >> \startluacode 5 function F() 6 context("draw (0,0)--(2cm,0)") 7 end 8 9 require("T~") 10 11 context.startMPcode() 12 F() 13 F2() 14 context.stopMPcode() <inserted text> ...re.mp ; fi ; ;;;;]===], false)} \processMPgraphic ...e ;\!!es , \MPaskedfigure )}} \egroup \placeMPgraphic \d... l.4 \stopMPcode } context.stopMPcode() \dodostartluacode ...d \directlua \zerocount {#1}} l.15 \stopluacode --- It's strange to me, especially when body of F() and F2() is almost identical. Why? And how do I make it work (I mean still having a function defined in a separate file)? Thank you in advance. Cheers, Lukas
On 29-9-2010 3:02, Procházka Lukáš wrote:
Hello,
I have the following problem.
Let's have T~.lua file which defines a function:
hm, what is this ~ doing there ... avoid such characters! ~ is HOME on some systems Hans ----------------------------------------------------------------- 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 -----------------------------------------------------------------
On 09/29/10 15:10, Hans Hagen wrote:
On 29-9-2010 3:02, Procházka Lukáš wrote:
Hello,
I have the following problem.
Let's have T~.lua file which defines a function:
hm, what is this ~ doing there ... avoid such characters! ~ is HOME on some systems
That is true of course, but the problem is much simpler than that: Make sure you end your metapost expressions with a semicolon. Best wishes, Taco
... Thanks, it works now! It had to be fixed both in F() and in F2().
(I forgot ";" in MP statement as Lua doesn't require ";".)
(Still it's a bit strange to me that calling F() worked even when the MP statement in F() was not finished by ";" and F2() was not called.)
Lukas
On Wed, 29 Sep 2010 15:27:14 +0200, Taco Hoekwater
On 09/29/10 15:10, Hans Hagen wrote:
On 29-9-2010 3:02, Procházka Lukáš wrote:
Hello,
I have the following problem.
Let's have T~.lua file which defines a function:
hm, what is this ~ doing there ... avoid such characters! ~ is HOME on some systems
That is true of course, but the problem is much simpler than that:
Make sure you end your metapost expressions with a semicolon.
Best wishes, Taco
___________________________________________________________________________________ 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 ___________________________________________________________________________________
-- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
I think that ";" is not needed to end an MP statement but to separate two of them. So it works without as long as you only have one MP statement. Stefan On 29.09.2010 15:35, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
... Thanks, it works now! It had to be fixed both in F() and in F2().
(I forgot ";" in MP statement as Lua doesn't require ";".)
(Still it's a bit strange to me that calling F() worked even when the MP statement in F() was not finished by ";" and F2() was not called.)
Lukas
participants (5)
-
Hans Hagen
-
Procházka Lukáš
-
Procházka Lukáš Ing. - Pontex s. r. o.
-
Stefan Müller
-
Taco Hoekwater