Details
Several small improvements (code style, warnings, comments, more tests),
in particular:
- 'lua_topointer' extended to handle strings
- raises an error in 'string.format("%10q")' ('%q' with modifiers)
- in the manual for 'string.format', the term "option" replaced by
"conversion specifier" (the term used by the C standard)
This commit is contained in:
31
lapi.c
31
lapi.c
@@ -414,8 +414,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
|
||||
}
|
||||
|
||||
|
||||
LUA_API void *lua_touserdata (lua_State *L, int idx) {
|
||||
const TValue *o = index2value(L, idx);
|
||||
static void *touserdata (const TValue *o) {
|
||||
switch (ttype(o)) {
|
||||
case LUA_TUSERDATA: return getudatamem(uvalue(o));
|
||||
case LUA_TLIGHTUSERDATA: return pvalue(o);
|
||||
@@ -424,23 +423,37 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) {
|
||||
}
|
||||
|
||||
|
||||
LUA_API void *lua_touserdata (lua_State *L, int idx) {
|
||||
const TValue *o = index2value(L, idx);
|
||||
return touserdata(o);
|
||||
}
|
||||
|
||||
|
||||
LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
|
||||
const TValue *o = index2value(L, idx);
|
||||
return (!ttisthread(o)) ? NULL : thvalue(o);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Returns a pointer to the internal representation of an object.
|
||||
** Note that ANSI C does not allow the conversion of a pointer to
|
||||
** function to a 'void*', so the conversion here goes through
|
||||
** a 'size_t'. (As the returned pointer is only informative, this
|
||||
** conversion should not be a problem.)
|
||||
*/
|
||||
LUA_API const void *lua_topointer (lua_State *L, int idx) {
|
||||
const TValue *o = index2value(L, idx);
|
||||
switch (ttypetag(o)) {
|
||||
case LUA_TTABLE: return hvalue(o);
|
||||
case LUA_TLCL: return clLvalue(o);
|
||||
case LUA_TCCL: return clCvalue(o);
|
||||
case LUA_TLCF: return cast_voidp(cast_sizet(fvalue(o)));
|
||||
case LUA_TTHREAD: return thvalue(o);
|
||||
case LUA_TUSERDATA: return getudatamem(uvalue(o));
|
||||
case LUA_TLIGHTUSERDATA: return pvalue(o);
|
||||
default: return NULL;
|
||||
case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA:
|
||||
return touserdata(o);
|
||||
default: {
|
||||
if (iscollectable(o))
|
||||
return gcvalue(o);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user