Skip to content

Commit

Permalink
Add documentation for new C-API low-level memory functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Apr 8, 2016
1 parent f2fb082 commit 47d2cab
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions docs/api-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@ This will automatically load all other headers too!
#include "sass/context.h"
```

### Deprecated usage

The old API is kept in the source for backward compatibility.
It's deprecated and incompatible with this documentation, use `sass/context.h`!

```C
// deprecated interface
#include "sass/interface.h"
```

## Basic C Example

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

int main() {
puts(libsass_VERSION());
puts(libsass_version());
return 0;
}
```
Expand Down Expand Up @@ -114,6 +104,34 @@ This mirrors very well how `libsass` uses these structures.

Structs can be down-casted to access `context` or `options`!

## Memory handling and life-cycles

We keep memory around for as long as the main [context](api-context.md) object is not destroyed (`sass_delete_context`). LibSass will create copies of most inputs/options beside the main sass code.
You need to allocate and fill that buffer before passing it to LibSass. You may also overtake memory management from libsass for certain return values (i.e. `sass_context_take_output_string`).

```C
// to allocate buffer to be filled
void* sass_alloc_memory(size_t size);
// to allocate a buffer from existing string
char* sass_copy_c_string(const char* str);
// to free overtaken memory when done
void sass_free_memory(void* ptr);
```
## Miscellaneous API functions
```C
// Some convenient string helper function
char* sass_string_unquote (const char* str);
char* sass_string_quote (const char* str, const char quote_mark);
// Resolve a file via the given include paths in the include char* array
char* sass_resolve_file (const char* path, const char* incs[]);
// Get compiled libsass version
const char* libsass_version(void);
```

## Common Pitfalls

**input_path**
Expand Down

0 comments on commit 47d2cab

Please sign in to comment.