Require calls function f with string name as an argument and sets the call result in package.loaded[name], as if that function had been called through require. If global is true, also stores the result into global name. Leaves a copy of that result on the stack.
(l *State, name string, f Function, global bool)
| 439 | // |
| 440 | // Leaves a copy of that result on the stack. |
| 441 | func Require(l *State, name string, f Function, global bool) { |
| 442 | l.PushGoFunction(f) |
| 443 | l.PushString(name) // argument to f |
| 444 | l.Call(1, 1) // open module |
| 445 | SubTable(l, RegistryIndex, "_LOADED") |
| 446 | l.PushValue(-2) // make copy of module (call result) |
| 447 | l.SetField(-2, name) // _LOADED[name] = module |
| 448 | l.Pop(1) // remove _LOADED table |
| 449 | if global { |
| 450 | l.PushValue(-1) // copy of module |
| 451 | l.SetGlobal(name) // _G[name] = module |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | func NewLibraryTable(l *State, functions []RegistryFunction) { l.CreateTable(0, len(functions)) } |
| 456 |
no test coverage detected