Discussion:
Sending mnu
Alejandro Reimondo
2018-11-19 19:39:03 UTC
Permalink
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
Gé Weijers
2018-11-19 23:34:12 UTC
Permalink
On Mon, Nov 19, 2018 at 11:39 AM Alejandro Reimondo <
Post by Alejandro Reimondo
Hi,
Where can I read what happens when I send a message to an object
that does not implement the message sent?
({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
Post by Alejandro Reimondo
({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.
--
--
Gé
Alejandro Reimondo
2018-11-20 00:11:56 UTC
Permalink
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
Post by Gé Weijers
On Mon, Nov 19, 2018 at 11:39 AM Alejandro Reimondo
Hi,
Where can I read what happens when I send a message to an object
that does not implement the message sent?
         ({123}):messageNotUnderstood()
Method calls (object:method()) is a shorthand for two simpler
operations: indexing a table and calling a function.
local m = object["method"]
m(object, args)
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'
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
Post by Alejandro Reimondo
({123}):messageNotUnderstood()
stdin:1: attempt to call a nil value (method 'messageNotUnderstood')
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 <http://v.name>(v,args), except that v is
evaluated only once."
Hope that clarifies things.
--
--
Gé
Continue reading on narkive:
Loading...