-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path13_nil.go
56 lines (47 loc) · 1.19 KB
/
13_nil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Dvacátá sedmá část
// Skriptovací jazyk Lua v aplikacích naprogramovaných v Go
// https://www.root.cz/clanky/skriptovaci-jazyk-lua-v-aplikacich-naprogramovanych-v-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z dvacáté sedmé části:
// https://github.com/tisnik/go-root/blob/master/article_27/README.md
//
// Demonstrační příklad číslo 13:
// Hodnota nil.
package main
import (
"github.com/yuin/gopher-lua"
"log"
)
// LuaSource contains name of file containing Lua script
const LuaSource = "return_nil.lua"
func main() {
luaVM := lua.NewState()
log.Println("Lua VM has been initialized")
defer func() {
luaVM.Close()
log.Println("Lua VM has been closed")
}()
err := luaVM.DoFile(LuaSource)
if err != nil {
log.Fatal(err)
}
err = luaVM.CallByParam(lua.P{
Fn: luaVM.GetGlobal("return_nil"),
NRet: 1,
Protect: true,
})
if err != nil {
log.Fatal(err)
}
ret := luaVM.Get(-1)
luaVM.Pop(1)
println("Type", ret.Type())
println("Value", ret.String())
println("is nil?", ret == lua.LNil)
}