diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib_ffi.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 24a6625c..69bebefc 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
@@ -323,6 +323,30 @@ checkgc: | |||
323 | return 1; | 323 | return 1; |
324 | } | 324 | } |
325 | 325 | ||
326 | static int ffi_pairs(lua_State *L, MMS mm) | ||
327 | { | ||
328 | CTState *cts = ctype_cts(L); | ||
329 | CTypeID id = ffi_checkcdata(L, 1)->ctypeid; | ||
330 | CType *ct = ctype_raw(cts, id); | ||
331 | cTValue *tv; | ||
332 | if (ctype_isptr(ct->info)) id = ctype_cid(ct->info); | ||
333 | tv = lj_ctype_meta(cts, id, mm); | ||
334 | if (!tv) | ||
335 | lj_err_callerv(L, LJ_ERR_FFI_BADMM, strdata(lj_ctype_repr(L, id, NULL)), | ||
336 | strdata(mmname_str(G(L), mm))); | ||
337 | return lj_meta_tailcall(L, tv); | ||
338 | } | ||
339 | |||
340 | LJLIB_CF(ffi_meta___pairs) | ||
341 | { | ||
342 | return ffi_pairs(L, MM_pairs); | ||
343 | } | ||
344 | |||
345 | LJLIB_CF(ffi_meta___ipairs) | ||
346 | { | ||
347 | return ffi_pairs(L, MM_ipairs); | ||
348 | } | ||
349 | |||
326 | LJLIB_PUSH("ffi") LJLIB_SET(__metatable) | 350 | LJLIB_PUSH("ffi") LJLIB_SET(__metatable) |
327 | 351 | ||
328 | #include "lj_libdef.h" | 352 | #include "lj_libdef.h" |