diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-17 15:01:01 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-17 15:01:01 -0400 |
| commit | de31398fe474d4c53bc1f1078077146ab52dd8d8 (patch) | |
| tree | d91049683c9d556e2dafe7db79ef6cd2620364b1 /compile.c | |
| parent | 2c8aa4ca574cc45c3869544deec33d25e9729928 (diff) | |
Add table:get_or_null(key) for tables with non-null pointer values,
which lets get() keep the non-null return type
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -2358,6 +2358,13 @@ CORD compile(env_t *env, ast_t *ast) CORD_asprintf("%ld", (int64_t)(ast->end - f->text)), ")"); } + } else if (streq(call->name, "get_or_null")) { + if (table->value_type->tag != PointerType) + code_err(ast, "The table method :get_or_null() is only supported for tables whose value type is a pointer, not %T", table->value_type); + CORD self = compile_to_pointer_depth(env, call->self, 0, false); + arg_t *arg_spec = new(arg_t, .name="key", .type=table->key_type); + return CORD_all("Table$get_value_or_default(", self, ", ", compile_type(table->key_type), ", ", compile_type(table->value_type), ", ", + compile_arguments(env, ast, arg_spec, call->args), ", NULL, ", compile_type_info(env, self_value_t), ")"); } else if (streq(call->name, "has")) { CORD self = compile_to_pointer_depth(env, call->self, 0, false); arg_t *arg_spec = new(arg_t, .name="key", .type=table->key_type); |
