File: export.go

package info (click to toggle)
golang-github-wellington-go-libsass 0.9.2%2Bgit20181130.4ef5b9d-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,128 kB
  • sloc: cpp: 28,607; ansic: 839; makefile: 44
file content (45 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (2)
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
package libs

// #include "sass/context.h"
//
import "C"
import (
	"fmt"
	"sync"
)

// SassCallback defines the callback libsass eventually executes in
// sprite_sass
type SassCallback func(v interface{}, csv UnionSassValue, rsv *UnionSassValue) error

// Cookie is used for passing context information to libsass.  Cookie is
// passed to custom handlers when libsass executes them through the go
// bridge.
type Cookie struct {
	Sign string
	Fn   SassCallback
	Ctx  interface{}
}

// gate gobridge, it has some unknown race conditions
var gobridgeMu sync.Mutex

// GoBridge is exported to C for linking libsass to Go.  This function
// adheres to the interface provided by libsass.
//
//export GoBridge
func GoBridge(cargs UnionSassValue, cidx C.int) UnionSassValue {
	// Recover the Cookie struct passed in
	idx := int(cidx)
	ck, ok := globalFuncs.Get(idx).(Cookie)
	if !ok {
		fmt.Printf("failed to resolve Cookie %d\n", idx)
		return MakeNil()
	}
	// ck := *(*Cookie)(ptr)

	var usv UnionSassValue
	err := ck.Fn(ck.Ctx, cargs, &usv)
	_ = err
	return usv
}