[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ipairs in Lua 5.3.0-alpha
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 5 Aug 2014 07:53:21 -0300
> 3) I wish __call were respected if you give the function type a
> metatable, and basic C operations were exposed to Lua, like
> getmetatable(0).__add = <C function to add 2 numbers>
A central point in Lua semantics is that metamethods correspond to
events that Lua cannot handle. (Metamethods were originally called
fallbacks, for this reason.) Addition of two numbers is not such an
event and it is never performed via a metamethod, even if you define one:
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> debug.setmetatable(0,{__add=print})
> a=1
> b=2
> =a+b
3
... but this works:
> debug.setmetatable(0,{__call=print})
> a(10,20,30)
1 10 20 30