@@ -19,9 +19,14 @@ const (
19
19
ChannelLibName = "channel"
20
20
// CoroutineLibName is the name of the coroutine Library.
21
21
CoroutineLibName = "coroutine"
22
+ // BaseLibName is here for consistency; the base functions have no namespace/library.
23
+ BaseLibName = "_baseLib"
24
+ // LoadLibName is here for consistency; the loading system has no namespace/library.
25
+ LoadLibName = "_loadLib"
22
26
)
23
27
24
- // LuaLibs are the built-in Gopher-lua libraries as opened by LState.OpenLibs().
28
+ // LuaLibs are the built-in Gopher-lua libraries as opened by LState.OpenLibs(),
29
+ // including Base/Load.
25
30
var LuaLibs = map [string ]LGFunction {
26
31
TabLibName : OpenTable ,
27
32
IoLibName : OpenIo ,
@@ -31,31 +36,23 @@ var LuaLibs = map[string]LGFunction{
31
36
DebugLibName : OpenDebug ,
32
37
ChannelLibName : OpenChannel ,
33
38
CoroutineLibName : OpenCoroutine ,
39
+ BaseLibName : OpenBase ,
40
+ LoadLibName : OpenLoad ,
34
41
}
35
42
36
- // OpenLibs loads the built-in libraries. It is equivalent to iterating over
37
- // LuaLibs, preloading each, and requiring each to its own name .
43
+ // OpenLibs loads the built-in libraries. It is equivalent to running OpenLoad,
44
+ // then OpenBase, then iterating over the other OpenXXX functions in any order .
38
45
func (ls * LState ) OpenLibs () {
39
- // TODO: Remove when ready.
40
- ls .oldOpenLibs ()
41
-
46
+ // NB: Map iteration order in Go is deliberately randomised, so must open Load/Base
47
+ // prior to iterating.
48
+ OpenLoad (ls )
49
+ OpenBase (ls )
42
50
for name , loader := range LuaLibs {
51
+ if name == BaseLibName || name == LoadLibName {
52
+ continue
53
+ }
43
54
ls .PreloadModule (name , loader )
55
+ // TODO: Are all built-ins normally "required"
44
56
ls .DoString (fmt .Sprintf (`%s = require "%s"` , name , name ))
45
57
}
46
58
}
47
-
48
- /// Deprecating for linit.go/OpenLibs for https://github.com/yuin/gopher-lua/issues/55
49
- func (ls * LState ) oldOpenLibs () {
50
- // loadlib must be loaded 1st
51
- loadOpen (ls )
52
- baseOpen (ls )
53
- //coroutineOpen(ls)
54
- //ioOpen(ls)
55
- //stringOpen(ls)
56
- //tableOpen(ls)
57
- //mathOpen(ls)
58
- //osOpen(ls)
59
- //debugOpen(ls)
60
- //channelOpen(ls)
61
- } // */
0 commit comments