OpenLibraries opens all standard libraries. Alternatively, the host program can open them individually by using Require to call BaseOpen (for the basic library), PackageOpen (for the package library), CoroutineOpen (for the coroutine library), StringOpen (for the string library), TableOpen (for the
(l *State, preloaded ...RegistryFunction)
| 29 | // Except for the basic and the package libraries, each library provides all |
| 30 | // its functions as fields of a global table or as methods of its objects. |
| 31 | func OpenLibraries(l *State, preloaded ...RegistryFunction) { |
| 32 | libs := []RegistryFunction{ |
| 33 | {"_G", BaseOpen}, |
| 34 | {"package", PackageOpen}, |
| 35 | // {"coroutine", CoroutineOpen}, |
| 36 | {"table", TableOpen}, |
| 37 | {"io", IOOpen}, |
| 38 | {"os", OSOpen}, |
| 39 | {"string", StringOpen}, |
| 40 | {"bit32", Bit32Open}, |
| 41 | {"math", MathOpen}, |
| 42 | {"debug", DebugOpen}, |
| 43 | } |
| 44 | for _, lib := range libs { |
| 45 | Require(l, lib.Name, lib.Function, true) |
| 46 | l.Pop(1) |
| 47 | } |
| 48 | SubTable(l, RegistryIndex, "_PRELOAD") |
| 49 | for _, lib := range preloaded { |
| 50 | l.PushGoFunction(lib.Function) |
| 51 | l.SetField(-2, lib.Name) |
| 52 | } |
| 53 | l.Pop(1) |
| 54 | } |