Пример #1
0
func (self *PulseMainLoop) NewContext(name string, flags int) *PulseContext {
	name_ := C.CString(name)
	ctx := C.context_new(self.pa, name_, C.pa_context_flags_t(flags))
	var retval *PulseContext = nil
	if ctx != nil {
		retval = &PulseContext{MainLoop: self, ctx: ctx}
	}
	C.cfree(unsafe.Pointer(name_))
	return retval
}
Пример #2
0
// NewContext creates a new execution context for the active engine and returns
// an error if the execution context failed to initialize at any point.
func NewContext() (*Context, error) {
	ctx := &Context{
		Header: make(http.Header),
		values: make([]*Value, 0),
	}

	ptr, err := C.context_new(unsafe.Pointer(ctx))
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize context for PHP engine")
	}

	ctx.context = ptr

	return ctx, nil
}
Пример #3
0
func (e *Engine) NewContext(w io.Writer) (engine.Context, error) {
	ctx := &Context{writer: w}

	ptr, err := C.context_new(e.engine, unsafe.Pointer(ctx))
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize context for PHP engine")
	}

	ctx.context = ptr

	runtime.SetFinalizer(ctx, func(ctx *Context) {
		C.context_destroy(ctx.context)
	})

	return ctx, nil
}
Пример #4
0
// New creates a new execution context, passing all script output into w. It
// returns an error if the execution context failed to initialize at any point.
func New(w io.Writer) (*Context, error) {
	ctx := &Context{
		writer: w,
		header: make(http.Header),
		values: make(map[string]*value.Value),
	}

	ptr, err := C.context_new(unsafe.Pointer(ctx))
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize context for PHP engine")
	}

	ctx.context = ptr

	return ctx, nil
}
Пример #5
0
// NewContext creates a new execution context for the active engine and returns
// an error if the execution context failed to initialize at any point. This
// corresponds to PHP's RINIT (request init) phase.
func (e *Engine) NewContext() (*Context, error) {
	ptr, err := C.context_new()
	if err != nil {
		return nil, fmt.Errorf("Failed to initialize context for PHP engine")
	}

	ctx := &Context{
		Header:  make(http.Header),
		context: ptr,
		values:  make([]*Value, 0),
	}

	// Store reference to context, using pointer as key.
	e.contexts[ptr] = ctx

	return ctx, nil
}
Пример #6
0
func (b Board) Copy() Board {
	cpy := Board{}
	cpy.b = C.board_copy(b.b, b.ctx)
	cpy.ctx = C.context_new((*b.ctx).nHoles, (*b.ctx).totalStones)
	return cpy
}