Sending mnu

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

Sending mnu

Alejandro Reimondo
Hi,

Where can I read what happens when I send a message to an object

that does not implement the message sent?

e.g. cases like:

         ({123}):messageNotUnderstood()

when I evaluate the expression it is returned

an object... where/why this object comes from? How to know it

has been an dnu (does not undestand) and not an object

returned by a "controlled evaluation"(message undestood)

I have not found an explanation on Lua documentation;

  any reference (to doc or code) will be appreciated.

w/best regards,

Ale



Reply | Threaded
Open this post in threaded view
|

Re: Sending mnu

Gé Weijers
On Mon, Nov 19, 2018 at 11:39 AM Alejandro Reimondo <[hidden email]> wrote:
Hi,

Where can I read what happens when I send a message to an object

that does not implement the message sent?

e.g. cases like:

         ({123}):messageNotUnderstood()

Method calls (object:method()) is a shorthand for two simpler operations: indexing a table and calling a function.

object:method(args) is really:

local m = object["method"]
m(object, args)

Your example code is equivalent to:

local t = {123}
local m = t["messageNotUnderstood"] -- this is nil because the method does not exist
m(t) -- passing the object to the nonexistent 'method'

You end up calling 'nil', which is what the interpreter complains about:

Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> ({123}):messageNotUnderstood()
stdin:1: attempt to call a nil value (method 'messageNotUnderstood')
stack traceback:
stdin:1: in main chunk
[C]: in ?

See section 3.4.10 of the Lua 5.3 manual. "A call v:name(args) is syntactic sugar for v.name(v,args), except that v is evaluated only once."

Hope that clarifies things.

--
--

Reply | Threaded
Open this post in threaded view
|

Re: Sending mnu

Alejandro Reimondo

Thank you I have found that in my case there is no error reported

 (and an object is returned) because there is actually a handler

for calling/evaluating nil.

Your response guided me to found the issue.

best,

Ale



El 19/11/2018 a las 20:34, Gé Weijers escribió:
On Mon, Nov 19, 2018 at 11:39 AM Alejandro Reimondo <[hidden email]> wrote:
Hi,

Where can I read what happens when I send a message to an object

that does not implement the message sent?

e.g. cases like:

         ({123}):messageNotUnderstood()

Method calls (object:method()) is a shorthand for two simpler operations: indexing a table and calling a function.

object:method(args) is really:

local m = object["method"]
m(object, args)

Your example code is equivalent to:

local t = {123}
local m = t["messageNotUnderstood"] -- this is nil because the method does not exist
m(t) -- passing the object to the nonexistent 'method'

You end up calling 'nil', which is what the interpreter complains about:

Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> ({123}):messageNotUnderstood()
stdin:1: attempt to call a nil value (method 'messageNotUnderstood')
stack traceback:
stdin:1: in main chunk
[C]: in ?

See section 3.4.10 of the Lua 5.3 manual. "A call v:name(args) is syntactic sugar for v.name(v,args), except that v is evaluated only once."

Hope that clarifies things.

--
--