Skip to content

Commit 2c2353e

Browse files
committed
Add some missing C-API documentation
1 parent db75db8 commit 2c2353e

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

docs/api-context.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ Sass_C_Import_Callback sass_option_get_importer (struct Sass_Options* options);
249249
// Getters for Context_Option include path array
250250
size_t sass_option_get_include_path_size(struct Sass_Options* options);
251251
const char* sass_option_get_include_path(struct Sass_Options* options, size_t i);
252+
// Plugin paths to load dynamic libraries work the same
253+
size_t sass_option_get_plugin_path_size(struct Sass_Options* options);
254+
const char* sass_option_get_plugin_path(struct Sass_Options* options, size_t i);
252255
253256
// Setters for Context_Option values
254257
void sass_option_set_precision (struct Sass_Options* options, int precision);

docs/api-doc.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Introduction
22

3-
LibSass wouldn't be much good without a way to interface with it. These interface documentations describe the various functions and data structures available to implementers. They are split up over three major components, which have all their own source files (plus some common functionality).
3+
LibSass wouldn't be much good without a way to interface with it. These
4+
interface documentations describe the various functions and data structures
5+
available to implementers. They are split up over three major components, which
6+
have all their own source files (plus some common functionality).
47

58
- [Sass Context](api-context.md) - Trigger and handle the main Sass compilation
69
- [Sass Value](api-value.md) - Exchange values and its format with LibSass
@@ -41,7 +44,12 @@ gcc -Wall version.c -lsass -o version && ./version
4144

4245
## Compiling your code
4346

44-
The most important is your sass file (or string of sass code). With this, you will want to start a LibSass compiler. Here is some pseudocode describing the process. The compiler has two different modes: direct input as a string with `Sass_Data_Context` or LibSass will do file reading for you by using `Sass_File_Context`. See the code for a list of options available [Sass_Options](https://github.com/sass/libsass/blob/36feef0/include/sass/interface.h#L18)
47+
The most important is your sass file (or string of sass code). With this, you
48+
will want to start a LibSass compiler. Here is some pseudocode describing the
49+
process. The compiler has two different modes: direct input as a string with
50+
`Sass_Data_Context` or LibSass will do file reading for you by using
51+
`Sass_File_Context`. See the code for a list of options available
52+
[Sass_Options](https://github.com/sass/libsass/blob/36feef0/include/sass/interface.h#L18)
4553

4654
**Building a file compiler**
4755

@@ -97,7 +105,9 @@ struct Sass_Data_context : Sass_Context;
97105

98106
This mirrors very well how `libsass` uses these structures.
99107

100-
- `Sass_Options` holds everything you feed in before the compilation. It also hosts `input_path` and `output_path` options, because they are used to generate/calculate relative links in source-maps. The `input_path` is shared with `Sass_File_Context`.
108+
- `Sass_Options` holds everything you feed in before the compilation. It also hosts
109+
`input_path` and `output_path` options, because they are used to generate/calculate
110+
relative links in source-maps. The `input_path` is shared with `Sass_File_Context`.
101111
- `Sass_Context` holds all the data returned by the compilation step.
102112
- `Sass_File_Context` is a specific implementation that requires no additional fields
103113
- `Sass_Data_Context` is a specific implementation that adds the `input_source` field
@@ -106,8 +116,11 @@ Structs can be down-casted to access `context` or `options`!
106116

107117
## Memory handling and life-cycles
108118

109-
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.
110-
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`).
119+
We keep memory around for as long as the main [context](api-context.md) object
120+
is not destroyed (`sass_delete_context`). LibSass will create copies of most
121+
inputs/options beside the main sass code. You need to allocate and fill that
122+
buffer before passing it to LibSass. You may also overtake memory management
123+
from libsass for certain return values (i.e. `sass_context_take_output_string`).
111124

112125
```C
113126
// to allocate buffer to be filled
@@ -137,39 +150,62 @@ const char* libsass_language_version(void);
137150

138151
**input_path**
139152

140-
The `input_path` is part of `Sass_Options`, but it also is the main option for `Sass_File_Context`. It is also used to generate relative file links in source-maps. Therefore it is pretty usefull to pass this information if you have a `Sass_Data_Context` and know the original path.
153+
The `input_path` is part of `Sass_Options`, but it also is the main option for
154+
`Sass_File_Context`. It is also used to generate relative file links in source-
155+
maps. Therefore it is pretty usefull to pass this information if you have a
156+
`Sass_Data_Context` and know the original path.
141157

142158
**output_path**
143159

144-
Be aware that `libsass` does not write the output file itself. This option merely exists to give `libsass` the proper information to generate links in source-maps. The file has to be written to the disk by the binding/implementation. If the `output_path` is omitted, `libsass` tries to extrapolate one from the `input_path` by replacing (or adding) the file ending with `.css`.
160+
Be aware that `libsass` does not write the output file itself. This option
161+
merely exists to give `libsass` the proper information to generate links in
162+
source-maps. The file has to be written to the disk by the
163+
binding/implementation. If the `output_path` is omitted, `libsass` tries to
164+
extrapolate one from the `input_path` by replacing (or adding) the file ending
165+
with `.css`.
145166

146167
## Error Codes
147168

148-
The `error_code` is integer value which indicates the type of error that occurred inside the LibSass process. Following is the list of error codes along with the short description:
169+
The `error_code` is integer value which indicates the type of error that
170+
occurred inside the LibSass process. Following is the list of error codes along
171+
with the short description:
149172

150173
* 1: normal errors like parsing or `eval` errors
151174
* 2: bad allocation error (memory error)
152175
* 3: "untranslated" C++ exception (`throw std::exception`)
153176
* 4: legacy string exceptions ( `throw const char*` or `std::string` )
154177
* 5: Some other unknown exception
155178

156-
Although for the API consumer, error codes do not offer much value except indicating whether *any* error occurred during the compilation, it helps debugging the LibSass internal code paths.
179+
Although for the API consumer, error codes do not offer much value except
180+
indicating whether *any* error occurred during the compilation, it helps
181+
debugging the LibSass internal code paths.
157182

158183
## Real-World Implementations
159184

160-
The proof is in the pudding, so we have highlighted a few implementations that should be on par with the latest LibSass interface version. Some of them may not have all features implemented!
185+
The proof is in the pudding, so we have highlighted a few implementations that
186+
should be on par with the latest LibSass interface version. Some of them may not
187+
have all features implemented!
161188

162189
1. [Perl Example](https://github.com/sass/perl-libsass/blob/master/lib/CSS/Sass.xs)
163190
2. [Go Example](http://godoc.org/github.com/wellington/go-libsass#example-Context-Compile)
164191
3. [Node Example](https://github.com/sass/node-sass/blob/master/src/binding.cpp)
165192

166193
## ABI forward compatibility
167194

168-
We use a functional API to make dynamic linking more robust and future compatible. The API is not yet 100% stable, so we do not yet guarantee [ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) forward compatibility. We will do so, once we increase the shared library version above 1.0.
195+
We use a functional API to make dynamic linking more robust and future
196+
compatible. The API is not yet 100% stable, so we do not yet guarantee
197+
[ABI](https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html) forward
198+
compatibility.
169199

170200
## Plugins (experimental)
171201

172-
LibSass can load plugins from directories. Just define `plugin_path` on context options to load all plugins from the given directories. To implement plugins, please consult the [[Wiki-Page for plugins|API-Plugins]].
202+
LibSass can load plugins from directories. Just define `plugin_path` on context
203+
options to load all plugins from the directories. To implement plugins, please
204+
consult the following example implementations.
205+
206+
- https://github.com/mgreter/libsass-glob
207+
- https://github.com/mgreter/libsass-math
208+
- https://github.com/mgreter/libsass-digest
173209

174210
## Internal Structs
175211

docs/api-function.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ typedef union Sass_Value* (*Sass_Function_Fn)
3232
// Creators for sass function list and function descriptors
3333
Sass_Function_List sass_make_function_list (size_t length);
3434
Sass_Function_Entry sass_make_function (const char* signature, Sass_Function_Fn cb, void* cookie);
35+
// In case you need to free them yourself
36+
void sass_delete_function (Sass_Function_Entry entry);
37+
void sass_delete_function_list (Sass_Function_List list);
3538

3639
// Setters and getters for callbacks on function lists
3740
Sass_Function_Entry sass_function_get_list_entry(Sass_Function_List list, size_t pos);

0 commit comments

Comments
 (0)