diff options
author | Mike Pall <mike> | 2011-06-11 18:30:22 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2011-06-11 18:30:22 +0200 |
commit | 287de611a209ed0e76be8623968106a2a9f13901 (patch) | |
tree | 991112e86c06349f6432aca228a734ed42a9e86a | |
parent | a58eb604f43d688057ae94f09738863c61a0e5d6 (diff) | |
download | luajit-287de611a209ed0e76be8623968106a2a9f13901.tar.gz luajit-287de611a209ed0e76be8623968106a2a9f13901.tar.bz2 luajit-287de611a209ed0e76be8623968106a2a9f13901.zip |
FFI: Support __tostring metamethod for pointers to structs, too.
-rw-r--r-- | src/lib_ffi.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 99f04aab..582e9bf7 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
@@ -273,7 +273,9 @@ LJLIB_CF(ffi_meta___tostring) | |||
273 | msg = "ctype<%s>"; | 273 | msg = "ctype<%s>"; |
274 | id = *(CTypeID *)p; | 274 | id = *(CTypeID *)p; |
275 | } else { | 275 | } else { |
276 | CType *ct = ctype_raw(ctype_cts(L), id); | 276 | CTState *cts = ctype_cts(L); |
277 | CType *ct = ctype_raw(cts, id); | ||
278 | if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct); | ||
277 | if (ctype_iscomplex(ct->info)) { | 279 | if (ctype_iscomplex(ct->info)) { |
278 | setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size)); | 280 | setstrV(L, L->top-1, lj_ctype_repr_complex(L, cdataptr(cd), ct->size)); |
279 | goto checkgc; | 281 | goto checkgc; |
@@ -281,16 +283,19 @@ LJLIB_CF(ffi_meta___tostring) | |||
281 | setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd), | 283 | setstrV(L, L->top-1, lj_ctype_repr_int64(L, *(uint64_t *)cdataptr(cd), |
282 | (ct->info & CTF_UNSIGNED))); | 284 | (ct->info & CTF_UNSIGNED))); |
283 | goto checkgc; | 285 | goto checkgc; |
284 | } else if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) { | ||
285 | /* Handle ctype __tostring metamethod. */ | ||
286 | CTState *cts = ctype_cts(L); | ||
287 | cTValue *tv = lj_ctype_meta(cts, id, MM_tostring); | ||
288 | if (tv) | ||
289 | return lj_meta_tailcall(L, tv); | ||
290 | } else if (ctype_isptr(ct->info)) { | ||
291 | p = cdata_getptr(p, ct->size); | ||
292 | } else if (ctype_isfunc(ct->info)) { | 286 | } else if (ctype_isfunc(ct->info)) { |
293 | p = *(void **)p; | 287 | p = *(void **)p; |
288 | } else { | ||
289 | if (ctype_isptr(ct->info)) { | ||
290 | p = cdata_getptr(p, ct->size); | ||
291 | ct = ctype_rawchild(cts, ct); | ||
292 | } | ||
293 | if (ctype_isstruct(ct->info) || ctype_isvector(ct->info)) { | ||
294 | /* Handle ctype __tostring metamethod. */ | ||
295 | cTValue *tv = lj_ctype_meta(cts, ctype_typeid(cts, ct), MM_tostring); | ||
296 | if (tv) | ||
297 | return lj_meta_tailcall(L, tv); | ||
298 | } | ||
294 | } | 299 | } |
295 | } | 300 | } |
296 | lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p); | 301 | lj_str_pushf(L, msg, strdata(lj_ctype_repr(L, id, NULL)), p); |