From e2c1b19b3e9c37872c92577aa6e623dabdf1a7da Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 27 Nov 2022 09:32:17 -0700 Subject: [PATCH] Make a complete todo list --- ph7.go | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/ph7.go b/ph7.go index 0d096cf..a347a58 100644 --- a/ph7.go +++ b/ph7.go @@ -94,6 +94,8 @@ func (e *Engine) ErrLog() (string, error) { return C.GoStringN(s, n), nil } +// TODO All the ph7_config verbs + func (e *Engine) Compile(source []byte, phpOnly bool) (*VM, error) { csource := C.CBytes(source) defer C.free(csource) @@ -110,13 +112,129 @@ func (e *Engine) Compile(source []byte, phpOnly bool) (*VM, error) { return newVM(cvm), nil } +// TODO (*Engine).CompileFile + func (e *Engine) Close() error { return newError(C.ph7_release((*C.ph7)(e))) } +type Context C.ph7_context + +func (c *Context) ResultInt(i int) error { + return newError(C.ph7_result_int((*C.ph7_context)(c), C.int(i))) +} + +func (c *Context) ResultInt64(i int64) error { + return newError(C.ph7_result_int64((*C.ph7_context)(c), C.ph7_int64(i))) +} + +func (c *Context) ResultBool(b bool) error { + var cb C.int + if b { + cb = 1 + } + return newError(C.ph7_result_bool((*C.ph7_context)(c), cb)) +} + +func (c *Context) ResultDouble(d float64) error { + return newError(C.ph7_result_double((*C.ph7_context)(c), C.double(d))) +} + +func (c *Context) ResultNull() error { + return newError(C.ph7_result_null((*C.ph7_context)(c))) +} + +func (c *Context) ResultString(s string) error { + cs := C.CString(s) + defer C.free(unsafe.Pointer(cs)) + + return newError(C.ph7_result_string((*C.ph7_context)(c), cs, C.int(len(s)))) +} + +// TODO (*Context).ResultStringFormat maybe? Or just use fmt.Sprint*. + +func (c *Context) ResultValue(value *Value) error { + return newError(C.ph7_result_value((*C.ph7_context)(c), (*C.ph7_value)(value))) +} + +// TODO (*Context).ResultResource + +func (c *Context) Output(s string) error { + cs := C.CString(s) + defer C.free(unsafe.Pointer(cs)) + + return newError(C.ph7_context_output((*C.ph7_context)(c), cs, C.int(len(s)))) +} + +// TODO (*Context).OutputFormat maybe? +// TODO (*Context).ThrowError + +func (c *Context) RandomNum() uint { + return uint(C.ph7_context_random_num((*C.ph7_context)(c))) +} + +// TODO (*Context).RandomString +// TODO (*Context).UserData +// TODO (*Context).PushAuxData +// TODO (*Context).PeekAuxData +// TODO (*Context).PopAuxData +// TODO (*Context).ResultBufLength +// TODO (*Context).FunctionName + +// TODO (*Context).AllocChunk +// TODO (*Context).ReallocChunk +// TODO (*Context).FreeChunk + type Value C.ph7_value -type Context C.ph7_context +// TODO (*Value).ToInt +// TODO (*Value).ToBool +// TODO (*Value).ToInt64 +// TODO (*Value).ToDouble +// TODO (*Value).ToString +// TODO (*Value).ToResource +// TODO (*Value).Compare + +// TODO (*Value).Int +// TODO (*Value).Int64 +// TODO (*Value).Bool +// TODO (*Value).Null +// TODO (*Value).Double +// TODO (*Value).String +// TODO (*Value).StringFormat maybe? +// TODO (*Value).ResetStringCursor +// TODO (*Value).Resource +// TODO (*Value).Release +// TODO (*Value).ArrayFetch +// TODO (*Value).ArrayWalk +// TODO (*Value).ArrayAddElem +// TODO (*Value).ArrayAddStrkeyElem +// TODO (*Value).ArrayAddIntkeyElem +// TODO (*Value).ArrayCount +// TODO (*Value).ObjectWalk +// TODO (*Value).ObjectFetchAttr +// TODO (*Value).ObjectGetClassName +// TODO (*Value).IsInt +// TODO (*Value).IsFloat +// TODO (*Value).IsBool +// TODO (*Value).IsString +// TODO (*Value).IsNull +// TODO (*Value).IsNumeric +// TODO (*Value).IsCallable +// TODO (*Value).IsScalar +// TODO (*Value).IsArray +// TODO (*Value).IsObject +// TODO (*Value).IsResource +// TODO (*Value).IsEmpty + +// TODO Init +// TODO Config +// TODO Shutdown +// TODO IsThreadsafe +// TODO Version +// TODO Signature +// TODO Ident +// TODO Copyright type VM struct { ptr *C.ph7_vm @@ -150,6 +268,9 @@ func (vm *VM) SetOutputWriter(w io.Writer) error { return newError(C.vm_set_output_callback(vm.ptr, vm.pointerKey)) } +// TODO All the ph7_vm_config verbs +// TODO (*VM).Dump(w io.Writer) + func (vm *VM) OutputWriteError() error { return vm.outputWriteErr } @@ -208,3 +329,7 @@ func (vm *VM) CreateFunction(name string, f ForeignFunction) error { return newError(C.vm_create_function(vm.ptr, cname, fkey)) } + +// TODO (*VM).DeleteFunction +// TODO (*VM).CreateConstant +// TODO (*VM).DeleteConstant