Пример #1
0
func NewJQ(program string) (*JQ, error) {
	state := C.jq_init()
	jq := &JQ{program, state, C.jv_invalid()}
	if err := jq.compile(program); err != nil {
		jq.Close()
		return nil, err
	}
	return jq, nil
}
Пример #2
0
// Compile compiles a JQ filter into a new JQ virtual machine.
func Compile(proc string) (*Vm, error) {
	s := new(Vm)
	s.jq = C.jq_init()

	err := compileJq(s.jq, proc)
	if err != nil {
		s.Close()
		return nil, err
	}
	return s, nil
}
Пример #3
0
Файл: jq.go Проект: ashb/jqrepl
// New initializes a new JQ object and the underlying C library.
func New() (*Jq, error) {
	jq := new(Jq)

	var err error
	jq._state, err = C.jq_init()

	if err != nil {
		return nil, err
	} else if jq == nil {
		return nil, errors.New("jq_init returned nil -- out of memory?")
	}

	return jq, nil
}
Пример #4
0
Файл: jq.go Проект: vantroy/jq
// NewJq returns an initialized state with a compiled program
// program should be a valid jq program/filter
// see http://stedolan.github.io/jq/manual/#Basicfilters for more info
func newJqExecutor(program string) (*jqExecutor, error) {
	jq := &jqExecutor{
		state: C.jq_init(),
	}

	if jq.state == nil {
		return nil, errJqStateNil
	}

	pgm := C.CString(program)
	defer C.free(unsafe.Pointer(pgm))

	// Compiles a program into jq_state.
	if ok := C.jq_compile(jq.state, pgm); ok != 1 {
		jq.free()
		return nil, errInvalidProgram
	}

	return jq, nil
}