MCPcopy Index your code
hub / github.com/Shopify/go-lua / PackageOpen

Function PackageOpen

load.go:152–191  ·  view source on GitHub ↗

PackageOpen opens the package library. Usually passed to Require.

(l *State)

Source from the content-addressed store, hash-verified

150
151// PackageOpen opens the package library. Usually passed to Require.
152func PackageOpen(l *State) int {
153 NewLibrary(l, packageLibrary)
154 createSearchersTable(l)
155 l.SetField(-2, "searchers")
156 setPath(l, "path", "LUA_PATH", defaultPath)
157 l.PushString(fmt.Sprintf("%c\n%c\n?\n!\n-\n", filepath.Separator, pathListSeparator))
158 l.SetField(-2, "config")
159 SubTable(l, RegistryIndex, "_LOADED")
160 l.SetField(-2, "loaded")
161 SubTable(l, RegistryIndex, "_PRELOAD")
162 l.SetField(-2, "preload")
163 l.PushGlobalTable()
164 l.PushValue(-2)
165 SetFunctions(l, []RegistryFunction{{"require", func(l *State) int {
166 name := CheckString(l, 1)
167 l.SetTop(1)
168 l.Field(RegistryIndex, "_LOADED")
169 l.Field(2, name)
170 if l.ToBoolean(-1) {
171 return 1
172 }
173 l.Pop(1)
174 findLoader(l, name)
175 l.PushString(name)
176 l.Insert(-2)
177 l.Call(2, 1)
178 if !l.IsNil(-1) {
179 l.SetField(2, name)
180 }
181 l.Field(2, name)
182 if l.IsNil(-1) {
183 l.PushBoolean(true)
184 l.PushValue(-1)
185 l.SetField(2, name)
186 }
187 return 1
188 }}}, 1)
189 l.Pop(1)
190 return 1
191}

Callers

nothing calls this directly

Calls 15

NewLibraryFunction · 0.85
createSearchersTableFunction · 0.85
setPathFunction · 0.85
SubTableFunction · 0.85
SetFunctionsFunction · 0.85
CheckStringFunction · 0.85
findLoaderFunction · 0.85
SetFieldMethod · 0.80
PushStringMethod · 0.80
PushGlobalTableMethod · 0.80
PushValueMethod · 0.80
SetTopMethod · 0.80

Tested by

no test coverage detected