lua-users home
lua-l archive

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


On Tue, 2011-03-08 at 12:49 +0100, Bertrand Mansion wrote:
> 
>   local playlist = itunes_application:currentPlaylist()   local plname
> = playlist:name()   print(string.format("Current playlist %s",
> plname))  
> 
> /Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa: ./ScriptingBridge_iTunes.lua:30: bad argument #2 to 'format' (string expected, got userdata) 

I do not know anything about LuaCocoa, but your problem is related to
the fact, that Cocoa strings are represented using userdata, and you
need to call tostring() to get the corresponding Lua string.

In your code, string.format('...%s...', plname) does not work, because
the %s expects a Lua string, and you pass userdata.

On the other hand, print(...) automatically calls tostring() on every
argument - so you receive a Lua string after all.

The solution is to use tostring explicitly and call string.format as
follows:

print(string.format("Current playlist %s", tostring(plname)))