lua-users home
lua-l archive

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

On Mon, Nov 19, 2018 at 11:39 AM Alejandro Reimondo <> wrote:

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:


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, 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,args), except that v is evaluated only once."

Hope that clarifies things.