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

Method RegisterModule

auxlib.go:289–305  ·  view source on GitHub ↗

* }}} */ * register operations {{{ */

(name string, funcs map[string]LGFunction)

Source from the content-addressed store, hash-verified

287/* register operations {{{ */
288
289func (ls *LState) RegisterModule(name string, funcs map[string]LGFunction) LValue {
290 tb := ls.FindTable(ls.Get(RegistryIndex).(*LTable), "_LOADED", 1)
291 mod := ls.GetField(tb, name)
292 if mod.Type() != LTTable {
293 newmod := ls.FindTable(ls.Get(GlobalsIndex).(*LTable), name, len(funcs))
294 if newmodtb, ok := newmod.(*LTable); !ok {
295 ls.RaiseError("name conflict for module(%v)", name)
296 } else {
297 for fname, fn := range funcs {
298 newmodtb.RawSetString(fname, ls.NewFunction(fn))
299 }
300 ls.SetField(tb, name, newmodtb)
301 return newmodtb
302 }
303 }
304 return mod
305}
306
307func (ls *LState) SetFuncs(tb *LTable, funcs map[string]LGFunction, upvalues ...LValue) *LTable {
308 for fname, fn := range funcs {

Callers 10

OpenPackageFunction · 0.80
OpenOsFunction · 0.80
OpenBaseFunction · 0.80
OpenMathFunction · 0.80
OpenIoFunction · 0.80
OpenStringFunction · 0.80
OpenDebugFunction · 0.80
OpenCoroutineFunction · 0.80
OpenTableFunction · 0.80
OpenChannelFunction · 0.80

Calls 8

FindTableMethod · 0.95
GetMethod · 0.95
GetFieldMethod · 0.95
RaiseErrorMethod · 0.95
NewFunctionMethod · 0.95
SetFieldMethod · 0.95
RawSetStringMethod · 0.80
TypeMethod · 0.65

Tested by

no test coverage detected