代码拉取完成,页面将自动刷新
package luar
import (
"reflect"
"github.com/yuin/gopher-lua"
)
// Config is used to define luar behaviour for a particular *lua.LState.
type Config struct {
// The name generating function that defines under which names Go
// struct fields will be accessed.
//
// If nil, the default behaviour is used:
// - if the "luar" tag of the field is "", the field name and its name
// with a lowercase first letter is returned
// - if the tag is "-", no name is returned (i.e. the field is not
// accessible)
// - for any other tag value, that value is returned
FieldNames func(s reflect.Type, f reflect.StructField) []string
// The name generating function that defines under which names Go
// methods will be accessed.
//
// If nil, the default behaviour is used:
// - the method name and its name with a lowercase first letter
MethodNames func(t reflect.Type, m reflect.Method) []string
regular map[reflect.Type]*lua.LTable
types *lua.LTable
}
func newConfig() *Config {
return &Config{
regular: make(map[reflect.Type]*lua.LTable),
}
}
// GetConfig returns the luar configuration options for the given *lua.LState.
func GetConfig(L *lua.LState) *Config {
const registryKey = "github.com/layeh/gopher-luar"
registry := L.Get(lua.RegistryIndex).(*lua.LTable)
lConfig, ok := registry.RawGetString(registryKey).(*lua.LUserData)
if !ok {
lConfig = L.NewUserData()
lConfig.Value = newConfig()
registry.RawSetString(registryKey, lConfig)
}
return lConfig.Value.(*Config)
}
func defaultFieldNames(s reflect.Type, f reflect.StructField) []string {
const tagName = "luar"
tag := f.Tag.Get(tagName)
if tag == "-" {
return nil
}
if tag != "" {
return []string{tag}
}
return []string{
f.Name,
getUnexportedName(f.Name),
}
}
func defaultMethodNames(t reflect.Type, m reflect.Method) []string {
return []string{
m.Name,
getUnexportedName(m.Name),
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。