Files
napi-go/boolean.go
Matheus Sampaio Queiroga 793989dc2a Add docs and remove threadsafe_function
- Add new function to ValueType conversion
- Add more docs to functions and minor changes
- rename entry to module
- don't expose Value and Env structs.

Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-05-17 02:13:46 -03:00

27 lines
976 B
Go

package napi
import "sirherobrine23.com.br/Sirherobrine23/napi-go/internal/napi"
type Boolean struct{ value }
// Convert [ValueType] to [*Boolean]
func ToBoolean(o ValueType) *Boolean { return &Boolean{o} }
// CreateBoolean creates a new Boolean value in the given N-API environment.
// It takes an EnvType representing the N-API environment and a Go bool value.
// Returns a pointer to a Boolean object representing the value in the N-API environment,
// or an error if the creation fails.
func CreateBoolean(env EnvType, value bool) (*Boolean, error) {
v, err := mustValueErr(napi.GetBoolean(env.NapiValue(), value))
if err != nil {
return nil, err
}
return ToBoolean(N_APIValue(env, v)), nil
}
// Value retrieves the boolean value represented by the Boolean object.
// It returns the Go bool value and an error if the underlying N-API call fails.
func (bo *Boolean) Value() (bool, error) {
return mustValueErr(napi.GetValueBool(bo.NapiEnv(), bo.NapiValue()))
}