diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-18 14:28:35 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-18 14:28:35 -0500 |
| commit | 095970170ca3ef4a91970e02494f8056ca47c2c9 (patch) | |
| tree | 93d9de38f0610da4e80b1b2338cbe38f9505ec96 /builtins/table.h | |
| parent | 88261bcbbd92cd78a4c068ae58906e36e26fd02a (diff) | |
Implement indexing
Diffstat (limited to 'builtins/table.h')
| -rw-r--r-- | builtins/table.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/builtins/table.h b/builtins/table.h index 13262bbe..3f93da32 100644 --- a/builtins/table.h +++ b/builtins/table.h @@ -18,6 +18,11 @@ $table.fallback = fb; \ $table.default_value = def; \ $table; }) +#define $Table_get(table_expr, key_t, val_t, key_expr, info_expr) ({ \ + const table_t *$t = table_expr; key_t $k = key_expr; const TypeInfo* $info = info_expr; \ + const val_t *$v = Table_get($t, &$k, $info); \ + if (__builtin_expect($v == NULL, 0)) fail("The key %r is not in this table", generic_as_str(&$k, no, $info->TableInfo.key)); \ + *$v; }) table_t Table_from_entries(array_t entries, const TypeInfo *type); |
