1
- ` Sass_Values ` are used to pass values and their types between the implementer and LibSass. Sass knows various different value types (including nested arrays and hash-maps). If you implement a binding to another programming language, you have to find a way to convert ` Sass_Values ` between the targeted language and C. ` Sass_Values ` are currently only used by custom functions.
1
+ ` Sass_Values ` are used to pass values and their types between the implementer
2
+ and LibSass. Sass knows various different value types (including nested arrays
3
+ and hash-maps). If you implement a binding to another programming language, you
4
+ have to find a way to [ marshal] [ 1] (convert) ` Sass_Values ` between the target
5
+ language and C. ` Sass_Values ` are currently only used by custom functions, but
6
+ it should also be possible to use them without a compiler context.
7
+
8
+ [ 1 ] : https://en.wikipedia.org/wiki/Marshalling_%28computer_science%29
2
9
3
10
### Basic Usage
4
11
@@ -23,7 +30,18 @@ enum Sass_Tag {
23
30
// Tags for denoting Sass list separators
24
31
enum Sass_Separator {
25
32
SASS_COMMA,
26
- SASS_SPACE
33
+ SASS_SPACE,
34
+ // only used internally to represent a hash map before evaluation
35
+ // otherwise we would be too early to check for duplicate keys
36
+ SASS_HASH
37
+ };
38
+
39
+ // Value Operators
40
+ enum Sass_OP {
41
+ AND, OR, // logical connectives
42
+ EQ, NEQ, GT, GTE, LT, LTE, // arithmetic relations
43
+ ADD, SUB, MUL, DIV, MOD, // arithmetic functions
44
+ NUM_OPS // so we know how big to make the op table
27
45
};
28
46
```
29
47
@@ -33,6 +51,32 @@ enum Sass_Separator {
33
51
// Forward declaration
34
52
union Sass_Value;
35
53
54
+ // Creator functions for all value types
55
+ union Sass_Value* sass_make_null (void);
56
+ union Sass_Value* sass_make_boolean (bool val);
57
+ union Sass_Value* sass_make_string (const char* val);
58
+ union Sass_Value* sass_make_qstring (const char* val);
59
+ union Sass_Value* sass_make_number (double val, const char* unit);
60
+ union Sass_Value* sass_make_color (double r, double g, double b, double a);
61
+ union Sass_Value* sass_make_list (size_t len, enum Sass_Separator sep);
62
+ union Sass_Value* sass_make_map (size_t len);
63
+ union Sass_Value* sass_make_error (const char* msg);
64
+ union Sass_Value* sass_make_warning (const char* msg);
65
+
66
+ // Generic destructor function for all types
67
+ // Will release memory of all associated Sass_Values
68
+ // Means we will delete recursively for lists and maps
69
+ void sass_delete_value (union Sass_Value* val);
70
+
71
+ // Make a deep cloned copy of the given sass value
72
+ union Sass_Value* sass_clone_value (const union Sass_Value* val);
73
+
74
+ // Stringify a Sass_Values and also return the result as a Sass_Value (of type STRING)
75
+ union Sass_Value* sass_value_stringify (const union Sass_Value* a, bool compressed, int precision);
76
+
77
+ // Execute an operation for two Sass_Values and return the result as a Sass_Value too
78
+ union Sass_Value* sass_value_op (enum Sass_OP op, const union Sass_Value* a, const union Sass_Value* b);
79
+
36
80
// Return the sass tag for a generic sass value
37
81
// Check is needed before accessing specific values!
38
82
enum Sass_Tag sass_value_get_tag (const union Sass_Value* v);
@@ -58,6 +102,8 @@ void sass_number_set_unit (union Sass_Value* v, char* unit);
58
102
// Getters and setters for Sass_String
59
103
const char* sass_string_get_value (const union Sass_Value* v);
60
104
void sass_string_set_value (union Sass_Value* v, char* value);
105
+ bool sass_string_is_quoted(const union Sass_Value* v);
106
+ void sass_string_set_quoted(union Sass_Value* v, bool quoted);
61
107
62
108
// Getters and setters for Sass_Boolean
63
109
bool sass_boolean_get_value (const union Sass_Value* v);
@@ -84,7 +130,7 @@ void sass_list_set_value (union Sass_Value* v, size_t i, union Sass_Value* value
84
130
85
131
// Getter for the number of items in map
86
132
size_t sass_map_get_length (const union Sass_Value* v);
87
- // Getters and setters for Sass_List keys and values
133
+ // Getters and setters for Sass_Map keys and values
88
134
union Sass_Value* sass_map_get_key (const union Sass_Value* v, size_t i);
89
135
void sass_map_set_key (union Sass_Value* v, size_t i, union Sass_Value* );
90
136
union Sass_Value* sass_map_get_value (const union Sass_Value* v, size_t i);
@@ -97,25 +143,6 @@ void sass_error_set_message (union Sass_Value* v, char* msg);
97
143
// Getters and setters for Sass_Warning
98
144
char* sass_warning_get_message (const union Sass_Value* v);
99
145
void sass_warning_set_message (union Sass_Value* v, char* msg);
100
-
101
- // Creator functions for all value types
102
- union Sass_Value* sass_make_null (void);
103
- union Sass_Value* sass_make_boolean (bool val);
104
- union Sass_Value* sass_make_string (const char* val);
105
- union Sass_Value* sass_make_number (double val, const char* unit);
106
- union Sass_Value* sass_make_color (double r, double g, double b, double a);
107
- union Sass_Value* sass_make_list (size_t len, enum Sass_Separator sep);
108
- union Sass_Value* sass_make_map (size_t len);
109
- union Sass_Value* sass_make_error (const char* msg);
110
- union Sass_Value* sass_make_warning (const char* msg);
111
-
112
- // Generic destructor function for all types
113
- // Will release memory of all associated Sass_Values
114
- // Means we will delete recursively for lists and maps
115
- void sass_delete_value (union Sass_Value* val);
116
-
117
- // Make a deep cloned copy of the given sass value
118
- union Sass_Value* sass_clone_value (const union Sass_Value* val);
119
146
```
120
147
121
148
### More links
0 commit comments