Functions as first-class objects

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Functions as first-class objects

Alejandro Reimondo
Hi,

Is it possible to send messages to functions?

I need to extend functions as first-class objects.

With string values the feature is implemented

extending string's metatables.

I coudn´t found a similar way to do it with

  function values.

Is it a limitation for functions in Lua?

Any help and/or links to find a solution will be appreciated.

cheers,

Ale




Reply | Threaded
Open this post in threaded view
|

Re: Functions as first-class objects

Dirk Laurie-2
Op Vr., 31 Aug. 2018 om 18:30 het Alejandro Reimondo
<[hidden email]> geskryf:


> Is it possible to send messages to functions?
>
> I need to extend functions as first-class objects.

Wrap it in a coroutine.

Reply | Threaded
Open this post in threaded view
|

Re: Functions as first-class objects

Egor Skriptunoff-2
In reply to this post by Alejandro Reimondo
On Fri, Aug 31, 2018 at 7:29 PM, Alejandro Reimondo wrote:
Is it possible to send messages to functions?
I need to extend functions as first-class objects.
With string values the feature is implemented
extending string's metatables.
I coudn´t found a similar way to do it with
 function values.


What does "send messages to functions" mean?

The "__call" metamethod is not applicable to closures, but others ("__pow", "__div", "__index",...) are still available.

Reply | Threaded
Open this post in threaded view
|

Re: Functions as first-class objects

ks_isaf@126.com
In reply to this post by Alejandro Reimondo
> Hi,

> Is it possible to send messages to functions?

> I need to extend functions as first-class objects.

you can use debug.setmetatable to set a metatable for function value.