From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/59373 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: Lua in LuaLaTeX is diferent?? Date: Sun, 06 Jun 2010 13:42:25 +0200 Message-ID: <4C0B89A1.5040605@wxs.nl> References: <4C0AB151.4060808@gyza.cz> <4C0ADF3B.9030308@gyza.cz> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1275824563 14759 80.91.229.12 (6 Jun 2010 11:42:43 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 6 Jun 2010 11:42:43 +0000 (UTC) To: hajtmar@gyza.cz, mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Jun 06 13:42:39 2010 connect(): No such file or directory Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OLEFT-0006eO-EZ for gctc-ntg-context-518@m.gmane.org; Sun, 06 Jun 2010 13:42:39 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 8FF49C9CCB; Sun, 6 Jun 2010 13:42:38 +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 jWu-Zxin9zXb; Sun, 6 Jun 2010 13:42:35 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id EA155C9B87; Sun, 6 Jun 2010 13:42:34 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E5D9DC9B16 for ; Sun, 6 Jun 2010 13:42: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 jx1xMREKne8t for ; Sun, 6 Jun 2010 13:42:27 +0200 (CEST) Original-Received: from smtp.ziggozakelijk.nl (sc-162.r-213-125-29.schoolconnect.nu [213.125.29.162]) by balder.ntg.nl (Postfix) with ESMTP id B386BC9B87 for ; Sun, 6 Jun 2010 13:42:27 +0200 (CEST) X-Default-Received-SPF: pass (skip=loggedin (res=PASS)) x-ip-name=10.100.1.100; Original-Received: from [10.100.1.100] (unverified [10.100.1.100]) by controller-9 (SurgeMail 4.3e) with ESMTP id 546-1713362 for multiple; Sun, 06 Jun 2010 13:42:18 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 In-Reply-To: <4C0ADF3B.9030308@gyza.cz> X-Authenticated-User: hagen@controller-9 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:59373 Archived-At: On 6-6-2010 1:35, Jaroslav Hajtmar wrote: > The second is more universal, but it only works in ConTeXt MKIV. > LuaLaTeX report error: "attempt to call field 'split' (a nil value) ... ." > > function ParseCSVdata(string2parse, separator, leftdelimiter, > rightdelimiter) > Sep = (Sep == nil) and UserCSVSeparator or Sep > Ld = (Ld == nil) and UserCSVLeftDelimiter or Ld > Rd = (Rd == nil) and UserCSVRightDelimiter or Rd > local separator = (separator == nil) and Sep or separator > local leftdelimiter = (leftdelimiter == nil) and Ld or leftdelimiter > local rightdelimiter = (rightdelimiter == nil) and Rd or rightdelimiter > local result={} > if leftdelimiter ~= '' and rightdelimiter ~= '' then > string.gsub(string2parse, leftdelimiter.."(.-)"..rightdelimiter, > function(a) table.insert(result,a) end ) > else > result=string.split(string2parse,separator) > end > return result > end You probably mean something ... UserCSVSeparator = ';' UserCSVLeftDelimiter = '' UserCSVRightDelimiter = '' function ParseCSVdata(string2parse, separator, leftdelimiter, rightdelimiter) leftdelimiter = leftdelimiter or Ld or UserCSVLeftDelimiter or "" rightdelimiter = rightdelimiter or Rd or UserCSVRightDelimiter or "" if leftdelimiter ~= '' and rightdelimiter ~= '' then local result = { } local pattern = string.esc(leftdelimiter) .. "(.-)" .. string.esc(rightdelimiter) for s in string.gmatch(string2parse,pattern) do table.insert(result,s) end return result else return string.split(string2parse,separator or Sep or UserCSVSeparator or ";") end end but anyhow, this might (name) clash at some point i guess, for instance because of using globals like Ld In order to be more or less compatible with the context module and third party code setup, in context you need to do: thirddata = thirddata or { } thirddata.cvs = { separator = ';', leftdelimiter = '', rightdelimiter = '', } function thirddata.cvs.parse(string2parse,separator,leftdelimiter,rightdelimiter) leftdelimiter = leftdelimiter or thirddata.leftdelimiter or "" rightdelimiter = rightdelimiter or thirddata.rightdelimiter or "" if leftdelimiter ~= "" and rightdelimiter ~= "" then local result = { } local pattern = string.esc(leftdelimiter) .. "(.-)" .. string.esc(rightdelimiter) for s in string.gmatch(string2parse,pattern) do table.insert(result,s) end return result else return string.split(string2parse,separator or thirddata.separator or ";") end end -- print(table.serialize(thirddata.cvs.parse("11,ss,cc",","))) -- print(table.serialize(thirddata.cvs.parse("[11] [ss] [cc]","","[","]"))) but i have no clue how this is used so there might be better approaches 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 ___________________________________________________________________________________