add flag for std libs

This commit is contained in:
Sky Johnson 2025-03-29 08:29:46 -05:00
parent 0756cabcaa
commit 44337fffe3
3 changed files with 12 additions and 8 deletions

View File

@ -3,9 +3,9 @@
## State Management ## State Management
### New() *State ### New() *State
Creates a new Lua state with all standard libraries loaded. New creates a new Lua state with optional standard libraries; true if not specified
```go ```go
L := luajit.New() L := luajit.New() // or luajit.New(false)
defer L.Close() defer L.Close()
defer L.Cleanup() defer L.Cleanup()
``` ```

View File

@ -22,7 +22,7 @@ You'll need LuaJIT's development files, but don't worry - we include libraries f
Here's the simplest thing you can do: Here's the simplest thing you can do:
```go ```go
L := luajit.New() L := luajit.New() // pass false to not load standard libs
defer L.Close() defer L.Close()
defer L.Cleanup() defer L.Cleanup()

View File

@ -55,13 +55,17 @@ type State struct {
L *C.lua_State L *C.lua_State
} }
// New creates a new Lua state with all standard libraries loaded // New creates a new Lua state with optional standard libraries; true if not specified
func New() *State { func New(openLibs ...bool) *State {
L := C.luaL_newstate() L := C.luaL_newstate()
if L == nil { if L == nil {
return nil return nil
} }
if len(openLibs) == 0 || openLibs[0] {
C.luaL_openlibs(L) C.luaL_openlibs(L)
}
return &State{L: L} return &State{L: L}
} }