PackageOpen opens the package library. Usually passed to Require.
(l *State)
| 150 | |
| 151 | // PackageOpen opens the package library. Usually passed to Require. |
| 152 | func 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 | } |
nothing calls this directly
no test coverage detected