| 1 | ## Example operation.c |
| 2 | |
| 3 | ```C |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include "sass/values.h" |
| 7 | |
| 8 | int main( int argc, const char* argv[] ) |
| 9 | { |
| 10 | |
| 11 | // create two new sass values to be added |
| 12 | union Sass_Value* string = sass_make_string("String"); |
| 13 | union Sass_Value* number = sass_make_number(42, "nits"); |
| 14 | |
| 15 | // invoke the add operation which returns a new sass value |
| 16 | union Sass_Value* total = sass_value_op(ADD, string, number); |
| 17 | |
| 18 | // no further use for the two operands |
| 19 | sass_delete_value(string); |
| 20 | sass_delete_value(number); |
| 21 | |
| 22 | // this works since libsass will always return a |
| 23 | // string for add operations with a string as the |
| 24 | // left hand side. But you should never rely on it! |
| 25 | puts(sass_string_get_value(total)); |
| 26 | |
| 27 | // invoke stringification (uncompressed with precision of 5) |
| 28 | union Sass_Value* result = sass_value_stringify(total, false, 5); |
| 29 | |
| 30 | // no further use for the sum |
| 31 | sass_delete_value(total); |
| 32 | |
| 33 | // print the result - you may want to make |
| 34 | // sure result is indeed a string, although |
| 35 | // stringify guarantees to return a string |
| 36 | // if (sass_value_is_string(result)) {} |
| 37 | // really depends on your level of paranoia |
| 38 | puts(sass_string_get_value(result)); |
| 39 | |
| 40 | // finally free result |
| 41 | sass_delete_value(result); |
| 42 | |
| 43 | // exit status |
| 44 | return 0; |
| 45 | |
| 46 | } |
| 47 | ``` |
| 48 | |
| 49 | ## Compile operation.c |
| 50 | |
| 51 | ```bash |
| 52 | gcc -c operation.c -o operation.o |
| 53 | gcc -o operation operation.o -lsass |
| 54 | ./operation # => String42nits |
| 55 | ``` |