diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-30 11:26:16 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-08-30 11:26:16 -0300 |
commit | f33cda8d6eb1cac5b9042429e85f1096175c7ca5 (patch) | |
tree | fc82b6d637628a489bb68fa8ac6f320334170ace /lobject.h | |
parent | 96f77142374da8a4a7d4e5e8afd559fbaf0430e8 (diff) | |
download | lua-f33cda8d6eb1cac5b9042429e85f1096175c7ca5.tar.gz lua-f33cda8d6eb1cac5b9042429e85f1096175c7ca5.tar.bz2 lua-f33cda8d6eb1cac5b9042429e85f1096175c7ca5.zip |
New macro 'getlstr'
Accesses content and length of a 'TString'.
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -392,7 +392,7 @@ typedef struct TString { | |||
392 | size_t lnglen; /* length for long strings */ | 392 | size_t lnglen; /* length for long strings */ |
393 | struct TString *hnext; /* linked list for hash table */ | 393 | struct TString *hnext; /* linked list for hash table */ |
394 | } u; | 394 | } u; |
395 | char contents[1]; | 395 | char contents[1]; /* string body starts here */ |
396 | } TString; | 396 | } TString; |
397 | 397 | ||
398 | 398 | ||
@@ -401,15 +401,22 @@ typedef struct TString { | |||
401 | ** Get the actual string (array of bytes) from a 'TString'. (Generic | 401 | ** Get the actual string (array of bytes) from a 'TString'. (Generic |
402 | ** version and specialized versions for long and short strings.) | 402 | ** version and specialized versions for long and short strings.) |
403 | */ | 403 | */ |
404 | #define getstr(ts) ((ts)->contents) | ||
405 | #define getlngstr(ts) check_exp((ts)->shrlen == 0xFF, (ts)->contents) | 404 | #define getlngstr(ts) check_exp((ts)->shrlen == 0xFF, (ts)->contents) |
406 | #define getshrstr(ts) check_exp((ts)->shrlen != 0xFF, (ts)->contents) | 405 | #define getshrstr(ts) check_exp((ts)->shrlen != 0xFF, (ts)->contents) |
406 | #define getstr(ts) ((ts)->contents) | ||
407 | 407 | ||
408 | 408 | ||
409 | /* get string length from 'TString *s' */ | 409 | /* get string length from 'TString *s' */ |
410 | #define tsslen(s) \ | 410 | #define tsslen(s) \ |
411 | ((s)->shrlen != 0xFF ? (s)->shrlen : (s)->u.lnglen) | 411 | ((s)->shrlen != 0xFF ? (s)->shrlen : (s)->u.lnglen) |
412 | 412 | ||
413 | /* | ||
414 | ** Get string and length */ | ||
415 | #define getlstr(ts, len) \ | ||
416 | ((ts)->shrlen != 0xFF \ | ||
417 | ? (cast_void(len = (ts)->shrlen), (ts)->contents) \ | ||
418 | : (cast_void(len = (ts)->u.lnglen), (ts)->contents)) | ||
419 | |||
413 | /* }================================================================== */ | 420 | /* }================================================================== */ |
414 | 421 | ||
415 | 422 | ||