lua-users home
lua-l archive

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


In the faraway future, in whatever version of lua comes next:
It'd be nice if lua_topointer was exposed to lua code.
This would allow for users to get a unique value corresponding to a
given object.

Use cases:
  - __tostring metamethods that have previously needed a `rawtostring`
        (usually painstakingly created by removing the metatable and
then replacing it)
  - common value for comparison by e.g. table.sort

Proposed implementation:

static int db_topointer (lua_State *L) {
  luaL_checkany(L, 1);
  void *p = lua_topointer(L, 1);
  if (p == NULL)
    lua_pushnil(L);
  else
    lua_pushlightuserdata(L, p);
  return 1;
}