diff options
Diffstat (limited to 'lapi.c')
-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 | ||