2022-10-04 13:21:05 +08:00
|
|
|
|
//----------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
|
//
|
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2022-10-04 13:21:05 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// V8 JSValue 通用类型实现
|
|
|
|
|
//
|
|
|
|
|
// 通用类型是可变类型,对于JS语言可以动态赋任意类型的值
|
|
|
|
|
//
|
|
|
|
|
// # Go中针对几种基本类型增加了可变类型实现
|
|
|
|
|
//
|
|
|
|
|
// 绑定 定义的普通函数 前缀-默认是结构名称, prefix default struct name
|
2022-10-04 13:21:05 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewString GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewString(name, value string) *JSString {
|
|
|
|
|
return VariableBind.NewString(name, value)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewInteger GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewInteger(name string, value int32) *JSInteger {
|
|
|
|
|
return VariableBind.NewInteger(name, value)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewDouble GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewDouble(name string, value float64) *JSDouble {
|
|
|
|
|
return VariableBind.NewDouble(name, value)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewBoolean GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewBoolean(name string, value bool) *JSBoolean {
|
|
|
|
|
return VariableBind.NewBoolean(name, value)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewNull GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewNull(name string) *JSNull {
|
|
|
|
|
return VariableBind.NewNull(name)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewUndefined GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewUndefined(name string) *JSUndefined {
|
|
|
|
|
return VariableBind.NewUndefined(name)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewFunction GO&JS 类型
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewFunction(name string, fn interface{}) error {
|
|
|
|
|
return VariableBind.NewFunction(name, fn)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
|
// NewObjects GO&JS 类型
|
|
|
|
|
//
|
|
|
|
|
// Go结构类型变量和Go结构函数绑定
|
2023-02-21 23:16:35 +08:00
|
|
|
|
func (m *V8Value) NewObjects(objects ...interface{}) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
bindObject(objects...)
|
|
|
|
|
}
|
2023-02-21 23:16:35 +08:00
|
|
|
|
|
|
|
|
|
// Bind V8Value
|
|
|
|
|
//
|
|
|
|
|
// 变量和函数绑定, 在Go中定义的字段绑定到JS字段中, 在Go中定义的函数导出到JS
|
|
|
|
|
//
|
|
|
|
|
// 支持类型 String = string , Integer = int32 , Double = float64, Boolean = bool, Function = func, Objects = struct | map, Array = Slice
|
|
|
|
|
//
|
|
|
|
|
// 主进程和子进程
|
|
|
|
|
func (m *V8Value) Bind(name string, bind interface{}) error {
|
|
|
|
|
return VariableBind.Bind(name, bind)
|
|
|
|
|
}
|