diff --git a/ph7.go b/ph7.go index 312c461..ad00c55 100644 --- a/ph7.go +++ b/ph7.go @@ -247,7 +247,10 @@ func (c *Context) RandomString(length int) (string, error) { // TODO (*Context).PeekAuxData // TODO (*Context).PopAuxData // TODO (*Context).ResultBufLength -// TODO (*Context).FunctionName + +func (c *Context) FunctionName() string { + return C.GoString(C.ph7_function_name((*C.ph7_context)(c))) +} // TODO (*Context).AllocChunk // TODO (*Context).ReallocChunk diff --git a/ph7_test.go b/ph7_test.go index ba95f65..d29d31d 100644 --- a/ph7_test.go +++ b/ph7_test.go @@ -198,6 +198,19 @@ func TestContextThrowError(t *testing.T) { } } +func TestFunctionName(t *testing.T) { + const script = "echo doStuff();" + vm, close := setupVM(t, script) + defer close() + + f := func(ctx *ph7.Context) error { + _, err := fmt.Fprint(ctx, ctx.FunctionName()) + return err + } + mustSucceed(t, vm.CreateFunction("doStuff", CtxFunc(f))) + expectOutput(t, vm, "doStuff") +} + func TestContextResultInt(t *testing.T) { testResultCode(t, "42", func(ctx *ph7.Context) error { return ctx.ResultInt(42)