本文整理汇总了Golang中github.com/aarzilli/golua/lua.State类的典型用法代码示例。如果您正苦于以下问题:Golang State类的具体用法?Golang State怎么用?Golang State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: apiTimerNew
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
}
开发者ID:mgalvey,项目名称:piepan,代码行数:27,代码来源:timer.go
示例2: prepContext
func (p *LuaPlugin) prepContext(L *lua.State, req *http.Request, ctx *apiplexy.APIContext) {
var clientIP string
if req.Header.Get("X-Forwarded-For") != "" {
clientIP = req.Header.Get("X-Forwarded-For")
} else {
clientIP, _, _ = net.SplitHostPort(req.RemoteAddr)
}
headers := make(map[string]interface{}, len(req.Header))
for k, vs := range req.Header {
headers[k] = strings.Join(vs, " ")
}
request := map[string]interface{}{
"path": req.URL.Path,
"method": req.Method,
"ip": clientIP,
"referrer": req.Referer(),
"browser": req.UserAgent(),
"headers": headers,
}
pushMap(L, request, false)
L.SetGlobal("request")
pushMap(L, structs.Map(ctx), true)
L.SetGlobal("context")
}
开发者ID:12foo,项目名称:apiplexy,代码行数:27,代码来源:lua.go
示例3: sliceSub
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
}
开发者ID:imvu,项目名称:Tetra,代码行数:7,代码来源:luar.go
示例4: callGoMethod
func callGoMethod(L *lua.State, name string, st reflect.Value) {
ret := st.MethodByName(name)
if !ret.IsValid() {
fmt.Println("whoops")
}
L.PushGoFunction(GoLuaFunc(L, ret))
}
开发者ID:kdar,项目名称:luar,代码行数:7,代码来源:luar.go
示例5: GoLua
func GoLua(L *lua.State) int {
go func() {
LT := L.NewThread()
L.PushValue(1)
lua.XMove(L, LT, 1)
res := LT.Resume(0)
for res != 0 {
if res == 2 {
emsg := LT.ToString(-1)
RaiseError(LT, emsg)
}
ch, t := valueOfProxy(LT, -2)
if LT.ToBoolean(-1) { // send on a channel
val := luaToGoValue(LT, t.Elem(), -3)
ch.Send(val)
res = LT.Resume(0)
} else { // receive on a channel
val, ok := ch.Recv()
GoToLua(LT, t.Elem(), val, false)
LT.PushBoolean(ok)
res = LT.Resume(2)
}
}
}()
return 0
}
开发者ID:imvu,项目名称:Tetra,代码行数:27,代码来源:luar.go
示例6: MessThingIndex
func MessThingIndex(state *lua.State) int {
log.Println("HEY WE MADE IT")
printStackTypes(state)
state.GetMetaTable(1)
state.LGetMetaTable(ThingMetaTableName)
isThing := state.RawEqual(-1, -2)
state.Pop(2)
if !isThing {
log.Println("!!! OMG ARG #1 IS NOT A MESS.THING !!!")
}
fieldName := state.CheckString(2)
log.Println("Arg #2 checks out, it's a string")
thing := checkThing(state, 1)
log.Println("So we're tryin'a look up", fieldName, "on thing", thing.Id)
if member, ok := MessThingMembers[fieldName]; ok {
return member(state, thing)
}
// That wasn't one of our members, so look it up in our Table.
if data, ok := thing.Table[fieldName]; ok {
// TODO: instead of pushing a whole map if the script asks for one, maybe we should use another kind of userdata that tracks the name & can access its submembers until the script asks for the leaf (or a non-existent branch)?
pushValue(state, data)
return 1
}
// uh... I guess we didn't do anything, so...?
return 0
}
开发者ID:natmeox,项目名称:mess,代码行数:31,代码来源:softcode.go
示例7: apiAudioSetBitrate
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
}
开发者ID:mgalvey,项目名称:piepan,代码行数:7,代码来源:audio.go
示例8: apiAudioPlay
func (p *Plugin) apiAudioPlay(l *lua.State) int {
if p.instance.Audio.IsPlaying() {
l.PushBoolean(false)
return 1
}
obj := luar.NewLuaObject(l, 1)
filename := obj.Get("filename").(string)
callback := obj.GetObject("callback")
obj.Close()
if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
enc.SetApplication(gopus.Audio)
}
p.instance.Audio.Source = gumble_ffmpeg.SourceFile(filename)
p.instance.Audio.Play()
go func() {
p.instance.Audio.Wait()
if callback.Type != "nil" {
p.callValue(callback)
}
callback.Close()
}()
return 0
}
开发者ID:mgalvey,项目名称:piepan,代码行数:27,代码来源:audio.go
示例9: slice__newindex
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
}
开发者ID:kdar,项目名称:luar,代码行数:7,代码来源:luar.go
示例10: copySliceToTable
// Also for arrays.
func copySliceToTable(L *lua.State, vslice reflect.Value, visited visitor) int {
ref := vslice
for vslice.Kind() == reflect.Ptr {
// For arrays.
vslice = vslice.Elem()
}
if vslice.IsValid() && (vslice.Kind() == reflect.Slice || vslice.Kind() == reflect.Array) {
n := vslice.Len()
L.CreateTable(n, 0)
if vslice.Kind() == reflect.Slice {
visited.mark(vslice)
} else if ref.Kind() == reflect.Ptr {
visited.mark(ref)
}
for i := 0; i < n; i++ {
L.PushInteger(int64(i + 1))
v := vslice.Index(i)
if isNil(v) {
v = nullv
}
goToLua(L, nil, v, true, visited)
L.SetTable(-3)
}
return 1
}
L.PushNil()
L.PushString("not a slice/array")
return 2
}
开发者ID:stevedonovan,项目名称:luar,代码行数:32,代码来源:luar.go
示例11: proxy__gc
func proxy__gc(L *lua.State) int {
vp := (*valueProxy)(L.ToUserdata(1))
mu.Lock()
delete(proxyMap, vp)
mu.Unlock()
return 0
}
开发者ID:yinlei,项目名称:luar,代码行数:7,代码来源:luar.go
示例12: LuaIntUTCTime
func LuaIntUTCTime(L *lua.State) int {
luaAssertArgnum(L, 1, "utctime()")
timestamp := L.ToInteger(1)
PushTime(L, time.Unix(int64(timestamp), 0))
return 1
}
开发者ID:aarzilli,项目名称:pooch,代码行数:7,代码来源:luaint.go
示例13: PushStringVec
func PushStringVec(L *lua.State, v []string) {
L.CheckStack(3)
L.CreateTable(len(v), 0)
for idx, val := range v {
SetTableIntString(L, int64(idx+1), val)
}
}
开发者ID:aarzilli,项目名称:pooch,代码行数:8,代码来源:luaint.go
示例14: apiAudioBitrate
func (p *Plugin) apiAudioBitrate(l *lua.State) int {
if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
l.PushInteger(int64(enc.Bitrate()))
} else {
l.PushInteger(-1)
}
return 1
}
开发者ID:mgalvey,项目名称:piepan,代码行数:8,代码来源:audio.go
示例15: LuaIntShowRet
func LuaIntShowRet(L *lua.State) int {
L.CheckStack(2)
tl := GetTasklistFromLua(L)
tl.luaFlags.showReturnValue = true
return 0
}
开发者ID:aarzilli,项目名称:pooch,代码行数:8,代码来源:luaint.go
示例16: printStackTypes
func printStackTypes(state *lua.State) {
topIndex := state.GetTop()
segments := make([]interface{}, topIndex+1)
segments[0] = "Stack types:"
for i := 1; i <= topIndex; i++ {
segments[i] = state.LTypename(i)
}
log.Println(segments...)
}
开发者ID:natmeox,项目名称:mess,代码行数:9,代码来源:softcode.go
示例17: LuaIntWriteCursor
func LuaIntWriteCursor(L *lua.State) int {
Logf(INFO, "Writing cursor")
L.CheckStack(1)
tl := GetTasklistFromLua(L)
luaAssertNotFreeCursor(tl, "writecursor()")
cursor := GetEntryFromLua(L, CURSOR, "writecursor()")
tl.Update(cursor, false)
return 0
}
开发者ID:aarzilli,项目名称:pooch,代码行数:9,代码来源:luaint.go
示例18: proxyType
func proxyType(L *lua.State) int {
v := unwrapProxy(L, 1)
if v != nil {
GoToLua(L, nil, valueOf(reflect.TypeOf(v)), false)
} else {
L.PushNil()
}
return 1
}
开发者ID:imvu,项目名称:Tetra,代码行数:9,代码来源:luar.go
示例19: goToLua
// goToLua copies Go values to Lua and sets the result to global 'name'.
// Compound types are deep-copied.
// Functions are automatically converted to 'func (L *lua.State) int'.
func goToLua(L *lua.State, name string, val interface{}) {
t := reflect.TypeOf(val)
if t.Kind() == reflect.Func {
L.PushGoFunction(luar.GoLuaFunc(L, val))
} else {
luar.GoToLua(L, t, reflect.ValueOf(val), true)
}
L.SetGlobal(name)
}
开发者ID:Ambrevar,项目名称:Demlo,代码行数:12,代码来源:luascript.go
示例20: proxy__eq
func proxy__eq(L *lua.State) int {
v1, t1 := valueOfProxy(L, 1)
v2, t2 := valueOfProxy(L, 2)
if t1 != t2 {
RaiseError(L, sprintf("mismatched types %s and %s", t1, t2))
}
L.PushBoolean(v1.Interface() == v2.Interface())
return 1
}
开发者ID:imvu,项目名称:Tetra,代码行数:9,代码来源:luar.go
注:本文中的github.com/aarzilli/golua/lua.State类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论