From 44337fffe3c8b11f276a102d1395612508fe79b6 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Sat, 29 Mar 2025 08:29:46 -0500 Subject: [PATCH] add flag for std libs --- DOCS.md | 6 +++--- README.md | 4 ++-- wrapper.go | 10 +++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/DOCS.md b/DOCS.md index 1d714c8..f877387 100644 --- a/DOCS.md +++ b/DOCS.md @@ -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() -``` \ No newline at end of file +``` diff --git a/README.md b/README.md index b51e094..0830fa3 100644 --- a/README.md +++ b/README.md @@ -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! \ No newline at end of file +MIT Licensed - do whatever you want with it! diff --git a/wrapper.go b/wrapper.go index ea2247f..f4e0a54 100644 --- a/wrapper.go +++ b/wrapper.go @@ -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} }