lua-users home
lua-l archive

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


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 <aleReimondo@smalltalking.net> 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.

--
--