lua-users home
lua-l archive

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




On Thursday, October 3, 2013, liam mail wrote:



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.

I'm speaking as a user on the Lua side that is consuming a userdata value that is playing the role of a value that might be added to or concatenated or otherwise interact with other values.  


>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?


I believe that I answered this in my post. pcall is fine, except if I want to perform some kind of logic, based on if I have an "int64" data type or a "real" datatype. Do I then parse the error string, looking for some hint as to what I've got, via the string matching library?

[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