* }}} */ * register operations {{{ */
(name string, funcs map[string]LGFunction)
| 287 | /* register operations {{{ */ |
| 288 | |
| 289 | func (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 | |
| 307 | func (ls *LState) SetFuncs(tb *LTable, funcs map[string]LGFunction, upvalues ...LValue) *LTable { |
| 308 | for fname, fn := range funcs { |
no test coverage detected