lua-users home
lua-l archive

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



On Jan 29, 2014, at 4:12 AM, John Hind <john.hind@zen.co.uk> wrote:

1. Deprecate luaL_typename.

Reason: it is too easy to write 'name = luaL_typename(L, lua_type(L, 1));'
when you mean 'name = lua_typename(L, lua_type(L, 1));' or 'name =
luaL_typename(L, 1);' and get a very subtle and hard to find bug!

Discussion: why does lua_typename need the state parameter? It is just a
constant lookup. It is not for consistency, because lua_upvalueindex already
breaks the rule that the first parameter is always the state. If
lua_typename did not take the state then luaL_typename would be safe because
the compiler would catch the error.

I think deprecating an API because of this confusion is a bit harsh (especially as I use both in my code!). However I agree that the names and signatures are too close for comfort. Maybe “luaL_valuetypename()” ???

—Tim