[NTG-context] lpdf.checkedkey has problem with false values
Dear Developers and All, lpdf.checkedkey routine from lpdf-ini.lua has problems with accessing false boolean values, it returns them as nil. Is it by design or neglect? (I vaguely remember stumbling on this problems before, so there is a chance that I have already got the answer, but have forgotten it.) The minimal demo: \starttext \startluacode local function writebool(bv,text) if bv == true then io.write(text, true \n) elseif bv == nil then io.write(text, nil \n) else io.write(text, false\n) end end local a = {} a[x] = true a[y] = false a[z] = nil writebool(lpdf.checkedkey(a,x,boolean),lpdf.checkedkey(a,\x\,\boolean\)) writebool(lpdf.checkedkey(a,y,boolean),lpdf.checkedkey(a,\y\,\boolean\)) writebool(lpdf.checkedkey(a,z,boolean),lpdf.checkedkey(a,\z\,\boolean\)) writebool(a.x,a.x) writebool(a.y,a.y) writebool(a.z,a.z) \stopluacode TEST \stoptext It results in the following relevant output lpdf.checkedkey(a,x,boolean) true lpdf.checkedkey(a,y,boolean) nil lpdf.checkedkey(a,z,boolean) nil a.x true a.y false a.z nil Note that false value was read by checkedkey as nil. Sincerely, 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
Am 15.09.2014 um 16:14 schrieb Michail Vidiassov: Dear Developers and All, lpdf.checkedkey routine from lpdf-ini.lua has problems with accessing false boolean values, it returns them as nil. Is it by design or neglect? More a lua design decision. 'nil' is equal to 'false' here, 'true' is equal to all that is not 'nil'. http://www.lua.org/pil/3.3.html (I vaguely remember stumbling on this problems before, so there is a chance that I have already got the answer, but have forgotten it.) The minimal demo: \starttext \startluacode local function writebool(bv,text) if bv == true then if bv then io.write(text, true \n) elseif bv == nil then else (if not bv then) HTH, Peter io.write(text, nil \n) else io.write(text, false\n) end end local a = {} a[x] = true a[y] = false a[z] = nil writebool(lpdf.checkedkey(a,x,boolean),lpdf.checkedkey(a,\x\,\boolean\)) writebool(lpdf.checkedkey(a,y,boolean),lpdf.checkedkey(a,\y\,\boolean\)) writebool(lpdf.checkedkey(a,z,boolean),lpdf.checkedkey(a,\z\,\boolean\)) writebool(a.x,a.x) writebool(a.y,a.y) writebool(a.z,a.z) \stopluacode TEST \stoptext It results in the following relevant output lpdf.checkedkey(a,x,boolean) true lpdf.checkedkey(a,y,boolean) nil lpdf.checkedkey(a,z,boolean) nil a.x true a.y false a.z nil Note that false value was read by checkedkey as nil. Sincerely, 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 ___ ___ 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
Dear Peter, More a lua design decision. 'nil' is equal to 'false' here I know no CS theory behind lua design, but try this: \starttext \startluacode if nil == false then io.write(nil == false\n) end if nil ~= false then io.write(nil ~= false\n) end \stopluacode TEST \stoptext and get nil ~= false As checkedkey is for reading parameter tables, based on user input, there may be real difference between a property not set (i.e. nil) and one set to be false. What if the default setting is true, for example? 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
On Mon, 15 Sep 2014, Michail Vidiassov wrote: Dear Peter, More a lua design decision. 'nil' is equal to 'false' here I know no CS theory behind lua design, but try this: \starttext \startluacode if nil == false then io.write(nil == false\n) end if nil ~= false then io.write(nil ~= false\n) end \stopluacode TEST \stoptext and get nil ~= false I think that what Peter meant was: if nil then end if not nil then ... end Aditya ___ 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
Dear Aditya, Peter and All, I think that what Peter meant was: the real issue is not teaching me lua and improving the style of my example, but my complaint (correct or not) about inability of lpdf.checkedkey to correctly fetch false boolean values: they are fetched as nil, just as if they were absent or of incorrect type. Please, someone with time and, preferably, authority - take a look at lpdf.checkedkey code (5 minutes maximum). Talking in general about lua, not knowing what lpdf.checkedkey is, does and is supposed to do, does not look like efficient use of time. 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
On 9/15/2014 6:12 PM, Michail Vidiassov wrote: Dear Aditya, Peter and All, I think that what Peter meant was: the real issue is not teaching me lua and improving the style of my example, but my complaint (correct or not) about inability of lpdf.checkedkey it looks like your question was not clear then to correctly fetch false boolean values: they are fetched as nil, just as if they were absent or of incorrect type. well, they're just not treated special Please, someone with time and, preferably, authority - take a look at lpdf.checkedkey code (5 minutes maximum). Talking in general about lua, not knowing what lpdf.checkedkey is, does and is supposed to do, does not look like efficient use of time. you can try this (untested) 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 return toboolean(pn) end end end end - 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
On 9/15/2014 8:25 PM, Michail Vidiassov wrote: 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 more like function lpdf.checkedkey(t,key,variant) local pn = t and t[key] if pn ~= nil 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) -- or nil elseif variant == boolean then return string.is_boolean(pn,nil,true) end end end end - 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 ___
Re: [NTG-context] lpdf.checkedkey has problem with false values
Dear Hans, more like function lpdf.checkedkey(t,key,variant) thank you. That works. Please, commit. Michail PS. lpdf.checkedkey issue was raised while I reviewed 3D PDF support. But there are greater problems: It seems that u3d inclusion stopped to work in the current (2014.09.06 20:59) ConTeXt. Texlive 2014 works. As far as I can track, the problem is caused by the change in function register(askedname,specification) from grph-inc.lua: if format %a supported by output file format (and u3d falls under this category) specification.found is set to false in the current ConTeXt. If I set it to true in this case (as in TeXLive 2014 version of ConTeXt) things start to work again. May be by doing so I am reversing some unfinished change, but it works for me. The relevant patch: @@ -725,7 +725,7 @@ report_inclusion(format %a natively supported by backend,format) end else -specification.found = false +specification.found = true -- was false if trace_figures then report_inclusion(format %a supported by output file format,format) end ___ 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 ___