commit 8265ca6

uint  ·  2026-10-24 19:06:11 +0000 UTC
parent f2cebb7
Remove register_native
1 files changed,  +16, -28
M expl.c
M expl.c
+16, -28
 1@@ -66,7 +66,6 @@ static expl_value eval(expression* n, environment** env);
 2 static expl_value eval_call(expression* args, environment** env);
 3 static expl_value eval_fn(expression* args, environment** env);
 4 static expl_value eval_user(function* f, int argc, expl_value* argv, environment** env);
 5-static int register_native(environment** env, const char* name, expl_native fn, void* data);
 6 
 7 static void skip_space(parser* p);
 8 static char* _strndup(const char* src, size_t len);
 9@@ -392,31 +391,6 @@ eval_user(function* f, int argc, expl_value* argv, environment** env)
10 	return result;
11 }
12 
13-static int
14-register_native(environment** env, const char* name, expl_native fn, void* data)
15-{
16-	function* f = malloc(sizeof(*f));
17-	expl_value value = { 0 };
18-
19-	if (!f)
20-		return 0;
21-
22-	f->native = fn;
23-	f->args = NULL;
24-	f->body = NULL;
25-	f->data = data;
26-
27-	value.type = EXPL_VALUE_FUNCTION;
28-	value.as.function = f;
29-
30-	if (!define(env, name, value)) {
31-		free(f);
32-		return 0;
33-	}
34-
35-	return 1;
36-}
37-
38 static void
39 skip_space(parser* p)
40 {
41@@ -533,10 +507,24 @@ void expl_close(expl* ctx)
42 int
43 expl_register(expl* ctx, const char* name, expl_native fn, void* data)
44 {
45-	if (!ctx || !name || !fn)
46+	function* f = calloc(1, sizeof(*f));
47+	expl_value value = { 0 };
48+
49+	if (!f || !ctx || !name || !fn)
50+		return 0;
51+
52+	f->native = fn;
53+	f->data = data;
54+
55+	value.type = EXPL_VALUE_FUNCTION;
56+	value.as.function = f;
57+
58+	if (!define(&ctx->env, name, value)) {
59+		free(f);
60 		return 0;
61+	}
62 
63-	return register_native(&ctx->env, name, fn, data);
64+	return 1;
65 }
66 
67 expl_value