From: Lukas Krickl Date: Sat, 21 Mar 2026 17:17:57 +0000 (+0100) Subject: script: Added getters for values and value type X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=HEAD;p=lrts%2F.git script: Added getters for values and value type --- diff --git a/src/l_lsl.c b/src/l_lsl.c index fc67249..bb61de1 100644 --- a/src/l_lsl.c +++ b/src/l_lsl.c @@ -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'; } diff --git a/src/l_lsl.h b/src/l_lsl.h index 64da415..7ef43da 100644 --- a/src/l_lsl.h +++ b/src/l_lsl.h @@ -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 diff --git a/src/tests/t_lsl.c b/src/tests/t_lsl.c index ddbb4e1..6675df6 100644 --- a/src/tests/t_lsl.c +++ b/src/tests/t_lsl.c @@ -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;