Help us shape the future of Go! Take the 2026 Go Developer Survey

pool

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypeTable = map[reflect.Type]func(interface{}, lua.LValue){
	reflect.TypeOf(""): func(dst interface{}, src lua.LValue) {
		*(dst.(*string)) = src.String()
	},
	reflect.TypeOf(true): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNil:
			*(dst.(*bool)) = false
		case lua.LTString:
			*(dst.(*bool)), _ = strconv.ParseBool(string(src.(lua.LString)))
		default:
			*(dst.(*bool)) = true
		}
	},
	reflect.TypeOf(float64(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*float64)) = float64(src.(lua.LNumber))
		case lua.LTString:
			*(dst.(*float64)), _ = strconv.ParseFloat(string(src.(lua.LString)), 64)
		default:
			*(dst.(*float64)) = 0
		}
	},
	reflect.TypeOf(float32(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*float32)) = float32(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseFloat(string(src.(lua.LString)), 32)
			*(dst.(*float32)) = float32(v)
		default:
			*(dst.(*float32)) = 0
		}
	},
	reflect.TypeOf(int(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*int)) = int(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseInt(string(src.(lua.LString)), 0, 63)
			*(dst.(*int)) = int(v)
		default:
			*(dst.(*int)) = 0
		}
	},
	reflect.TypeOf(int8(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*int8)) = int8(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseInt(string(src.(lua.LString)), 0, 7)
			*(dst.(*int8)) = int8(v)
		default:
			*(dst.(*int8)) = 0
		}
	},
	reflect.TypeOf(int16(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*int16)) = int16(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseInt(string(src.(lua.LString)), 0, 15)
			*(dst.(*int16)) = int16(v)
		default:
			*(dst.(*int16)) = 0
		}
	},
	reflect.TypeOf(int32(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*int32)) = int32(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseInt(string(src.(lua.LString)), 0, 31)
			*(dst.(*int32)) = int32(v)
		default:
			*(dst.(*int32)) = 0
		}
	},
	reflect.TypeOf(int64(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*int64)) = int64(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseInt(string(src.(lua.LString)), 0, 63)
			*(dst.(*int64)) = int64(v)
		default:
			*(dst.(*int64)) = 0
		}
	},
	reflect.TypeOf(rune(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*rune)) = rune(src.(lua.LNumber))
		case lua.LTString:
			if s := string(src.(lua.LString)); len(s) > 0 {
				*(dst.(*rune)), _ = utf8.DecodeRuneInString(s)
			}
		default:
			*(dst.(*rune)) = 0
		}
	},
	reflect.TypeOf(uint(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*uint)) = uint(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseUint(string(src.(lua.LString)), 0, 64)
			*(dst.(*uint)) = uint(v)
		default:
			*(dst.(*uint)) = 0
		}
	},
	reflect.TypeOf(byte(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*byte)) = byte(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseUint(string(src.(lua.LString)), 0, 8)
			*(dst.(*byte)) = byte(v)
		default:
			*(dst.(*byte)) = 0
		}
	},
	reflect.TypeOf(uint8(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*uint8)) = uint8(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseUint(string(src.(lua.LString)), 0, 8)
			*(dst.(*uint8)) = uint8(v)
		default:
			*(dst.(*uint8)) = 0
		}
	},
	reflect.TypeOf(uint16(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*uint16)) = uint16(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseUint(string(src.(lua.LString)), 0, 16)
			*(dst.(*uint16)) = uint16(v)
		default:
			*(dst.(*uint16)) = 0
		}
	},
	reflect.TypeOf(uint32(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*uint32)) = uint32(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseUint(string(src.(lua.LString)), 0, 32)
			*(dst.(*uint32)) = uint32(v)
		default:
			*(dst.(*uint32)) = 0
		}
	},
	reflect.TypeOf(uint64(0)): func(dst interface{}, src lua.LValue) {
		switch src.Type() {
		case lua.LTNumber:
			*(dst.(*uint64)) = uint64(src.(lua.LNumber))
		case lua.LTString:
			v, _ := strconv.ParseUint(string(src.(lua.LString)), 0, 64)
			*(dst.(*uint64)) = uint64(v)
		default:
			*(dst.(*uint64)) = 0
		}
	},
}

Functions

func Lazy added in v1.0.5

func Lazy(name string, init func() interface{}) func(*lua.LState) error

func Library added in v1.0.6

func Library() func(ls *lua.LState) error

func Module

func Module(name string, val interface{}) func(*lua.LState) error

func Source

func Source(r io.Reader, name ...string) func(*lua.LState) error

func Type

func Type(name string, val interface{}) func(*lua.LState) error

func Value

func Value(name string, val interface{}) func(*lua.LState) error

Types

type LuaModule added in v1.0.4

type LuaModule interface {
	To(val interface{}, name ...string) bool
	Call(name string, args ...interface{})
	Method(name string, val interface{}) bool
}

type LuaPool

type LuaPool struct {
	// contains filtered or unexported fields
}

func NewLuaPool

func NewLuaPool(opt ...lua.Options) *LuaPool

func (*LuaPool) Close

func (p *LuaPool) Close() error

func (*LuaPool) DoFile

func (p *LuaPool) DoFile(file string) error

func (*LuaPool) DoString

func (p *LuaPool) DoString(source string) error

func (*LuaPool) Get

func (p *LuaPool) Get() *lua.LState

func (*LuaPool) Group

func (p *LuaPool) Group(l int) (result []*lua.LState)

func (*LuaPool) ModuleFile added in v1.0.4

func (p *LuaPool) ModuleFile(file string) (LuaModule, error)

func (*LuaPool) ModuleString added in v1.0.4

func (p *LuaPool) ModuleString(source string) (LuaModule, error)

func (*LuaPool) Preload

func (p *LuaPool) Preload(load ...func(*lua.LState) error) *LuaPool

func (*LuaPool) Put

func (p *LuaPool) Put(L *lua.LState)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL