From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/106831 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Jeong Dal Newsgroups: gmane.comp.tex.context Subject: running lua in metafun and in ConTeXt Date: Sat, 11 Apr 2020 23:15:42 +0900 Message-ID: <1E5889A8-5BF2-4170-B495-129CF86E0949@me.com> References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Content-Type: multipart/mixed; boundary="===============8244507805955572134==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="82503"; mail-complaints-to="usenet@ciao.gmane.io" To: "list ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl ntg-context@ntg.nl" Original-X-From: ntg-context-bounces@ntg.nl Sat Apr 11 16:19:29 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNGym-000LJ7-Il for gctc-ntg-context-518@m.gmane-mx.org; Sat, 11 Apr 2020 16:19:28 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id E69EA183263; Sat, 11 Apr 2020 16:15:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1I4SH0ZuS2C3; Sat, 11 Apr 2020 16:15:52 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id F001518325E; Sat, 11 Apr 2020 16:15:51 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 1646E183254 for ; Sat, 11 Apr 2020 16:15:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ayoEQJtwwAXD for ; Sat, 11 Apr 2020 16:15:50 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=17.58.6.44; helo=pv50p00im-ztdg10021101.me.com; envelope-from=haksan@me.com; receiver= Original-Received: from pv50p00im-ztdg10021101.me.com (pv50p00im-ztdg10021101.me.com [17.58.6.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 4701218325A for ; Sat, 11 Apr 2020 16:15:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1586614548; bh=XhLxItWeIplSijkAWMnpI/tFbqQSkYwDitDOGoxr7ik=; h=From:Content-Type:Subject:Date:To:Message-Id; b=Odk7qWVWcmbLfjXLfQOCsnuIlitgMLK7U82zXvFIofehFyE9zxjFKQhGK6oytvUCA bW8D5N6QrRajEbChPHShsFtHHDjZc8dsKVGwL4sK1lcdOEl8IjMEw8LRoCY1oppXNK sJWG5DYboWLraQ+AXM8KHoYNBVs9TiSWGKEULpS7MFpQ31E8I8Ll6psXB1myWWjGdx sw43xPdj4QxY1Mt+WBGrJk44hAyidwMHsU4Z4usEDfvLTCsNyDJD6wDjVk9k85hkcA xxEjRKQf2fALUOkQ3hlaW1ZjNCoFO286GIVabTn1nz2hTkJZyYNchfV/3nsI3rt+38 l6rKHY1Xfllew== Original-Received: from [10.0.1.6] (unknown [222.232.154.22]) by pv50p00im-ztdg10021101.me.com (Postfix) with ESMTPSA id E840D1800A1 for ; Sat, 11 Apr 2020 14:15:44 +0000 (UTC) In-Reply-To: X-Mailer: Apple Mail (2.3608.80.23.2.2) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-11_04:2020-04-09, 2020-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=770 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2002250000 definitions=main-2004110135 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:106831 Archived-At: --===============8244507805955572134== Content-Type: multipart/alternative; boundary="Apple-Mail=_3ECB9AD3-4724-415B-BDFB-D043CA5630E9" --Apple-Mail=_3ECB9AD3-4724-415B-BDFB-D043CA5630E9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Dear all, The problem is solved by using the namespace of lua as below: I am not sure what I did is the right way. If it is not the right way, please let me know. Thanks for reading. Best regards, Dalyoung \startluacode P=3D{} combi =3D P function P.fact (n) if n <=3D 0 then return 1 else return n * P.fact(n-1) end end function P.ncr(n,r) return P.fact(n)/(P.fact(r)*P.fact(n-r)) end combi =3D { fact =3D fact, ncr =3D ncr, } \stopluacode \startbuffer[fig121] numeric n,r,s,u,dx,dy,tt; u :=3D 1.8cm; path p, q; pair A,B,start,now; A :=3D dir(210)*u; B :=3D dir(-30)*u; dy :=3D sind(30)*u; dx :=3D 2*cosd(30)*u; for n=3D0 upto 4: start :=3D n*dir(210)*u; for r=3D0 upto n: s :=3D n-r; % tt :=3D lua("mp.print(P.fact(" & decimal n & ")/(P.fact(" & = decimal r & ")*P.fact(" & decimal s &" )))"); tt :=3D lua("mp.print(P.ncr(" & decimal n & "," & decimal r & " = ))"); now :=3D start+r*right*dx; dotlabel.top(textext("$\displaystyle {" & decimal n & "\choose" & = decimal r & "} =3D "& decimal tt & "$"),now); draw now -- (now+A); draw now -- (now+B); endfor; endfor; \stopbuffer --Apple-Mail=_3ECB9AD3-4724-415B-BDFB-D043CA5630E9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Dear all,

The = problem is solved by using the namespace of lua as below:
I am not sure what I did is the right way.
If it is not the right way, please let me know.

Thanks for = reading.

Best = regards,

Dalyoung



\startluacode
P=3D{}
combi =3D = P

function P.fact (n)
if n <=3D 0 then
return 1
else
return n * P.fact(n-1)
end
end

function = P.ncr(n,r)
return P.fact(n)/(P.fact(r)*P.fact(n-r))
end
combi =3D = {
= fact =3D fact,
= ncr =3D ncr,
}
\stopluacode

\startbuffer[fig121]
numeric = n,r,s,u,dx,dy,tt; u :=3D= 1.8cm;
path p, q;
pair = A,B,start,now;
A :=3D dir(210)*u;
B :=3D dir(-30)*u;
dy :=3D sind(30)*u;
dx :=3D 2*cosd(30)*u;
for n=3D0 upto 4:
start = :=3D n*dir(210)*u;
for r=3D0 upto n:
s :=3D = n-r;
% tt = :=3D lua("mp.print(P.fact(" & decimal n & ")/(P.fact(" & decimal r & ")*P.fact(" & decimal s &"= )))");
tt :=3D= lua("mp.print(P.ncr(" & decimal n & "," = & decimal r & " ))");
now :=3D start+r*right*dx;
= dotlabel.top(textext("$\displaystyle {" = & decimal n & "\choose" & decimal r & "} = =3D "& decimal tt & "$"),now);
draw now -- (now+A);
draw now -- (now+B);
endfor;
endfor;
\stopbuffer

= --Apple-Mail=_3ECB9AD3-4724-415B-BDFB-D043CA5630E9-- --===============8244507805955572134== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============8244507805955572134==--