* string.format changed in LuaTeX / grph-downsample
@ 2018-03-23 8:46 Henning Hraban Ramm
2018-03-23 9:44 ` Hans Hagen
0 siblings, 1 reply; 2+ messages in thread
From: Henning Hraban Ramm @ 2018-03-23 8:46 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 736 bytes --]
Ahoi, since i recently updated my ConTeXt beta, Lua function string.format behaves differently, i.e. type checks are stricter.
I guess it’s due to switching to Lua 5.3 in LuaTeX?
E.g. this:
if tonumber(string.format('%d', value)) == value then ...
throws
bad argument #2 to 'format' (number has no integer representation)
Since I just need to check if the number is integer, this works:
if tonumber(value) == math.floor(value) then ...
This also affects Peter Münster’s grph-downsample module; please find a fixed version attached.
(Decimal pixel sizes make no sense anyway, so I just "floored" them.)
Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD
[-- Attachment #2: grph-downsample.lua --]
[-- Type: application/octet-stream, Size: 1655 bytes --]
if not modules then modules = { } end modules ['grph-downsample'] = {
version = 1.002,
comment = "companion to grph-inc.mkiv",
author = "Peter Münster",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local format = string.format
-- figures.cachepaths.path = "cache" -- should be setup-option
local function sample_down(oldname, newname, resolution)
local request = figures.current().request
local width = request.width
local height = request.height
if resolution == "" or (not width and not height) then
-- can work only if width and/or height ist set
print(format("Nothing to do: %s, %s, %s", oldname, newname, resolution))
return
end
local inch = 72.27
local image = img.scan{filename = oldname}
local xy = image.xsize / image.ysize
if not width then
width = height * xy / 65536
end
if not height then
height = width / xy / 65536
end
local xsize = math.floor(resolution * width / inch)
local ysize = math.floor(resolution * height / inch)
if xsize < image.xsize or ysize < image.ysize then
local s = format("gm convert -resize %dx%d %s %s",
xsize, ysize, oldname, newname)
print("Conversion: " .. s)
os.execute(s)
else
print(format("Nothing to do: %s, %s, %s", oldname, newname, resolution))
print(format("xsize = %d, ysize = %d", xsize, ysize))
end
end
local formats = {"png", "jpg", "gif"}
for _, s in ipairs(formats) do
figures.converters[s] = figures.converters[s] or {}
figures.converters[s]["lowres." .. s] = sample_down
end
[-- Attachment #3: Type: text/plain, Size: 492 bytes --]
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: string.format changed in LuaTeX / grph-downsample
2018-03-23 8:46 string.format changed in LuaTeX / grph-downsample Henning Hraban Ramm
@ 2018-03-23 9:44 ` Hans Hagen
0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen @ 2018-03-23 9:44 UTC (permalink / raw)
To: ntg-context
On 3/23/2018 9:46 AM, Henning Hraban Ramm wrote:
> Ahoi, since i recently updated my ConTeXt beta, Lua function string.format behaves differently, i.e. type checks are stricter.
> I guess it’s due to switching to Lua 5.3 in LuaTeX?
This is indeed one of the changes in 5.3 (more about that at the ctx
meeting).
Anyway, format is a bit unstable over time anyway, which is why in
context we have string.formatters with some more options (cld manual):
print(string.formatter("%r",1))
print(string.formatter("%r",1.1))
print(string.formatter("%p",1))
print(string.formatter("%p",1.1))
etc. On the average its also faster than string.format. It means that we
could make the transition to 5.3 without too much hassle (very little
had to be adapted and luigi and i are running context with 5.3 for quite
a while now).
> E.g. this:
>
> if tonumber(string.format('%d', value)) == value then ...
>
> throws
>
> bad argument #2 to 'format' (number has no integer representation)
>
> Since I just need to check if the number is integer, this works:
>
> if tonumber(value) == math.floor(value) then ...
>
>
> This also affects Peter Münster’s grph-downsample module; please find a fixed version attached.
> (Decimal pixel sizes make no sense anyway, so I just "floored" them.)
better round them
> Greetlings, Hraban
> ---
> http://www.fiee.net
> http://wiki.contextgarden.net
> GPG Key ID 1C9B22FD
>
>
>
> ___________________________________________________________________________________
> 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://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
--
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-23 9:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-23 8:46 string.format changed in LuaTeX / grph-downsample Henning Hraban Ramm
2018-03-23 9:44 ` Hans Hagen
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).