[PD-dev] pdlua: lua-5.3 problem with float/int representation

Patric Schmitz flavi0 at openmailbox.org
Mon Aug 1 17:59:52 CEST 2016


Hi pd devs,

I'm using pd 0.47.1 on archlinux which ships the latest lua-5.3
by default. It seems that in 5.3 the internal representation of
'number' types differentiates between floating and integer types
now. Quoting the manual:
> The type number uses two internal representations, or two subtypes, one called integer and the other called float. Lua has explicit rules about when each representation is used, but it also converts between them automatically as needed (see ยง3.4.3).

This led to the problem that the 'inlet' variable to string
conversion resulted in the value 1.0 instead of 1, so the
dispatching of the method failed since no method named e.g.
in_1.0_float exists.

I was able to fix it by making the inlet value integral with
> inlet = math.floor(inlet)
in pd.lua pd.Class:dispatch.

An integer-cast could be used as well, but that would not be
compatible with older language versions. As found by Claude on
IRC the floor version should be safe since "Rounding functions
(math.ceil, math.floor, and math.modf) return an integer when the
result fits in the range of an integer, or a float otherwise.".
So as long as < 2^31 inlets are used, which one can reasonably
assume, this should be fine.

There are probably more places where this fix would need to be
applied, such as the outlet dispatching, and the multi-receive
example. It should also be commented to make obvious what is
happening, like that no int-cast is used due to older language
version compatibility.

Thanks,
Patric



More information about the Pd-dev mailing list