* }}} */ * load lib {{{ */
(L *LState)
| 482 | /* load lib {{{ */ |
| 483 | |
| 484 | func 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 | |
| 524 | var loopdetection = &LUserData{} |
| 525 |
nothing calls this directly
no test coverage detected
searching dependent graphs…