From: Otared Kavian <otared@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: running lua in metafun and in ConTeXt
Date: Sat, 11 Apr 2020 14:48:37 +0200 [thread overview]
Message-ID: <2107AEC3-C798-4146-94BC-039D78753420@gmail.com> (raw)
In-Reply-To: <FE8D614C-0F27-4456-802E-3160C9C80A28@me.com>
Hi Dalyoung,
I tested your code: it works fine with both definitions of the variable tt in your code. I am using the current LMTX version 2020.04.08 14:38.
Best regards: Otared
> On 11 Apr 2020, at 14:32, Jeong Dal <haksan@me.com> wrote:
>
> Dear all,
>
> I draw Pascal’s triangle with the label of each point created by using lua functions.
> As you see in the code below, I defined fact(n) and combi(n,r) using lua.
> For the calculation tt, I used two different methods.
> Both are working well when I run the given code.
>
> But I got an error, when I added this code to a ConTeXt file composed product and components,
> and using the second method, i.e. combi(n,r). The first method is still working well.
> The error message is as following:
>
> metapost log > loading metafun, including plain.mp version 1.004 for metafun iv and xl
> metapost log >
> luatex warning > mplib: run script: [string "return mp.print(combi(0,0 ))"]:1: attempt to call a nil value (global 'combi')
>
> metapost log > >> tt
> metapost log > >> vacuous
> metapost log > ! Equation cannot be performed (numeric=vacuous).
> metapost log > <to be read again>
> metapost log > ;
> metapost log > <for(0)> ...&decimal(0)&","&decimal(EXPR0)&" ))");
> metapost log > now:=start+(EXPR0)*right*d...
> metapost log > <for(0)> ....now--(now+A);draw.now--(now+B);endfor
> metapost log > ; ENDFOR
> metapost log > <*> ...now+A); draw now -- (now+B); endfor; endfor
> metapost log > ;;
>
> I don’t know why the same code treated differently.
> I think that I have to do something more in luacode which I don’t know.
> Comments are wellcome!
>
> Best regards,
>
> Dalyoung
>
> %%%%%%%
>
> \startluacode
> function fact (n)
> if n <= 0 then
> return 1
> else
> return n * fact(n-1)
> end
> end
> function combi(n,r)
> return fact(n)/(fact(r)*fact(n-r))
> end
> \stopluacode
> \startbuffer[fig121]
> numeric n,r,s,u,dx,dy,tt; u := 1.8cm;
> path p, q;
> pair A,B,start,now;
> A := dir(210)*u;
> B := dir(-30)*u;
> dy := sind(30)*u;
> dx := 2*cosd(30)*u;
> for n=0 upto 4:
> start := n*dir(210)*u;
> for r=0 upto n:
> s := n-r;
> % tt := lua("mp.print(fact(" & decimal n & ")/(fact(" & decimal r & ")*fact(" & decimal s &" )))");
> tt := lua("mp.print(combi(" & decimal n & "," & decimal r & " ))");
>
> now := start+r*right*dx;
> dotlabel.top(textext("$\displaystyle {" & decimal n & "\choose" & decimal r & "} = "& decimal tt & "$"),now);
> draw now -- (now+A);
> draw now -- (now+B);
> endfor;
> endfor;
> \stopbuffer
> \starttext
> \switchtobodyfont[11pt]
> \processMPbuffer[fig121]
> \switchtobodyfont[12pt]
> \stoptext
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2020-04-11 12:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.2082.1586557063.1332.ntg-context@ntg.nl>
2020-04-11 12:32 ` Jeong Dal
2020-04-11 12:48 ` Otared Kavian [this message]
2020-04-11 14:15 ` Jeong Dal
2020-04-11 17:08 ` Hans Hagen
2020-04-11 23:19 ` Jeong Dal
2020-04-12 9:44 ` Hans Hagen
2020-04-12 13:02 ` Jeong Dal
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=2107AEC3-C798-4146-94BC-039D78753420@gmail.com \
--to=otared@gmail.com \
--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).