From 0a7062e2d711b5ac7fb71e873f293a8f0d0e8bc6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 1 Sep 2025 12:43:08 -0400 Subject: Improved error messages --- src/stdlib/tables.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/stdlib/tables.h') diff --git a/src/stdlib/tables.h b/src/stdlib/tables.h index 208bf6b2..129aa5ec 100644 --- a/src/stdlib/tables.h +++ b/src/stdlib/tables.h @@ -49,6 +49,18 @@ void *Table$get(Table_t t, const void *key, const TypeInfo_t *type); val_t *nonnull_var = Table$get(t, &k, info_expr); \ nonnull_var ? nonnull_expr : null_expr; \ }) +#define Table$get_checked(table_expr, key_t, val_t, key_expr, start, end, info_expr) \ + ({ \ + const Table_t t = table_expr; \ + const key_t key = key_expr; \ + const TypeInfo_t *info = info_expr; \ + val_t *value = Table$get(t, &key, info); \ + if (unlikely(value == NULL)) \ + fail_source(__SOURCE_FILE__, start, end, \ + "This key was not found in the table: ", generic_as_text(&key, false, info->TableInfo.key), \ + "\n"); \ + *value; \ + }) #define Table$get_or_setdefault(table_expr, key_t, val_t, key_expr, default_expr, info_expr) \ ({ \ Table_t *t = table_expr; \ -- cgit v1.2.3