Exemplo n.º 1
0
func init() {
	piepan.Register("lua", &piepan.Plugin{
		Name: "Lua (C)",
		New: func(in *piepan.Instance) piepan.Environment {
			s := luar.Init()
			p := &Plugin{
				instance:  in,
				state:     s,
				listeners: make(map[string][]*luar.LuaObject),
			}

			luar.Register(s, "piepan", luar.Map{
				"On":         p.apiOn,
				"Disconnect": p.apiDisconnect,
			})
			s.GetGlobal("piepan")
			s.NewTable()
			luar.Register(s, "*", luar.Map{
				"Play":       p.apiAudioPlay,
				"IsPlaying":  p.apiAudioIsPlaying,
				"Stop":       p.apiAudioStop,
				"NewTarget":  p.apiAudioNewTarget,
				"SetTarget":  p.apiAudioSetTarget,
				"Bitrate":    p.apiAudioBitrate,
				"SetBitrate": p.apiAudioSetBitrate,
				"Volume":     p.apiAudioVolume,
				"SetVolume":  p.apiAudioSetVolume,
			})
			s.SetField(-2, "Audio")
			s.NewTable()
			luar.Register(s, "*", luar.Map{
				"New": p.apiTimerNew,
			})
			s.SetField(-2, "Timer")
			s.NewTable()
			luar.Register(s, "*", luar.Map{
				"New": p.apiProcessNew,
			})
			s.SetField(-2, "Process")
			s.SetTop(0)

			return p
		},
	})
}
Exemplo n.º 2
0
func init() {
	piepan.Register("go.lua", &piepan.Plugin{
		Name: "Lua (Go)",
		New: func(in *piepan.Instance) piepan.Environment {
			s := lua.NewState()
			p := &Plugin{
				instance:  in,
				state:     s,
				listeners: make(map[string][]lua.LValue),
			}

			pp := s.NewTable()
			s.SetGlobal("piepan", pp)

			pp.RawSetH(lua.LString("On"), luar.New(s, p.apiOn))
			pp.RawSetH(lua.LString("Disconnect"), luar.New(s, p.apiDisconnect))

			t := s.NewTable()
			t.RawSetH(lua.LString("Play"), luar.New(s, p.apiAudioPlay))
			t.RawSetH(lua.LString("IsPlaying"), luar.New(s, p.apiAudioIsPlaying))
			t.RawSetH(lua.LString("Stop"), luar.New(s, p.apiAudioStop))
			t.RawSetH(lua.LString("NewTarget"), luar.New(s, p.apiAudioNewTarget))
			t.RawSetH(lua.LString("SetTarget"), luar.New(s, p.apiAudioSetTarget))
			t.RawSetH(lua.LString("Bitrate"), luar.New(s, p.apiAudioBitrate))
			t.RawSetH(lua.LString("SetBitrate"), luar.New(s, p.apiAudioSetBitrate))
			t.RawSetH(lua.LString("Volume"), luar.New(s, p.apiAudioVolume))
			t.RawSetH(lua.LString("SetVolume"), luar.New(s, p.apiAudioSetVolume))
			pp.RawSetH(lua.LString("Audio"), t)

			t = s.NewTable()
			t.RawSetH(lua.LString("New"), luar.New(s, p.apiTimerNew))
			pp.RawSetH(lua.LString("Timer"), t)

			t = s.NewTable()
			t.RawSetH(lua.LString("New"), luar.New(s, p.apiProcessNew))
			pp.RawSetH(lua.LString("Process"), t)

			return p
		},
	})
}
Exemplo n.º 3
0
func init() {
	piepan.Register("js", &piepan.Plugin{
		Name: "JavaScript",
		New: func(in *piepan.Instance) piepan.Environment {
			s := otto.New()
			p := &Plugin{
				instance:  in,
				state:     s,
				listeners: make(map[string][]otto.Value),
			}
			s.Set("piepan", map[string]interface{}{
				"On":         p.apiOn,
				"Disconnect": p.apiDisconnect,
				"Audio": map[string]interface{}{
					"Play":       p.apiAudioPlay,
					"IsPlaying":  p.apiAudioIsPlaying,
					"Stop":       p.apiAudioStop,
					"NewTarget":  p.apiAudioNewTarget,
					"SetTarget":  p.apiAudioSetTarget,
					"Bitrate":    p.apiAudioBitrate,
					"SetBitrate": p.apiAudioSetBitrate,
					"Volume":     p.apiAudioVolume,
					"SetVolume":  p.apiAudioSetVolume,
				},
				"File": map[string]interface{}{
					"Open": p.apiFileOpen,
				},
				"Process": map[string]interface{}{
					"New": p.apiProcessNew,
				},
				"Timer": map[string]interface{}{
					"New": p.apiTimerNew,
				},
			})
			s.Set("ENV", createEnvVars())
			return p
		},
	})
}