lua-users home
lua-l archive

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





On 3 October 2013 22:56, Andrew Starks <andrew.starks@trms.com> wrote:
On Thu, Oct 3, 2013 at 2:04 PM, Justin Cormack
<justin@specialbusservice.com> wrote:
> Checking type() is wrong, Lua is a duck typing language.

While Lua just needs a quack, the libraries, including the standard
libraries, that integrate with it aren't. So then, you check type.

Delete the type function from Lua and then tell me how comfortable you
are with using Lua in day-to-day operations... :)

-Andrew


I agree with Justin here for userdata types, in fact a certain library[1] does not even know the types of userdata[2] in C++ which is not so unusual[3]. If you really wanted to check the type then using the debug library seems very very wrong to me; just don't set a __metatable entry to hide it, grab the metatable and check against the type you want.

>It didn't seem right to call int64.tonumber or to
>otherwise perform the math without knowing that I was looking at what
>I was expecting.

Why?
Would int64.tonumber not throw an error for an incorrect type?
Could you not wrap it in pcall?

[1] OOLua
[2] It has no __tostring method either as this would reveal an implementation details and would surprise some users I am sure.
[3] luaL_checkudata which is not used in [1] does not even know the type, it checks to see if it is a certain requested type