script: Added getters for values and value type master origin/HEAD origin/master
authorLukas Krickl <lukas@krickl.dev>
Sat, 21 Mar 2026 17:17:57 +0000 (18:17 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 21 Mar 2026 17:17:57 +0000 (18:17 +0100)
src/l_lsl.c
src/l_lsl.h
src/tests/t_lsl.c

index fc672494ac26ca8d0c539d7fe3b1ce5355673b03..bb61de176a95fe97cad38788005638436dc96c33 100644 (file)
@@ -54,6 +54,20 @@ struct l_lsl_value l_lsl_value_init(void) {
        return val;
 }
 
+enum l_lsl_data_type l_lsl_value_rtype(struct l_lsl_value *v) {
+       return v->type;
+}
+
+char *l_lsl_value_rstr(struct l_lsl_value *v) {
+       return v->data.str_val;
+}
+
+i32 l_lsl_value_rint(struct l_lsl_value *v) {
+       return v->data.int_val;
+}
+
+
+
 lrts_bool l_lsl_isnum(char c) {
        return c >= '0' && c <= '9';
 }
index 64da41506a2283d3c716b6ec222180f3e18deca3..7ef43daef4dd767ba92d0468cc164fe0af9cfe49 100644 (file)
@@ -118,6 +118,19 @@ struct l_lsl_value* l_lsl_value_alloc(struct l_lsl_vm *v);
 void l_lsl_value_free(struct l_lsl_vm *v, 
                struct l_lsl_value *val);
 
+/* value io */
+
+/* gets the type of a value */
+enum l_lsl_data_type l_lsl_value_rtype(struct l_lsl_value *v);
+
+/* reads string value of a value
+ * beware no type checking is performed */
+char *l_lsl_value_rstr(struct l_lsl_value *v);
+
+/* reads the int value of a value
+ * beware no type checking is performed */
+i32 l_lsl_value_rint(struct l_lsl_value *v);
+
 /* 
  * gets the next token returns tone's length in token_len
  * the result token is placed into an internal string buffer and should not be modified 
index ddbb4e1d2591301facf7d4d9f7690154e06386f3..6675df6d3589049a160f6dfb246f05f345fd9431 100644 (file)
@@ -5,7 +5,9 @@ typedef int (*t_lsl_value_assert)(struct l_lsl_value *expected,
 
 int t_lsl_vlue_assert_int(struct l_lsl_value *expected, 
                struct l_lsl_value *actual) {
-       T_ASSERT(expected->data.int_val == actual->data.int_val, 
+       T_ASSERT(
+                       l_lsl_value_rint(expected) 
+                               == l_lsl_value_rint(actual), 
                        ("Unexpected int value. Expected %d got %d\n", expected->data.int_val,
                         actual->data.int_val));
 
@@ -14,7 +16,9 @@ int t_lsl_vlue_assert_int(struct l_lsl_value *expected,
 
 int t_lsl_vlue_assert_str(struct l_lsl_value *expected, 
                struct l_lsl_value *actual) {
-       T_ASSERT(u_strncmp(expected->data.str_val, actual->data.str_val, 256) == 0, 
+       T_ASSERT(u_strncmp(
+                               l_lsl_value_rstr(expected), 
+                               l_lsl_value_rstr(actual), 256) == 0, 
                        ("Unexpected str value. Expected '%s' got '%s'\n", expected->data.str_val,
                         actual->data.str_val));
 
@@ -41,7 +45,8 @@ int t_lsl_assert(struct l_lsl_value expect_value, enum l_lsl_error expect_err,
                return 0;
        }
        T_ASSERT(res != LRTS_NULL, ("Invalid result value\n"))
-       T_ASSERT(res->type == expect_value.type, ("Unexpected return value\n"));
+       T_ASSERT(l_lsl_value_rtype(res) == l_lsl_value_rtype(&expect_value), 
+                       ("Unexpected return value\n"));
 
        if (assert_val(&expect_value, res) != 0) {
                return 1;