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

Function Require

auxiliary.go:441–453  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

439//
440// Leaves a copy of that result on the stack.
441func 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
455func NewLibraryTable(l *State, functions []RegistryFunction) { l.CreateTable(0, len(functions)) }
456

Callers 1

OpenLibrariesFunction · 0.85

Calls 8

SubTableFunction · 0.85
PushGoFunctionMethod · 0.80
PushStringMethod · 0.80
CallMethod · 0.80
PushValueMethod · 0.80
SetFieldMethod · 0.80
PopMethod · 0.80
SetGlobalMethod · 0.80

Tested by

no test coverage detected