MCPcopy Index your code
hub / github.com/zalando/skipper / withSymbols

Method withSymbols

script/module.go:52–76  ·  view source on GitHub ↗

withSymbols returns copy of module with selected symbols

(L *lua.LState, enabledSymbols []string)

Source from the content-addressed store, hash-verified

50
51// withSymbols returns copy of module with selected symbols
52func (m luaModule) withSymbols(L *lua.LState, enabledSymbols []string) luaModule {
53 // gopher-lua does not have API to select enabled symbols,
54 // see https://github.com/yuin/gopher-lua/discussions/393
55 //
56 // Instead collect symbols to disable as difference
57 // between all and enabled module symbols
58 allSymbols := make(map[string]struct{})
59
60 m.load(L)
61 m.table(L).ForEach(func(k, _ lua.LValue) {
62 if name, ok := k.(lua.LString); ok {
63 allSymbols[name.String()] = struct{}{}
64 }
65 })
66
67 for _, s := range enabledSymbols {
68 delete(allSymbols, s)
69 }
70
71 result := luaModule{m.name, m.loader, nil}
72 for s := range allSymbols {
73 result.disabledSymbols = append(result.disabledSymbols, s)
74 }
75 return result
76}
77
78func (m luaModule) table(L *lua.LState) *lua.LTable {
79 name := m.name

Callers 1

initScriptMethod · 0.80

Calls 3

loadMethod · 0.95
tableMethod · 0.95
StringMethod · 0.65

Tested by

no test coverage detected