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
### 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
L := luajit.New()
L := luajit.New() // or luajit.New(false)
defer L.Close()
defer L.Cleanup()
```
@ -428,4 +428,4 @@ Sandbox management:
```go
sandbox := luajit.NewSandbox()
defer sandbox.Close()
```
```

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:
```go
L := luajit.New()
L := luajit.New() // pass false to not load standard libs
defer L.Close()
defer L.Cleanup()
@ -212,4 +212,4 @@ Check out the tests in the repository - they're full of examples. If you're stuc
## License
MIT Licensed - do whatever you want with it!
MIT Licensed - do whatever you want with it!

View File

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