func testMap() { m := sciter.NewValue() m.Set("key", "asdf") log.Println("m.len", m.Length(), m.IsMap()) m.Set("int", 123) log.Println("m:", m.Get("key"), m.Get("int")) }
func testCall(w *window.Window) { // test sciter call v, err := w.Call("gFunc", sciter.NewValue("kkk"), sciter.NewValue(555)) if err != nil { log.Println("sciter call failed:", err) } else { log.Println("sciter call successfully:", v.String()) } // test method call root, err := w.GetRootElement() if err != nil { log.Fatalf("get root element failed: %s", err.Error()) } v, err = root.CallMethod("mfn", sciter.NewValue("method call"), sciter.NewValue(10300)) if err != nil { log.Println("method call failed:", err) } else { log.Println("method call successfully:", v.String()) } // test function call v, err = root.CallFunction("gFunc", sciter.NewValue("function call"), sciter.NewValue(10300)) if err != nil { log.Println("function call failed:", err) } else { log.Println("function call successfully:", v.String()) } }
func setEventHandler(w *window.Window) { w.DefineFunction("kkk", func(args ...*sciter.Value) *sciter.Value { log.Println("kkk called!") rval := sciter.NewValue() rval.Set("num", sciter.NewValue(1000)) rval.Set("str", sciter.NewValue("a string")) var fn sciter.NativeFunctor fn = func(args ...*sciter.Value) *sciter.Value { log.Printf("args[%d]:%v\n", len(args), args) return sciter.NewValue("native functor called") } rval.Set("f", sciter.NewValue(fn)) return rval }) w.DefineFunction("sumall", func(args ...*sciter.Value) *sciter.Value { sum := 0 for i := 0; i < len(args); i++ { sum += args[i].Int() } return sciter.NewValue(sum) }) w.DefineFunction("gprintln", func(args ...*sciter.Value) *sciter.Value { print("\t->") for _, arg := range args { print(arg.String(), "\t") } println() return sciter.NullValue() }) }
func testArray() { v := sciter.NewValue() // v.SetIndex(0, sciter.NewValue(100)) log.Println("v.len", v.Length()) v.Append(105) log.Println("v.len", v.Length(), v.IsArray()) v.Append(205) log.Println("v.len", v.Length()) v.Append(200) log.Println("v.len", v.Length()) rv := v.Index(0) log.Println("test Value.Index:", rv) }