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
|
package libs
// #include <string.h>
// #include "sass/context.h"
//
// extern struct Sass_Import** HeaderBridge(int idx);
//
// Sass_Import_List SassHeaders(const char* cur_path, Sass_Importer_Entry cb, struct Sass_Compiler* comp)
// {
// void* cookie = sass_importer_get_cookie(cb);
// int idx = *((int *)cookie);
// Sass_Import_List list = HeaderBridge(idx);
// return list;
//
// }
//
import "C"
import "unsafe"
var globalHeaders SafeMap
func init() {
globalHeaders.init()
}
// BindHeader attaches the header to a libsass context ensuring
// gc does not delete the pointers necessary to make this happen.
func BindHeader(opts SassOptions, entries []ImportEntry) int {
idx := globalHeaders.Set(entries)
// ptr := unsafe.Pointer(idx)
czero := C.double(0)
imper := C.sass_make_importer(
C.Sass_Importer_Fn(C.SassHeaders),
czero,
unsafe.Pointer(idx),
)
impers := C.sass_make_importer_list(1)
C.sass_importer_set_list_entry(impers, 0, imper)
C.sass_option_set_c_headers(
(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
impers)
return *idx
}
func RemoveHeaders(idx int) error {
globalHeaders.Del(idx)
return nil
}
|