diff options
author | Mike Pall <mike> | 2014-10-08 22:16:53 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2014-10-08 22:16:53 +0200 |
commit | d6ff3afc14eb3580c1aa7985431fa152b135d4c5 (patch) | |
tree | a6271b131c04207489695989e8daa7f09db8d389 | |
parent | d2809bec24a7c6a6ec38d3e658c34131adc0de5a (diff) | |
download | luajit-d6ff3afc14eb3580c1aa7985431fa152b135d4c5.tar.gz luajit-d6ff3afc14eb3580c1aa7985431fa152b135d4c5.tar.bz2 luajit-d6ff3afc14eb3580c1aa7985431fa152b135d4c5.zip |
FFI: Add ffi.typeinfo().
Thanks to Peter Colberg.
-rw-r--r-- | src/lib_ffi.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 989fddd3..bc2339ce 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
@@ -559,6 +559,31 @@ LJLIB_CF(ffi_typeof) LJLIB_REC(.) | |||
559 | return 1; | 559 | return 1; |
560 | } | 560 | } |
561 | 561 | ||
562 | /* Internal and unsupported API. */ | ||
563 | LJLIB_CF(ffi_typeinfo) | ||
564 | { | ||
565 | CTState *cts = ctype_cts(L); | ||
566 | CTypeID id = (CTypeID)ffi_checkint(L, 1); | ||
567 | if (id > 0 && id < cts->top) { | ||
568 | CType *ct = ctype_get(cts, id); | ||
569 | GCtab *t; | ||
570 | lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */ | ||
571 | t = tabV(L->top-1); | ||
572 | setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "info")), (int32_t)ct->info); | ||
573 | if (ct->size != CTSIZE_INVALID) | ||
574 | setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "size")), (int32_t)ct->size); | ||
575 | if (ct->sib) | ||
576 | setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "sib")), (int32_t)ct->sib); | ||
577 | if (gcref(ct->name)) { | ||
578 | GCstr *s = gco2str(gcref(ct->name)); | ||
579 | setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "name")), s); | ||
580 | } | ||
581 | lj_gc_check(L); | ||
582 | return 1; | ||
583 | } | ||
584 | return 0; | ||
585 | } | ||
586 | |||
562 | LJLIB_CF(ffi_istype) LJLIB_REC(.) | 587 | LJLIB_CF(ffi_istype) LJLIB_REC(.) |
563 | { | 588 | { |
564 | CTState *cts = ctype_cts(L); | 589 | CTState *cts = ctype_cts(L); |