lua-users home
lua-l archive

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


local function callable_to_function(callable)
   return
      function(...)
         return callable(unpack(arg))
      end       
end

local callable_table = setmetatable({}, {__call = function (t, k, v) print(k,v) end})

foreach({a = 1, [3] = 'hello'}, callable_to_function(callable_table))


>-----Original Message-----
>From: Gustavo Niemeyer [mailto:niemeyer@conectiva.com]
>Sent: Friday, December 19, 2003 12:39 PM
>To: Lua list
>Subject: Re: __call?
>
>
>> > To the Lua authors, are there any plans for changes in 5.1 or later
>> > to address these issues?
>>
>> Currently we have no plans to change that. As pointed out,
>> lua_isfunction is different from lua_iscallable. If you really want
>> that, it is quite easy to define a reasonable lua_iscallable
>using the
>> current API.
>[...]
>
>It might be a good idea to at least fix the standard library in this
>respect, either completely removing the type checking from
>table.foreach
>and others, or implementing a generic checking mechanism.
>
>--
>Gustavo Niemeyer
>http://niemeyer.net
>
>