llgo/c/lua:link style

This commit is contained in:
luoliwoshang
2024-07-13 22:57:01 +08:00
parent 9edeee4b3f
commit de4b5b70da
12 changed files with 225 additions and 183 deletions

View File

@@ -8,29 +8,29 @@ import (
)
func main() {
L := lua.NewState()
L := lua.Newstate()
defer L.Close()
L.OpenLibs()
if res := L.LoadString(c.Str("function doubleNumber(x) return x * 2 end")); res != lua.OK {
c.Printf(c.Str("error: %s\n"), L.ToString(-1))
L.Openlibs()
if res := L.Loadstring(c.Str("function doubleNumber(x) return x * 2 end")); res != lua.OK {
c.Printf(c.Str("error: %s\n"), L.Tostring(-1))
}
if res := L.PCall(0, 0, 0); res != lua.OK {
c.Printf(c.Str("error: %s\n"), L.ToString(-1))
if res := L.Pcall(0, 0, 0); res != lua.OK {
c.Printf(c.Str("error: %s\n"), L.Tostring(-1))
}
L.GetGlobal(c.Str("doubleNumber"))
L.PushNumber(10)
L.Getglobal(c.Str("doubleNumber"))
L.Pushnumber(10)
if res := L.PCall(1, 1, 0); res != lua.OK {
c.Printf(c.Str("error: %s\n"), L.ToString(-1))
if res := L.Pcall(1, 1, 0); res != lua.OK {
c.Printf(c.Str("error: %s\n"), L.Tostring(-1))
}
if res := L.IsNumber(-1); res != 0 {
result := L.ToInteger(-1)
if res := L.Isnumber(-1); res != 0 {
result := L.Tointeger(-1)
c.Printf(c.Str("result: %lld\n"), result)
} else {
c.Printf(c.Str("error: %s\n"), L.ToString(-1))
c.Printf(c.Str("error: %s\n"), L.Tostring(-1))
}
}