]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Add ffi.typeinfo().
authorMike Pall <mike>
Wed, 8 Oct 2014 20:16:53 +0000 (22:16 +0200)
committerMike Pall <mike>
Wed, 8 Oct 2014 20:16:53 +0000 (22:16 +0200)
Thanks to Peter Colberg.

src/lib_ffi.c

index 989fddd3c56c8710fd2643d0ee8587f2bb82f645..bc2339cef9f3063de33bb405a335502609c616e7 100644 (file)
@@ -559,6 +559,31 @@ LJLIB_CF(ffi_typeof)       LJLIB_REC(.)
   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(.)
 {
   CTState *cts = ctype_cts(L);