sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.58k stars 268 forks source link

not support empty parameter in CallFunction #175

Closed JerryKwan closed 6 years ago

JerryKwan commented 6 years ago

When defining a function in script, if the function has not parameter, it will introduce an error such as "runtime error: index out of range", and after review the codes, i think it was introduced in the following snippets

func (e *Element) CallFunction(functionName string, args ...*Value) (retval *Value, err error) {
    retval = NewValue()
    argc := len(args)
    argv := make([]Value, argc)
    for i := 0; i < argc; i++ {
        argv[i] = *args[i]
    }
    // args
    cfn := C.LPCSTR(unsafe.Pointer(StringToBytePtr(functionName)))
    cargc := C.UINT(argc)
    cargv := (*C.SCITER_VALUE)(unsafe.Pointer(&argv[0]))
    cretval := (*C.SCITER_VALUE)(unsafe.Pointer(retval))
    // cgo call
    r := C.SciterCallScriptingFunction(e.handle, cfn, cargv, cargc, cretval)
    err = wrapDomResult(r, "SciterCallScriptingFunction")
    return
}

The error was introduced by __cargv := (*C.SCITER_VALUE)(unsafe.Pointer(&argv[0]))__

pravic commented 6 years ago

True, thank you for the catch. Care to send a fix?

JerryKwan commented 6 years ago

@pravic , Yes, absolutely, the pull request has been sent, please take some time to review, thank you

https://github.com/sciter-sdk/go-sciter/pull/176

pravic commented 6 years ago

Thanks!