c/lua:thread

This commit is contained in:
luoliwoshang
2024-09-07 18:54:09 +08:00
parent 3c588e67b8
commit 743ddf83c1
2 changed files with 56 additions and 5 deletions

View File

@@ -0,0 +1,44 @@
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/lua"
)
func pushThread(state *lua.State, name string) {
isMain := state.Pushthread()
if isMain != 0 {
c.Printf(c.Str("%s Thread is main\n"), c.AllocaCStr(name))
} else {
c.Printf(c.Str("%s Thread is not main\n"), c.AllocaCStr(name))
}
}
func main() {
L := lua.Newstate()
defer L.Close()
L.Openlibs()
pushThread(L, "main")
L.Pop(1)
newThread := L.Newthread()
pushThread(newThread, "newthread")
state := newThread.Tothread(-1)
if newThread == state {
c.Printf(c.Str("Successfully retrieved thread from stack\n"))
}
status := state.Status()
c.Printf(c.Str("New thread status: %d"), status)
if L.Closethread(newThread) != lua.OK {
println("Failed to close thread status %d", state.Status())
}
}
/* Expected output:
main Thread is main
newthread Thread is not main
Successfully retrieved thread from stack
New thread status: 0
*/