Example #1
0
func (p *Plugin) apiAudioSetBitrate(l *lua.State) int {
	bitrate := l.ToInteger(1)
	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		enc.SetBitrate(bitrate)
	}
	return 0
}
Example #2
0
File: luar.go Project: imvu/Tetra
func sliceSub(L *lua.State) int {
	slice, _ := valueOfProxy(L, 1)
	i1, i2 := L.ToInteger(2), L.ToInteger(3)
	newslice := slice.Slice(i1-1, i2)
	makeValueProxy(L, newslice, cSLICE_META)
	return 1
}
Example #3
0
func LuaIntUTCTime(L *lua.State) int {
	luaAssertArgnum(L, 1, "utctime()")
	timestamp := L.ToInteger(1)
	PushTime(L, time.Unix(int64(timestamp), 0))

	return 1
}
Example #4
0
func (p *Plugin) apiTimerNew(l *lua.State) int {
	callback := luar.NewLuaObject(l, 1)
	timeout := l.ToInteger(2)

	t := &Timer{
		cancel: make(chan bool),
	}

	go func() {
		defer func() {
			close(t.cancel)
			t.cancel = nil
		}()

		select {
		case <-time.After(time.Millisecond * time.Duration(timeout)):
			p.callValue(callback)
			callback.Close()
		case <-t.cancel:
		}
	}()

	obj := luar.NewLuaObjectFromValue(l, t)
	obj.Push()
	obj.Close()
	return 1
}
Example #5
0
File: luar.go Project: kdar/luar
func slice__newindex(L *lua.State) int {
	slice, t := valueOfProxy(L, 1)
	idx := L.ToInteger(2)
	val := LuaToGo(L, t.Elem(), 3)
	slice.Index(idx - 1).Set(valueOf(val))
	return 0
}
Example #6
0
func GetTableInt(L *lua.State, name string) int {
	// Remember to check stack for 1 extra location
	L.PushString(name)
	L.GetTable(-2)
	r := L.ToInteger(-1)
	L.Pop(1)
	return r
}
Example #7
0
File: luar.go Project: imvu/Tetra
func slice__newindex(L *lua.State) int {
	slice, t := valueOfProxy(L, 1)
	idx := L.ToInteger(2)
	val := luaToGoValue(L, t.Elem(), 3)
	if idx < 1 || idx > slice.Len() {
		RaiseError(L, "slice set: index out of range")
	}
	slice.Index(idx - 1).Set(val)
	return 0
}
Example #8
0
func (p *Plugin) apiAudioNewTarget(l *lua.State) int {
	id := l.ToInteger(1)

	target := &gumble.VoiceTarget{}
	target.ID = uint32(id)

	obj := luar.NewLuaObjectFromValue(l, target)
	obj.Push()
	obj.Close()
	return 1
}
Example #9
0
func LuaIntLocalTime(L *lua.State) int {
	luaAssertArgnum(L, 1, "localtime()")
	tl := GetTasklistFromLua(L)
	timezone := tl.GetTimezone()
	timestamp := L.ToInteger(1)

	t := time.Unix(int64(timestamp)+(int64(timezone)*60*60), 0)

	PushTime(L, t)

	return 1
}
Example #10
0
File: luar.go Project: imvu/Tetra
func slice__index(L *lua.State) int {
	slice, _ := valueOfProxy(L, 1)
	if L.IsNumber(2) {
		idx := L.ToInteger(2)
		if idx < 1 || idx > slice.Len() {
			RaiseError(L, "slice get: index out of range")
		}
		ret := slice.Index(idx - 1)
		GoToLua(L, ret.Type(), ret, false)
	} else {
		RaiseError(L, "slice requires integer index")
	}
	return 1
}
Example #11
0
File: luar.go Project: kdar/luar
func slice__index(L *lua.State) int {
	slice, _ := valueOfProxy(L, 1)
	if L.IsNumber(2) {
		idx := L.ToInteger(2)
		ret := slice.Index(idx - 1)
		GoToLua(L, ret.Type(), ret)
	} else {
		name := L.ToString(2)
		switch name {
		case "Slice":
			L.PushGoFunction(slice_slice)
		default:
			fmt.Println("unknown slice method")
		}
	}
	return 1
}
Example #12
0
func LuaIntGetterSetterFunctionInt(fname string, L *lua.State, getter func(tl *Tasklist, entry *Entry) int64, setter func(tl *Tasklist, entry *Entry, value int)) int {
	argNum := L.GetTop()

	if argNum == 0 {
		entry := GetEntryFromLua(L, CURSOR, fname)
		tl := GetTasklistFromLua(L)
		L.PushInteger(getter(tl, entry))
		return 1
	} else if argNum == 1 {
		value := L.ToInteger(1)
		entry := GetEntryFromLua(L, CURSOR, fname)
		tl := GetTasklistFromLua(L)
		setter(tl, entry, value)
		if !tl.luaFlags.cursorCloned {
			tl.luaFlags.cursorEdited = true
		}
		return 0
	}

	panic(errors.New(fmt.Sprintf("Incorrect number of argoments to %s (only 0 or 1 accepted)", fname)))
	return 0
}
Example #13
0
func LuaIntSplit(L *lua.State) int {
	if L.GetTop() < 2 {
		panic(errors.New("Wrong number of arguments to split()"))
		return 0
	}

	instr := L.ToString(1)
	sepstr := L.ToString(2)

	n := -1

	if L.GetTop() == 3 {
		n = L.ToInteger(3)
	}

	if L.GetTop() > 3 {
		panic(errors.New("Wrong number of arguments to split()"))
		return 0
	}

	PushStringVec(L, strings.SplitN(instr, sepstr, n))

	return 1
}