MCPcopy Index your code
hub / github.com/yuin/gopher-lua / loModule

Function loModule

baselib.go:484–522  ·  view source on GitHub ↗

* }}} */ * load lib {{{ */

(L *LState)

Source from the content-addressed store, hash-verified

482/* load lib {{{ */
483
484func loModule(L *LState) int {
485 name := L.CheckString(1)
486 loaded := L.GetField(L.Get(RegistryIndex), "_LOADED")
487 tb := L.GetField(loaded, name)
488 if _, ok := tb.(*LTable); !ok {
489 tb = L.FindTable(L.Get(GlobalsIndex).(*LTable), name, 1)
490 if tb == LNil {
491 L.RaiseError("name conflict for module: %v", name)
492 }
493 L.SetField(loaded, name, tb)
494 }
495 if L.GetField(tb, "_NAME") == LNil {
496 L.SetField(tb, "_M", tb)
497 L.SetField(tb, "_NAME", LString(name))
498 names := strings.Split(name, ".")
499 pname := ""
500 if len(names) > 1 {
501 pname = strings.Join(names[:len(names)-1], ".") + "."
502 }
503 L.SetField(tb, "_PACKAGE", LString(pname))
504 }
505
506 caller := L.currentFrame.Parent
507 if caller == nil {
508 L.RaiseError("no calling stack.")
509 } else if caller.Fn.IsG {
510 L.RaiseError("module() can not be called from GFunctions.")
511 }
512 L.SetFEnv(caller.Fn, tb)
513
514 top := L.GetTop()
515 for i := 2; i <= top; i++ {
516 L.Push(L.Get(i))
517 L.Push(tb)
518 L.Call(1, 0)
519 }
520 L.Push(tb)
521 return 1
522}
523
524var loopdetection = &LUserData{}
525

Callers

nothing calls this directly

Calls 11

LStringTypeAlias · 0.85
CheckStringMethod · 0.80
FindTableMethod · 0.80
PushMethod · 0.65
GetFieldMethod · 0.45
GetMethod · 0.45
RaiseErrorMethod · 0.45
SetFieldMethod · 0.45
SetFEnvMethod · 0.45
GetTopMethod · 0.45
CallMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…