ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Otared Kavian <otared@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: How to use in Metafun, a function defined in Lua
Date: Sat, 28 Dec 2019 16:22:42 +0100	[thread overview]
Message-ID: <F0146DF6-8A04-42B7-90BC-E0FE92D1445F@gmail.com> (raw)

Hi all,

I would like to use a math function defined in lua in Metafun in order to draw its graph, together with the graphs of some other functions.
As a simple example consider the following:

%%% begin lua-metafun-example.tex
\startluacode 
	function document.myfunction(n,x)
		local S
		S = math.sin(n*x)
		return S
	end
\stopluacode

\starttext

Here \type{document.myfunction(n,x)} is $\sin(nx)$. For instance when $n = 2$ and $x = 355/113$ we have:

\type{document.myfunction(2,355/113)} $=\cldcontext{document.myfunction(2,355/113)} \sim 0$.

\startplacefigure[title={Nothing works\dots}]
\startMPcode{GridAxis}
	numeric gu ; gu = 5mm ; % gu = graph unit
	draw image (
	draw function (1,"x","document.myfunction(2,x)", % <-- this does not work
%	draw function (1,"x","sin(2*x)", % <-- this works
	-355/113,355/113,.01)
	scaled gu 
	withpen pencircle scaled .075pt
	withcolor darkred ;
	) xsized .7TextWidth ;
\stopMPcode
\stopplacefigure

\stoptext
%%% end lua-metafun-example.tex

Here one sees that the function « document.myfunction » is well defined in Lua and is known in ConTeXt, but I cannot use it in a Metapost code: how can one do that?

Thanks in advance for any help.
Best regards: Otared
___________________________________________________________________________________
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
___________________________________________________________________________________

             reply	other threads:[~2019-12-28 15:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-28 15:22 Otared Kavian [this message]
2019-12-28 15:46 ` Hans Hagen

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=F0146DF6-8A04-42B7-90BC-E0FE92D1445F@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).