From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87087 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: Attributes Date: Wed, 23 Apr 2014 11:00:27 +0200 Message-ID: <5357812B.7010605@wxs.nl> References: <20140420131459.7c23b8af@cuisine.seix> <53565AFF.4070304@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1398243660 17282 80.91.229.3 (23 Apr 2014 09:01:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Apr 2014 09:01:00 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Apr 23 11:00:54 2014 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wct2x-0007IZ-RY for gctc-ntg-context-518@m.gmane.org; Wed, 23 Apr 2014 11:00:51 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 72C1D1023C for ; Wed, 23 Apr 2014 11:00:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qe9QCCZ1WEKr for ; Wed, 23 Apr 2014 11:00:51 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 4AEE510242 for ; Wed, 23 Apr 2014 11:00:46 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id D3E57101E7 for ; Wed, 23 Apr 2014 11:00:41 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9F1UEGf+m60e for ; Wed, 23 Apr 2014 11:00:40 +0200 (CEST) Original-Received: from filter4-til.mf.surf.net (filter4-til.mf.surf.net [194.171.167.220]) by balder.ntg.nl (Postfix) with ESMTP id 07559101E6 for ; Wed, 23 Apr 2014 11:00:31 +0200 (CEST) Original-Received: from smtp.ziggozakelijk.nl (D57D1DA2.static.ziggozakelijk.nl [213.125.29.162]) by filter4-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s3N90UQ4017288 for ; Wed, 23 Apr 2014 11:00:30 +0200 X-Default-Received-SPF: pass (skip=loggedin (res=PASS)) x-ip-name=10.100.1.103; Original-Received: from [10.100.1.103] (unverified [10.100.1.103]) by pragma-net.nl (SurgeMail 6.5a2) with ESMTP id 1941-1713362 for ; Wed, 23 Apr 2014 11:00:28 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: X-Authenticated-User: hagen@controller-9 X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=213.125.29.162; country=NL; region=Provincie Overijssel; city=Zwolle; latitude=52.5058; longitude=6.0858; http://maps.google.com/maps?q=52.5058,6.0858&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0VLRl0u5Q - 0a647d2f50e8 - 20140423 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.220 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 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-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:87087 Archived-At: On 4/22/2014 8:10 PM, St=E9phane Goujet wrote: > On Tue, 22 Apr 2014, Hans Hagen wrote: > >> On 4/20/2014 3:14 PM, St=E9phane Goujet wrote: >>> I would like to know what is the recommended way to use >>> attributes in >>> Context. >>> What is the Context way to declare and set attributes? Is it something >>> like this? >>> \defineattribute[myattr] >>> \dosetattribute{myattr}{1} >>> >>> And how do I then access them from Lua? Should it look like >>> has_attribute(mynode, attributes.myattr) >>> or >>> has_attribute(mynode, attributes.xxxxx("myattr")) >>> or something else? >> >> attributes.names[...] >> attributes.numbers[...] > > Please have a look at my example (it is a bit long because it shows > various possibilities) and its result. > When I have not yet done a \defineattribute[myattr], node.has_attribu= te > returns 0 when I thought it should return nil. > When I do \defineattribute[...], every attribute seems to get the > same number (1024), but now node.has_attribute returns nil ... change this is syst-ini.mkiv: \normalprotected\def\newattribute{\syst_basics_allocate\c_syst_last_allocat= ed_attribute\attribute\attributedef\c_syst_max_allocated_register} > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > Example > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > \starttext > > \startluacode > mycallback=3Dfunction(head) > if attributes.names=3D=3Dnil then > print "No attribute names at all" > end > if attributes.numbers=3D=3Dnil then > print "No attribute numbers at all" > end > for mynode in node.traverse_id(node.id("glyph"), head) do > if string.match("0ABCDEabcdefg", > unicode.utf8.char(mynode.char)) then > print ("Glyph =3D "..unicode.utf8.char(mynode.char)) > if attributes.numbers["myattr"]=3D=3Dnil then > print "No attribute number for myattr" > else > print ("myattr : number =3D > "..(attributes.numbers["myattr"])) > end > if attributes.numbers["myattrb"]=3D=3Dnil then > print "No attribute number for myattrb" > else > print ("myattrb : number =3D > "..(attributes.numbers["myattrb"])) > end > if node.has_attribute(mynode, > attributes.numbers["myattr"]) then > print ("Attribute myattr =3D > "..(node.has_attribute(mynode, attributes.numbers["myattr"]))) > else > print "No attribute myattr" > end > if node.has_attribute(mynode, > attributes.numbers["myattrb"]) then > print ("Attribute myattrb =3D > "..(node.has_attribute(mynode, attributes.numbers["myattrb"]))) > else > print "No attribute myattrb" > end > if node.has_attribute(mynode, 111) then > print ("Attribute 111 =3D > "..(node.has_attribute(mynode, 111))) > else > print "No attribute 111" > end > end > end > return head > end > > nodes.tasks.appendaction("processors", "before", "mycallback") > \stopluacode > > 0 > > \attribute111=3D-1 > A > > \attribute111=3D200 > B > > \attribute111=3D202 > C > > \attribute111=3D-1 > D > > \attribute111=3D-"7FFFFFFF > E > > \defineattribute[myattr] > \defineattribute[myattrb] > a > > \doresetattribute{myattr} > b > > \dosetattribute{myattr}{500} > c > > \dosetattribute{myattr}{502} > d > > \doresetattribute{myattr} > e > > > \stoptext > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > Result : > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > Glyph =3D 0 > No attribute number for myattr > No attribute number for myattrb > Attribute myattr =3D 0 > Attribute myattrb =3D 0 > No attribute 111 > Glyph =3D A > No attribute number for myattr > No attribute number for myattrb > Attribute myattr =3D 0 > Attribute myattrb =3D 0 > Attribute 111 =3D -1 > Glyph =3D B > No attribute number for myattr > No attribute number for myattrb > Attribute myattr =3D 0 > Attribute myattrb =3D 0 > Attribute 111 =3D 200 > Glyph =3D C > No attribute number for myattr > No attribute number for myattrb > Attribute myattr =3D 0 > Attribute myattrb =3D 0 > Attribute 111 =3D 202 > Glyph =3D D > No attribute number for myattr > No attribute number for myattrb > Attribute myattr =3D 0 > Attribute myattrb =3D 0 > Attribute 111 =3D -1 > Glyph =3D E > No attribute number for myattr > No attribute number for myattrb > Attribute myattr =3D 0 > Attribute myattrb =3D 0 > No attribute 111 > Glyph =3D a > myattr : number =3D 1024 > myattrb : number =3D 1024 > No attribute myattr > No attribute myattrb > No attribute 111 > Glyph =3D b > myattr : number =3D 1024 > myattrb : number =3D 1024 > No attribute myattr > No attribute myattrb > No attribute 111 > Glyph =3D c > myattr : number =3D 1024 > myattrb : number =3D 1024 > No attribute myattr > No attribute myattrb > No attribute 111 > Glyph =3D d > myattr : number =3D 1024 > myattrb : number =3D 1024 > No attribute myattr > No attribute myattrb > No attribute 111 > Glyph =3D e > myattr : number =3D 1024 > myattrb : number =3D 1024 > No attribute myattr > No attribute myattrb > No attribute 111 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > Goodbye, > St=E9phane. > > > _________________________________________________________________________= __________ > 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-co= ntext > webpage : http://www.pragma-ade.nl / http://tex.aanhet.net > archive : http://foundry.supelec.fr/projects/contextrev/ > wiki : http://contextgarden.net > _________________________________________________________________________= __________ > -- = ----------------------------------------------------------------- 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 ----------------------------------------------------------------- ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________