From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87079 Path: news.gmane.org!not-for-mail From: =?ISO-8859-15?Q?St=E9phane_Goujet?= Newsgroups: gmane.comp.tex.context Subject: Re: Attributes Date: Tue, 22 Apr 2014 20:10:49 +0200 (CEST) Message-ID: 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: MULTIPART/MIXED; BOUNDARY="8323328-817447762-1398190250=:8109" X-Trace: ger.gmane.org 1398189879 23415 80.91.229.3 (22 Apr 2014 18:04:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Apr 2014 18:04:39 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Apr 22 20:04:34 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 1Wcf3Z-0004u6-9t for gctc-ntg-context-518@m.gmane.org; Tue, 22 Apr 2014 20:04:33 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id AC14D10273 for ; Tue, 22 Apr 2014 20:04:32 +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 co93tx3zr2ol for ; Tue, 22 Apr 2014 20:04:32 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 52735101E9 for ; Tue, 22 Apr 2014 20:04:27 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 900CC101E6 for ; Tue, 22 Apr 2014 20:04:23 +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 JecdCTlrlEmV for ; Tue, 22 Apr 2014 20:04:21 +0200 (CEST) Original-Received: from filter3-ams.mf.surf.net (filter3-ams.mf.surf.net [192.87.102.71]) by balder.ntg.nl (Postfix) with ESMTP id D4275101E1 for ; Tue, 22 Apr 2014 20:04:21 +0200 (CEST) Original-Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by filter3-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s3MI4CcA027417 for ; Tue, 22 Apr 2014 20:04:21 +0200 Original-Received: from [192.168.1.7] ([86.217.195.30]) by mwinf5d54 with ME id t64C1n0040fpbTJ0364CTu; Tue, 22 Apr 2014 20:04:12 +0200 X-ME-Helo: [192.168.1.7] X-ME-Auth: c3RlcGhhbmUuZ291amV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 22 Apr 2014 20:04:12 +0200 X-ME-IP: 86.217.195.30 X-X-Sender: stephane@zbox.seix In-Reply-To: <53565AFF.4070304@wxs.nl> User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=80.12.242.123; country=FR; latitude=48.8600; longitude=2.3500; http://maps.google.com/maps?q=48.8600,2.3500&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 03LR64cPb - dcf385a548ee - 20140422 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.71 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:87079 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-817447762-1398190250=:8109 Content-Type: TEXT/PLAIN; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On Tue, 22 Apr 2014, Hans Hagen wrote: > On 4/20/2014 3:14 PM, St=C3=A9phane 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 somethin= g >> 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=20 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= =20 number (1024), but now node.has_attribute returns nil ... =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",=20 unicode.utf8.char(mynode.char)) then print ("Glyph =3D=20 "..unicode.utf8.char(mynode.char)) if attributes.numbers["myattr"]=3D=3Dnil then print "No attribute number for=20 myattr" else print ("myattr : number =3D=20 "..(attributes.numbers["myattr"])) end if attributes.numbers["myattrb"]=3D=3Dnil then print "No attribute number for=20 myattrb" else print ("myattrb : number =3D=20 "..(attributes.numbers["myattrb"])) end if node.has_attribute(mynode,=20 attributes.numbers["myattr"]) then print ("Attribute myattr =3D=20 "..(node.has_attribute(mynode, attributes.numbers["myattr"]))) else print "No attribute myattr" end if node.has_attribute(mynode,=20 attributes.numbers["myattrb"]) then print ("Attribute myattrb =3D=20 "..(node.has_attribute(mynode, attributes.numbers["myattrb"]))) else print "No attribute myattrb" end if node.has_attribute(mynode, 111) then print ("Attribute 111 =3D=20 "..(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=C3=A9phane. --8323328-817447762-1398190250=:8109 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 ___________________________________________________________________________________ --8323328-817447762-1398190250=:8109--