MCPcopy Create free account
hub / github.com/sipcapture/homer / ScanLuaCode

Function ScanLuaCode

src/scripting/scriptengine.go:61–94  ·  view source on GitHub ↗

ScanLuaCode scans the script folder for Lua files

(folder string)

Source from the content-addressed store, hash-verified

59
60// ScanLuaCode scans the script folder for Lua files
61func ScanLuaCode(folder string) (*bytes.Buffer, error) {
62 buf := bytes.NewBuffer(nil)
63
64 if folder == "" {
65 return buf, nil
66 }
67
68 dir, err := os.ReadDir(folder)
69 if err != nil {
70 return nil, err
71 }
72
73 for _, file := range dir {
74 if file.IsDir() {
75 continue
76 }
77 name := file.Name()
78 if !strings.HasSuffix(name, ".lua") {
79 continue
80 }
81 path := filepath.Join(folder, name)
82 f, err := os.Open(path)
83 if err != nil {
84 return nil, err
85 }
86 _, err = io.Copy(buf, f)
87 f.Close()
88 if err != nil {
89 return nil, err
90 }
91 }
92
93 return buf, nil
94}
95
96// ExtractFunctions extracts function names from Lua code
97func ExtractFunctions(r io.Reader) []string {

Callers 2

NewLuaEngineFunction · 0.85
ReloadMethod · 0.85

Calls 2

CloseMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected