diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 13:16:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 13:16:53 -0300 |
commit | cf71a5ddc742692fad813f89f1c9ef53e1ffde0f (patch) | |
tree | df02305ff3cf05908f21829384e3a7f8699d2331 /lapi.c | |
parent | 2c32bff60987d38a60a58d4f0123f3783da60a63 (diff) | |
download | lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.tar.gz lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.tar.bz2 lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.zip |
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)
Diffstat (limited to '')
-rw-r--r-- | lapi.c | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -414,8 +414,7 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) { | |||
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | LUA_API void *lua_touserdata (lua_State *L, int idx) { | 417 | static void *touserdata (const TValue *o) { |
418 | const TValue *o = index2value(L, idx); | ||
419 | switch (ttype(o)) { | 418 | switch (ttype(o)) { |
420 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); | 419 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); |
421 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 420 | case LUA_TLIGHTUSERDATA: return pvalue(o); |
@@ -424,23 +423,37 @@ LUA_API void *lua_touserdata (lua_State *L, int idx) { | |||
424 | } | 423 | } |
425 | 424 | ||
426 | 425 | ||
426 | LUA_API void *lua_touserdata (lua_State *L, int idx) { | ||
427 | const TValue *o = index2value(L, idx); | ||
428 | return touserdata(o); | ||
429 | } | ||
430 | |||
431 | |||
427 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { | 432 | LUA_API lua_State *lua_tothread (lua_State *L, int idx) { |
428 | const TValue *o = index2value(L, idx); | 433 | const TValue *o = index2value(L, idx); |
429 | return (!ttisthread(o)) ? NULL : thvalue(o); | 434 | return (!ttisthread(o)) ? NULL : thvalue(o); |
430 | } | 435 | } |
431 | 436 | ||
432 | 437 | ||
438 | /* | ||
439 | ** Returns a pointer to the internal representation of an object. | ||
440 | ** Note that ANSI C does not allow the conversion of a pointer to | ||
441 | ** function to a 'void*', so the conversion here goes through | ||
442 | ** a 'size_t'. (As the returned pointer is only informative, this | ||
443 | ** conversion should not be a problem.) | ||
444 | */ | ||
433 | LUA_API const void *lua_topointer (lua_State *L, int idx) { | 445 | LUA_API const void *lua_topointer (lua_State *L, int idx) { |
434 | const TValue *o = index2value(L, idx); | 446 | const TValue *o = index2value(L, idx); |
435 | switch (ttypetag(o)) { | 447 | switch (ttypetag(o)) { |
436 | case LUA_TTABLE: return hvalue(o); | ||
437 | case LUA_TLCL: return clLvalue(o); | ||
438 | case LUA_TCCL: return clCvalue(o); | ||
439 | case LUA_TLCF: return cast_voidp(cast_sizet(fvalue(o))); | 448 | case LUA_TLCF: return cast_voidp(cast_sizet(fvalue(o))); |
440 | case LUA_TTHREAD: return thvalue(o); | 449 | case LUA_TUSERDATA: case LUA_TLIGHTUSERDATA: |
441 | case LUA_TUSERDATA: return getudatamem(uvalue(o)); | 450 | return touserdata(o); |
442 | case LUA_TLIGHTUSERDATA: return pvalue(o); | 451 | default: { |
443 | default: return NULL; | 452 | if (iscollectable(o)) |
453 | return gcvalue(o); | ||
454 | else | ||
455 | return NULL; | ||
456 | } | ||
444 | } | 457 | } |
445 | } | 458 | } |
446 | 459 | ||