File: api-value-example.md

package info (click to toggle)
golang-github-bep-golibsass 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,808 kB
  • sloc: cpp: 30,398; ansic: 848; sh: 662; makefile: 340; perl: 56
file content (55 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Example operation.c

```C
#include <stdio.h>
#include <string.h>
#include "sass/values.h"

int main( int argc, const char* argv[] )
{

  // create two new sass values to be added
  union Sass_Value* string = sass_make_string("String");
  union Sass_Value* number = sass_make_number(42, "nits");

  // invoke the add operation which returns a new sass value
  union Sass_Value* total = sass_value_op(ADD, string, number);

  // no further use for the two operands
  sass_delete_value(string);
  sass_delete_value(number);

  // this works since libsass will always return a
  // string for add operations with a string as the
  // left hand side. But you should never rely on it!
  puts(sass_string_get_value(total));

  // invoke stringification (uncompressed with precision of 5)
  union Sass_Value* result = sass_value_stringify(total, false, 5);

  // no further use for the sum
  sass_delete_value(total);

  // print the result - you may want to make
  // sure result is indeed a string, although
  // stringify guarantees to return a string
  // if (sass_value_is_string(result)) {}
  // really depends on your level of paranoia
  puts(sass_string_get_value(result));

  // finally free result
  sass_delete_value(result);

  // exit status
  return 0;

}
```

## Compile operation.c

```bash
gcc -c operation.c -o operation.o
gcc -o operation operation.o -lsass
./operation # => String42nits
```