lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Mar 23, 2014 at 09:10:06PM -0300, Luiz Henrique de Figueiredo wrote:
> > Most common breakage seem to be (%d+) captures.
> How so?

Or my codebase is just particularly crappy. This manifested quite often:

Lua 5.3.0 (work2-dontcoerce)  Copyright (C) 1994-2014 Lua.org, PUC-Rio
> debug.setmetatable(0, {
>>     __sub = function(a,b) return tonumber(a)-tonumber(b) end
>> })
> for bottles=("bottles=99"):match("bottles=(%d+)"),1,-1 do
>>     print(bottles)
>> end 
stdin:1: 'for' initial value must be a number

Setting number meta was my first go-to fix, but turns out there are
way too many places not triggering it.

Or perhaps go the opposite route - keep the in-stack coercion, but via
string.__tonumber. Whoever wants to, can nuke it. As a bonus, users can
pass arbitrary data as numbers, too.