lua-users home
lua-l archive

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


It was thus said that the Great Andrew Starks once stated:
> On Wed, Nov 20, 2013 at 4:14 PM, Steven Johnson
> <steve@xibalbastudios.com> wrote:
> >> While we are on the subject of API functions that would be nice to
> >> have directly from Lua:
> >>
> >> 1. getmetafield(tbl,key)  -- calls luaL_getmetafield.
> >
> > Some time in the ancient past  I seconded this same suggestion. The
> > thinking being that a __metatable key meant you couldn't ask what
> > metamethods something implemented, whereas the intent was probably
> > just to make that thing tamper-proof. This was obviously simple to add
> > when I controlled the environment, but otherwise it's not quite
> > possible to make correct versions of is_callable() et al. without
> > recourse to debug.metatable().
> >
> 
> What do you think about  something like `getudtype(userdatavalue)`,
> where the field name from the registry or something like a __type
> field value would be returned.

  I would propose extending type() such that:

	if type is userdate then
	  if metatable(userdata).__type then
	    return metatable(userdata).__type
	  else
	    return "userdata"
	  end
	end

  -spc