Doesn't Lua have something comparable to Ruby's method_missing?
Asked Answered
O

1

5

I seem to recall Lua has something similar to Ruby's method_missing. Or am I remembering incorrectly?

Otway answered 11/10, 2011 at 20:35 Comment(0)
V
8

The __index and __newindex of a table's metatable can be used to the same effect as Ruby's method_missing.

Volney answered 11/10, 2011 at 20:44 Comment(1)
Yes, upon more vigilant googling I found this URL lua.org/pil/13.4.1.html from the Lua manual which states: "when we access an absent field in a table .... such access triggers the interpreter to look for an __index metamethod"Otway

© 2022 - 2024 — McMap. All rights reserved.