ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Procházka Lukáš" <lpr@pontex.cz>
To: ConTeXt <ntg-context@ntg.nl>
Subject: Calling Lua function from an external package
Date: Wed, 29 Sep 2010 15:02:02 +0200	[thread overview]
Message-ID: <op.vjso5oga8lgizc@lk-2008-nbk> (raw)

[-- Attachment #1: Type: text/plain, Size: 4426 bytes --]

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

[-- Attachment #2: T~.lua --]
[-- Type: application/octet-stream, Size: 72 bytes --]

function F2()
  context("draw (0,0)--(5cm,0)")
end

print("T~OK!")

[-- Attachment #3: MP-02.ctx --]
[-- Type: application/octet-stream, Size: 225 bytes --]

\starttext
  AAA

  \startluacode
    function F()
      context("draw (0,0)--(2cm,0)")
    end

    require("T~")

    context.startMPcode()
    F()
    F2()
    context.stopMPcode()
  \stopluacode
\stoptext

[-- Attachment #4: 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
___________________________________________________________________________________

             reply	other threads:[~2010-09-29 13:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-29 13:02 Procházka Lukáš [this message]
2010-09-29 13:10 ` Hans Hagen
2010-09-29 13:27   ` Taco Hoekwater
2010-09-29 13:35     ` Procházka Lukáš Ing. - Pontex s. r. o.
2010-09-29 13:48       ` Stefan Müller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=op.vjso5oga8lgizc@lk-2008-nbk \
    --to=lpr@pontex.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).