lua-users home
lua-l archive

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


On 12/11/2012 19:08, Roberto Ierusalimschy wrote:
Maybe related, or not:

    print(string.format("%s", true))
==>
    Error: xyz.lua:192: bad argument #2 to 'format' (string expected, got boolean)

_Sometimes_, in some program files (and the same with other
non-string and non-number types).
(This is why I was so surprised when, in a previous thread, Luiz H.
de Figueiredo just stepped it to note it's right what format now
does in 5.2 (auto-convert to string). I then checked in a test file,
and it worked like a charm. But I knew I had had these errors
precisely, reason of my to wrap that into a printf and worrying.
These same errors now come back in different files of 2 different
projects. And again I have checked I don't modify by error any
builtin func or "type-table".)

Indeed, it seems quite related. Again, it looks like you are using Lua
5.1 instead of Lua 5.2:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
print(string.format("%s", true))
stdin:1: bad argument #2 to 'format' (string expected, got boolean)


Lua 5.2.1  Copyright (C) 1994-2012 Lua.org, PUC-Rio
print(string.format("%s", true))
true

Right, I understand, but then why does it work in simple test cases (and also in some cases from my project files)? The parameters I give to my editor --geany-- about the run command don't change in the meantime, it's the same lua beeing launched in both cases. Also, i have tried from the command-line directly. Anyway, as shown in a previous message, I don't have lua 5.1. In usr/bin/, I have lua5.2, luac5.2 and 2 symlinks lua, luac. And 'which' finds lua, lua 5.2, but no lua 5.1 (unless lua5.1 the program was called by another name?).

Denis