FFI: Add ffi.typeinfo().

Thanks to Peter Colberg.
This commit is contained in:
Mike Pall 2014-10-08 22:16:53 +02:00
parent d2809bec24
commit d6ff3afc14

View File

@ -559,6 +559,31 @@ LJLIB_CF(ffi_typeof) LJLIB_REC(.)
return 1; return 1;
} }
/* Internal and unsupported API. */
LJLIB_CF(ffi_typeinfo)
{
CTState *cts = ctype_cts(L);
CTypeID id = (CTypeID)ffi_checkint(L, 1);
if (id > 0 && id < cts->top) {
CType *ct = ctype_get(cts, id);
GCtab *t;
lua_createtable(L, 0, 4); /* Increment hash size if fields are added. */
t = tabV(L->top-1);
setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "info")), (int32_t)ct->info);
if (ct->size != CTSIZE_INVALID)
setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "size")), (int32_t)ct->size);
if (ct->sib)
setintV(lj_tab_setstr(L, t, lj_str_newlit(L, "sib")), (int32_t)ct->sib);
if (gcref(ct->name)) {
GCstr *s = gco2str(gcref(ct->name));
setstrV(L, lj_tab_setstr(L, t, lj_str_newlit(L, "name")), s);
}
lj_gc_check(L);
return 1;
}
return 0;
}
LJLIB_CF(ffi_istype) LJLIB_REC(.) LJLIB_CF(ffi_istype) LJLIB_REC(.)
{ {
CTState *cts = ctype_cts(L); CTState *cts = ctype_cts(L);