Wrapped ph7_compile_file
This commit is contained in:
parent
4b4b9abcbc
commit
869a2f3e67
26
ph7.go
26
ph7.go
@ -53,8 +53,6 @@ type Error struct {
|
|||||||
Code ResultCode
|
Code ResultCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO create a CompileError that contains the error log text
|
|
||||||
|
|
||||||
func newError(code C.int) error {
|
func newError(code C.int) error {
|
||||||
if code == C.PH7_OK {
|
if code == C.PH7_OK {
|
||||||
return nil
|
return nil
|
||||||
@ -100,7 +98,12 @@ func (e *Engine) ErrLog() (string, error) {
|
|||||||
return C.GoStringN(s, n), nil
|
return C.GoStringN(s, n), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO All the ph7_config verbs
|
/*
|
||||||
|
We don't bother ph7_config verbs other than PH7_CONFIG_ERR_LOG.
|
||||||
|
PH7_CONFIG_ERR_OUTPUT is another way of getting compile error messages,
|
||||||
|
which we don't need separately from returning CompileError values.
|
||||||
|
PH7_CONFIG_ERR_ABORT doesn't do anything.
|
||||||
|
*/
|
||||||
|
|
||||||
func (e *Engine) compileError(code C.int) error {
|
func (e *Engine) compileError(code C.int) error {
|
||||||
switch code {
|
switch code {
|
||||||
@ -135,6 +138,23 @@ func (e *Engine) Compile(source []byte, phpOnly bool) (*VM, error) {
|
|||||||
return newVM(cvm), nil
|
return newVM(cvm), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Engine) CompileFile(path string, phpOnly bool) (*VM, error) {
|
||||||
|
cpath := C.CString(path)
|
||||||
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
|
||||||
|
var flags C.int
|
||||||
|
if phpOnly {
|
||||||
|
flags |= C.PH7_PHP_ONLY
|
||||||
|
}
|
||||||
|
var cvm *C.ph7_vm
|
||||||
|
err := e.compileError(C.ph7_compile_file((*C.ph7)(e), cpath, &cvm, flags))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newVM(cvm), nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO (*Engine).CompileFile
|
// TODO (*Engine).CompileFile
|
||||||
|
|
||||||
func (e *Engine) Close() error {
|
func (e *Engine) Close() error {
|
||||||
|
12
ph7_test.go
12
ph7_test.go
@ -84,6 +84,18 @@ func TestCore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompileFile(t *testing.T) {
|
||||||
|
engine, err := ph7.NewEngine()
|
||||||
|
mustSucceed(t, err)
|
||||||
|
defer mustSucceedF(t, engine.Close)
|
||||||
|
|
||||||
|
vm, err := engine.CompileFile("testdata/test_compile_file.php", false)
|
||||||
|
mustSucceed(t, err)
|
||||||
|
defer mustSucceedF(t, vm.Close)
|
||||||
|
|
||||||
|
expectOutput(t, vm, "Hello world!")
|
||||||
|
}
|
||||||
|
|
||||||
func TestCompileError(t *testing.T) {
|
func TestCompileError(t *testing.T) {
|
||||||
engine, err := ph7.NewEngine()
|
engine, err := ph7.NewEngine()
|
||||||
mustSucceed(t, err)
|
mustSucceed(t, err)
|
||||||
|
1
testdata/test_compile_file.php
vendored
Normal file
1
testdata/test_compile_file.php
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?php echo 'Hello world!'; ?>
|
Loading…
Reference in New Issue
Block a user