]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/level/script.c
(#477) Replace all instances of malloc with nth_alloc
[nothing.git] / src / game / level / script.c
index 1fb0b4a503c816e0f87d1a99846410c3241e9cb4..568337b0cb387b4990525d23a536eedcc8732789 100644 (file)
@@ -9,6 +9,7 @@
 #include "system/error.h"
 #include "system/line_stream.h"
 #include "system/lt.h"
+#include "system/nth_alloc.h"
 #include "ui/console.h"
 
 struct Script
@@ -27,7 +28,7 @@ Script *create_script_from_line_stream(LineStream *line_stream, Level *level)
         return NULL;
     }
 
-    Script *script = PUSH_LT(lt, malloc(sizeof(Script)), free);
+    Script *script = PUSH_LT(lt, nth_alloc(sizeof(Script)), free);
     if (script == NULL) {
         throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
@@ -121,3 +122,11 @@ int script_eval(Script *script, const char *source_code)
 
     return 0;
 }
+
+bool script_has_scope_value(const Script *script, const char *name)
+{
+    return !nil_p(
+        get_scope_value(
+            &script->scope,
+            SYMBOL(script->gc, name)));
+}