github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/lib.go (about) 1 package lib 2 3 import ( 4 "github.com/arnodel/golua/lib/base" 5 "github.com/arnodel/golua/lib/coroutine" 6 "github.com/arnodel/golua/lib/debuglib" 7 "github.com/arnodel/golua/lib/golib" 8 "github.com/arnodel/golua/lib/iolib" 9 "github.com/arnodel/golua/lib/mathlib" 10 "github.com/arnodel/golua/lib/oslib" 11 "github.com/arnodel/golua/lib/packagelib" 12 "github.com/arnodel/golua/lib/runtimelib" 13 "github.com/arnodel/golua/lib/stringlib" 14 "github.com/arnodel/golua/lib/tablelib" 15 "github.com/arnodel/golua/lib/utf8lib" 16 rt "github.com/arnodel/golua/runtime" 17 ) 18 19 func LoadLibs(r *rt.Runtime, loaders ...packagelib.Loader) func() { 20 var cleanups []func() 21 for _, loader := range loaders { 22 cleanup := loader.Run(r) 23 if cleanup != nil { 24 cleanups = append(cleanups, cleanup) 25 } 26 } 27 return func() { 28 for i := len(cleanups) - 1; i >= 0; i-- { 29 cleanups[i]() 30 } 31 } 32 } 33 34 func LoadAll(r *rt.Runtime) func() { 35 return LoadLibs( 36 r, 37 base.LibLoader, 38 packagelib.LibLoader, 39 coroutine.LibLoader, 40 stringlib.LibLoader, 41 tablelib.LibLoader, 42 mathlib.LibLoader, 43 iolib.LibLoader, 44 utf8lib.LibLoader, 45 oslib.LibLoader, 46 debuglib.LibLoader, 47 golib.LibLoader, 48 runtimelib.LibLoader, 49 ) 50 }