]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level_script.c
Add TODO(#521)
[nothing.git] / src / game / level_script.c
index 52b373bc400dd85028c7daa071141b1e8da201ed..7d3fbcfc5d72dee3dc359bc57daca30b4cd100e3 100644 (file)
@@ -8,75 +8,6 @@
 #include "level_script.h"
 #include "system/log.h"
 
-/* unpack_args(gc, 3, (1, 2), &x, &y, &z) */
-/* unpack_args(gc, "dsd", (1, 2), &x, &y, &z) */
-
-static struct EvalResult
-unpack_args(struct Gc *gc, const char *format, struct Expr args, ...)
-{
-    va_list args_list;
-    va_start(args_list, args);
-
-    if (!list_p(args)) {
-        va_end(args_list);
-        return wrong_argument_type(gc, "listp", args);
-    }
-
-    long int i = 0;
-    for (i = 0; *format != 0 && !nil_p(args); ++i) {
-        struct Expr arg = CAR(args);
-        args = CDR(args);
-
-        switch (*format) {
-        case 'd': {
-            if (!number_p(arg)) {
-                va_end(args_list);
-                return wrong_argument_type(gc, "numberp", arg);
-            }
-
-            long int *p = va_arg(args_list, long int *);
-            *p = arg.atom->num;
-        } break;
-
-        case 's': {
-            if (!string_p(arg)) {
-                va_end(args_list);
-                return wrong_argument_type(gc, "stringp", arg);
-            }
-
-            const char **p = va_arg(args_list, const char**);
-            *p = arg.atom->str;
-        } break;
-
-        case 'q': {
-            if (!symbol_p(arg)) {
-                va_end(args_list);
-                return wrong_argument_type(gc, "symbolp", arg);
-            }
-
-            const char **p = va_arg(args_list, const char**);
-            *p = arg.atom->sym;
-        } break;
-
-        case 'e': {
-            struct Expr *p = va_arg(args_list, struct Expr*);
-            *p = arg;
-        } break;
-        }
-
-        format++;
-    }
-
-    if (!nil_p(args)) {
-        return eval_failure(
-            CONS(gc,
-                 SYMBOL(gc, "wrong-number-of-arguments"),
-                 NUMBER(gc, i)));
-    }
-
-    return eval_success(NIL(gc));
-}
-
 struct EvalResult
 hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
 {
@@ -84,25 +15,14 @@ hide_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
     assert(gc);
     assert(scope);
 
-    /* TODO(#507): Manually parsing args of native functions is tedious. */
-    if (!list_p(args)) {
-        return wrong_argument_type(gc, "listp", args);
-    }
-
-    if (length_of_list(args) != 1) {
-        return eval_failure(
-            CONS(gc,
-                 SYMBOL(gc, "wrong-number-of-arguments"),
-                 NUMBER(gc, length_of_list(args))));
-    }
+    Level * const level = (Level*)param;
+    const char * const goal_id = NULL;
 
-    if (!string_p(CAR(args))) {
-        return wrong_argument_type(gc, "stringp", args);
+    struct EvalResult result = unpack_args(gc, "s", args, &goal_id);
+    if (result.is_error) {
+        return result;
     }
 
-    const char * const goal_id = CAR(args).atom->str;
-    Level * const level = (Level*)param;
-
     level_hide_goal(level, goal_id);
 
     return eval_success(NIL(gc));
@@ -115,21 +35,14 @@ show_goal(void *param, Gc *gc, struct Scope *scope, struct Expr args)
     assert(gc);
     assert(scope);
 
-    if (!list_p(args)) {
-        return wrong_argument_type(gc, "listp", args);
-    }
-
-    if (length_of_list(args) != 1) {
-        return wrong_number_of_arguments(gc, length_of_list(args));
-    }
+    Level * const level = (Level*)param;
+    const char *goal_id = NULL;
 
-    if (!string_p(CAR(args))) {
-        return wrong_argument_type(gc, "stringp", args);
+    struct EvalResult result = unpack_args(gc, "s", args, &goal_id);
+    if (result.is_error) {
+        return result;
     }
 
-    const char * const goal_id = CAR(args).atom->str;
-    Level * const level = (Level*)param;
-
     level_show_goal(level, goal_id);
 
     return eval_success(NIL(gc));
@@ -163,6 +76,45 @@ struct EvalResult rect_apply_force(void *param, Gc *gc, struct Scope *scope, str
     return eval_success(NIL(gc));
 }
 
+struct EvalResult
+hide_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
+{
+    assert(param);
+    assert(gc);
+    assert(scope);
+    (void) args;
+
+    /* TODO: hide-label is not implemented */
+
+    return not_implemented(gc);
+}
+
+struct EvalResult
+show_label(void *param, Gc *gc, struct Scope *scope, struct Expr args)
+{
+    assert(param);
+    assert(gc);
+    assert(scope);
+    (void) args;
+
+    /* TODO: show-label is not implemented */
+
+    return not_implemented(gc);
+}
+
+struct EvalResult
+get_player_jump_count(void *param, Gc *gc, struct Scope *scope, struct Expr args)
+{
+    assert(param);
+    assert(gc);
+    assert(scope);
+    (void) args;
+
+    /* TODO: get-player-jump-count is not implemented */
+
+    return not_implemented(gc);
+}
+
 void load_level_library(Gc *gc, struct Scope *scope, Level *level)
 {
     set_scope_value(
@@ -180,4 +132,19 @@ void load_level_library(Gc *gc, struct Scope *scope, Level *level)
         scope,
         SYMBOL(gc, "show-goal"),
         NATIVE(gc, show_goal, level));
+    set_scope_value(
+        gc,
+        scope,
+        SYMBOL(gc, "show-label"),
+        NATIVE(gc, show_label, level));
+    set_scope_value(
+        gc,
+        scope,
+        SYMBOL(gc, "hide-label"),
+        NATIVE(gc, hide_label, level));
+    set_scope_value(
+        gc,
+        scope,
+        SYMBOL(gc, "get-player-jump-count"),
+        NATIVE(gc, get_player_jump_count, level));
 }