From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/83810 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: problem with lua io.lines Date: Wed, 14 Aug 2013 17:00:56 +0200 Message-ID: <520B9BA8.8080302@wxs.nl> References: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1376492495 22673 80.91.229.3 (14 Aug 2013 15:01:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Aug 2013 15:01:35 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Aug 14 17:01:39 2013 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 1V9cZu-0005zM-Un for gctc-ntg-context-518@m.gmane.org; Wed, 14 Aug 2013 17:01:39 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1A19810207; Wed, 14 Aug 2013 17:00:43 +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 kf6ET8U4rjWS; Wed, 14 Aug 2013 17:00:41 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id A68E7101FF; Wed, 14 Aug 2013 17:00:41 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 8A093101FF for ; Wed, 14 Aug 2013 17:00:40 +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 bWQQyKY1cCC4 for ; Wed, 14 Aug 2013 17:00:26 +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 BB725101FC for ; Wed, 14 Aug 2013 17:00:26 +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 r7EF1KLw032043 for ; Wed, 14 Aug 2013 17:01:21 +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.3c2) with ESMTP id 1462-1713362 for ; Wed, 14 Aug 2013 17:01:20 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: X-Authenticated-User: hagen@controller-9 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=213.125.29.162; country=NL; region=15; 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: 0VKcD1kXF - d26f92463b26 - 20130814 (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:83810 Archived-At: On 8/14/2013 4:43 PM, Henning Hraban Ramm wrote: > > Am 2013-08-14 um 20:15 schrieb Wolfgang Schuster : > >>> Current beta MkIV seems to have a bug in the Lua function io.lines: >>> >>> for myline in io.lines(myfile) do >>> logs.report(myline) >>> end >>> >>> "myfile" just contains one line with a number, without return/newline. >>> If the number has more than one digit, I get single digits as "myeline". >> >> Do you have a minimal working example? > > Minimal working yes, but not minimal failing ;-) > > This works: > > io.output(io.open("myfile.txt","w")) > io.write("123") > io.close() > > for myline in io.lines("myfile.txt") do > print(myline .. "\n") > end > > But in my t-lilyfilter.tex where it reads the systems.count files of LilyPond (that contain only the number of note systems that resulted from the included LilyPond code), it fails: > > function thirddata.parselilypondfile(name) > -- include all systems (note lines) > -- name is like \LILYTEMP/mainfile-temp-lilypond-21.pdf > logs.report("LILYPOND","name='" .. name .. "'") > syco = 0 > for ts in io.lines(string.gsub(name, '%.pdf$', '-systems.count')) do > syco = ts*1 > end > > for nr = 1, syco do > logs.report("LILYPOND","including system no." .. nr) > context("\\externalfigure[" .. string.gsub(name, '%.pdf$', '-' .. nr) .. "]") > end > end > > > While I have a single-digit number of systems, it works, but the song of my failing case has 11 lines. > > I wouldn't complain if it wouldn't have worked before! well, you probably were lucky before: string.gsub returns multiple values so io.lines get a second argument that limits the length of what gets returned local myfile = "myfile.txt" for myline in io.lines(myfile,2) do logs.report("test",myline) end so you need: io.lines((string.gsub(name, '%.pdf$', '-systems.count'))) or local name = string.gsub(name, '%.pdf$', '-systems.count') io.lines(name) or maybe better: io.lines(file.replacesuffix(name,'-systems.count')) Hans ----------------------------------------------------------------- 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 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 ___________________________________________________________________________________