ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: hajtmar@gyza.cz, mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Lua in LuaLaTeX is diferent??
Date: Sun, 06 Jun 2010 13:42:25 +0200	[thread overview]
Message-ID: <4C0B89A1.5040605@wxs.nl> (raw)
In-Reply-To: <4C0ADF3B.9030308@gyza.cz>

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
___________________________________________________________________________________


  parent reply	other threads:[~2010-06-06 11:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-05 20:19 Jaroslav Hajtmar
2010-06-05 23:35 ` Jaroslav Hajtmar
2010-06-06  2:46   ` Khaled Hosny
2010-06-06  6:15     ` Jaroslav Hajtmar
2010-06-06  6:34       ` Jaroslav Hajtmar
2010-06-06 11:17         ` Hans Hagen
2010-06-06 13:00       ` Khaled Hosny
2010-06-06 11:42   ` Hans Hagen [this message]
2010-06-06 11:13 ` Hans Hagen
2010-06-06 18:24   ` Jaroslav Hajtmar

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=4C0B89A1.5040605@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=hajtmar@gyza.cz \
    --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).