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

Function loFindFile

loadlib.go:30–47  ·  view source on GitHub ↗
(L *LState, name, pname string)

Source from the content-addressed store, hash-verified

28}
29
30func loFindFile(L *LState, name, pname string) (string, string) {
31 name = strings.Replace(name, ".", string(os.PathSeparator), -1)
32 lv := L.GetField(L.GetField(L.Get(EnvironIndex), "package"), pname)
33 path, ok := lv.(LString)
34 if !ok {
35 L.RaiseError("package.%s must be a string", pname)
36 }
37 messages := []string{}
38 for _, pattern := range strings.Split(string(path), ";") {
39 luapath := strings.Replace(pattern, "?", name, -1)
40 if _, err := os.Stat(luapath); err == nil {
41 return luapath, ""
42 } else {
43 messages = append(messages, err.Error())
44 }
45 }
46 return "", strings.Join(messages, "\n\t")
47}
48
49func OpenPackage(L *LState) int {
50 packagemod := L.RegisterModule(LoadLibName, loFuncs)

Callers 1

loLoaderLuaFunction · 0.85

Calls 5

ErrorMethod · 0.65
ReplaceMethod · 0.45
GetFieldMethod · 0.45
GetMethod · 0.45
RaiseErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…