From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/88702 Path: news.gmane.org!not-for-mail From: Michail Vidiassov Newsgroups: gmane.comp.tex.context Subject: Re: lpdf.checkedkey has problem with false values Date: Mon, 15 Sep 2014 22:25:15 +0400 Message-ID: References: <5416FEEC.7080704@gmx.net> <54171DE2.3070008@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1410805540 11220 80.91.229.3 (15 Sep 2014 18:25:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Sep 2014 18:25:40 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Sep 15 20:25:35 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 1XTaxy-0008HX-Pc for gctc-ntg-context-518@m.gmane.org; Mon, 15 Sep 2014 20:25:34 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 7CE1510220 for ; Mon, 15 Sep 2014 20:25:34 +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 LYws6dg2-TMR for ; Mon, 15 Sep 2014 20:25:34 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id CD96310221 for ; Mon, 15 Sep 2014 20:25:26 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 8F809101E6 for ; Mon, 15 Sep 2014 20:25: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 uzdRqC8JVacJ for ; Mon, 15 Sep 2014 20:25:18 +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 EBE6E101E1 for ; Mon, 15 Sep 2014 20:25:17 +0200 (CEST) Original-Received: from mail-lb0-x234.google.com (mail-lb0-x234.google.com [IPv6:2a00:1450:4010:c04::234]) by filter3-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s8FIPGWw006374 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Mon, 15 Sep 2014 20:25:16 +0200 Original-Received: by mail-lb0-f180.google.com with SMTP id b12so4980837lbj.39 for ; Mon, 15 Sep 2014 11:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iaas.msu.ru; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=wUhksO1bXMfp+UVkKBkDmgrTYroNOXus6cRxhPU6iMA=; b=deIH+h+a+BzXTht2JKeezWoR42EfV2McgwqwJIYyua+WVzQXETYVo2Q8/YuOQnTZXY 51RdNSmCF47PG25zUTbpZenustJs5ZS6nnS5ki/7H4nNt75HWx6zznXQXsfa3CYqFRFn kWcs4X+85/kQYBkA7M6yxaShRcgnpXDEhNuqE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=wUhksO1bXMfp+UVkKBkDmgrTYroNOXus6cRxhPU6iMA=; b=RnuDPSkv7ljH7ymPkI3a0ERInVWHqoZ29nxIrrOyneeSieraqDhky2ksrtdWi14wl3 6URXHqWwhQW+/NPnpfX1T+6j+jBnSrWC4o5vO4k9fHePuRxBzv+9aBnQ3Ctw5g/6Z5Lj mdRb5XC89tudBYn6eWS4vHs4E9dc6Y3nsR+v/Oi8rUi26zci+R6pmRAq6uo1PXol/5Lf JLqknwachLBQTzacB6ha5XQweB7vNpym27uC3XhYVMA6V2GjTx8q2MrfE79g2xUEKUob quCUUTTGsoziuky1lbNjjfqxvs51LulDDXFzutAPaouYUSHMPpDW/UHlJ+2wf/BCpoiM Uh7A== X-Gm-Message-State: ALoCoQnZZAkG+PUS6HzVhPzmvA+L0j10bzEQmsWXJORwX+CXvn7GxfXTrOyusFgb+kRhT36M96VV X-Received: by 10.112.135.137 with SMTP id ps9mr29044979lbb.24.1410805515714; Mon, 15 Sep 2014 11:25:15 -0700 (PDT) Original-Received: by 10.112.137.38 with HTTP; Mon, 15 Sep 2014 11:25:15 -0700 (PDT) In-Reply-To: <54171DE2.3070008@wxs.nl> X-Bayes-Prob: 0.4609 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=2a00:1450:4010:c04::234; country=IE X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 03MPupgVP - bc797eb46e25 - 20140915 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) 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:88702 Archived-At: Dear Hans, > well, they're just not treated special IMHO, they have to be treated special. > you can try this (untested) I have tested it. It adds nice enhancement, but does not fix the bug In the following case local a = {} a["e"] = "blabla" a["t"] = "true" a["f"] = "false" a["x"] = true a["y"] = false a["z"] = nil your new lpdf.checkedkey correctly fetches "t" and "f", where the old one failed. And your new lpdf.checkedkey fails for "e" - if I attempt to fetch it as boolean I get false instead of nil. (That is caused by toboolean returning false for unconvertible data - unlike tonumber). But I did not complain about reading strings! My problem was with "y". Both your new and old lpdf.checkedkey fetch it as nil instead of false. My (somewhat ugly) idea of the fix is the following local function lpdf.checkedkey(t,key,variant) local pn = t and t[key] if pn then local tn = type(pn) if tn == variant then if variant == "string" then return pn ~= "" and pn or nil elseif variant == "table" then return next(pn) and pn or nil else return pn end elseif tn == "string" then if variant == "number" then return tonumber(pn) elseif variant == "boolean" then if pn == "true" then return true elseif pn == "false" then return false end end end elseif t and t[key] ~= nil and variant == "boolean" and type(t[key]) == "boolean" then return t[key] end end Michail ___________________________________________________________________________________ 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 ___________________________________________________________________________________