napi

package
v0.0.0-...-564e5ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPPTypeToTS

func CPPTypeToTS(t string) (string, bool)

Types

type ArgHelpers

type ArgHelpers struct {
	FFIType     string
	CGoWrapType string
	OGGoType    string
	Name        string
	ASTField    *ast.Field
}

type CPPArg

type CPPArg struct {
	TypeQualifier *string
	IsPrimitive   bool
	Type          *string
	RefDecl       *string
	Ident         *string
	DefaultValue  *CPPArgDefault
}

type CPPArgDefault

type CPPArgDefault struct {
	Val *string
}

type CPPClass

type CPPClass struct {
	NameSpace    *string
	FieldDecl    *[]*CPPFieldDecl
	FriendDecl   *[]*CPPFriend
	Decl         *[]*ParsedClassDecl
	TemplateDecl *[]*TemplateMethod
}

type CPPFieldDecl

type CPPFieldDecl struct {
	Ident         *string
	Args          *[]*CPPArg
	Returns       *CPPType
	TypeQualifier *string
}

type CPPFriend

type CPPFriend struct {
	Ident          *string
	QualifiedIdent *QualifiedIdentifier
	IsClass        bool
	Type           *CPPType
	FuncDecl       *CPPFriendFunc
}

type CPPFriendFunc

type CPPFriendFunc struct {
	QualifiedIdent *QualifiedIdentifier
	Args           *[]*CPPArg
}

type CPPMethod

type CPPMethod struct {
	Ident        *string
	Overloads    []*[]*CPPArg
	Returns      *string
	ExpectedArgs int
}

type CPPType

type CPPType struct {
	FullType     *string
	Scope        *string
	Name         *string
	NameSpace    *string
	TemplateType *[]*TemplateArg
}

type ClassOpts

type ClassOpts struct {
	Fields             []FnOpts `yaml:"fields"`
	FinalizerTransform string   `yaml:"finalizer_transform"`
	Methods            []FnOpts `yaml:"methods"`
	ForcedMethods      []FnOpts `yaml:"forced_methods"`
	Constructor        string   `yaml:"constructor"`
}

type Config

type Config struct {
	Packages []*PackageConfig `yaml:"packages"`
}

func (Config) PackageConfig

func (c Config) PackageConfig(packagePath string) *PackageConfig

func (Config) PackageNames

func (c Config) PackageNames() []string

type EnumField

type EnumField struct {
	Name string
	Val  string
}

type FnArg

type FnArg struct {
	Name   string `yaml:"name"`
	TSType string `yaml:"ts_type"`
}

type FnOpts

type FnOpts struct {
	Name          string   `yaml:"name"`
	Args          []FnArg  `yaml:"args"`
	JSWrapperName string   `yaml:"js_wrapper_name"`
	JSWrapperAlts []string `yaml:"js_wrapper_alts"`
	FnBody        string   `yaml:"body"`
	IsVoid        bool     `yaml:"is_void"`
	TSReturnType  string   `yaml:"ts_return_type"`
}

type JSWrapperOpts

type JSWrapperOpts struct {
	AddonPath      string `yaml:"addon_path"`
	WrapperOutPath string `yaml:"wrapper_out_path"`
	// specifies whether gen JS/TS wrapper code
	EnvType string `yaml:"env_type"`
}

type MethodTransforms

type MethodTransforms struct {
	ArgCount           int               `yaml:"arg_count"`
	ArgCheckTransforms string            `yaml:"arg_check_transforms"`
	ReturnTransforms   string            `yaml:"return_transforms"`
	ArgTransforms      map[string]string `yaml:"arg_transforms"`
}

type PackageConfig

type PackageConfig struct {
	// The package path just like you would import it in Go
	Path string `yaml:"path"`

	// Where this output should be written to.
	// If you specify a folder it will be written to a file `index.ts` within that folder. By default it is written into the Golang package folder.
	BindingsOutPath string        `yaml:"bindings_out_path"`
	HeaderOutPath   string        `yaml:"header_out_path"`
	JSWrapperOpts   JSWrapperOpts `yaml:"js_wrapper_opts"`

	// Customize the indentation (use \t if you want tabs)
	Indent string `yaml:"indent"`

	// Specify your own custom type translations, useful for custom types, `time.Time` and `null.String`.
	// Be default unrecognized types will be output as `any /* name */`.
	TypeMappings map[string]TypeMap `yaml:"type_mappings"`

	TypeHandlers map[string]TypeHandler `yaml:"type_handlers"`

	ClassOpts map[string]ClassOpts `yaml:"class_opts"`

	// This content will be put at the top of the output Typescript file.
	// You would generally use this to import custom types.
	HeaderFrontmatter   string `yaml:"header_frontmatter"`
	BindingsFrontmatter string `yaml:"bindings_frontmatter"`

	IgnoredMethods []string `yaml:"ignored_methods"`

	GlobalForcedMethods []FnOpts `yaml:"global_methods"`

	GlobalTypeOutTransforms map[string]string `yaml:"global_type_out_transforms"`

	MethodTransforms map[string]MethodTransforms `yaml:"method_transforms"`

	GlobalVars  string            `yaml:"global_vars"`
	HelperFuncs map[string]string `yaml:"helper_funcs"`
}

func (PackageConfig) IsEnvTS

func (c PackageConfig) IsEnvTS() bool

func (PackageConfig) IsFieldWrapped

func (c PackageConfig) IsFieldWrapped(className string, fnName string) bool

func (PackageConfig) IsMethodIgnored

func (c PackageConfig) IsMethodIgnored(name string) bool

func (PackageConfig) IsMethodWrapped

func (c PackageConfig) IsMethodWrapped(className string, fnName string) bool

func (PackageConfig) ResolvedBindingsImportPath

func (c PackageConfig) ResolvedBindingsImportPath(packageDir string) string

func (PackageConfig) ResolvedBindingsOutPath

func (c PackageConfig) ResolvedBindingsOutPath(packageDir string) string

func (PackageConfig) ResolvedHeaderOutPath

func (c PackageConfig) ResolvedHeaderOutPath(packageDir string) string

func (PackageConfig) ResolvedWrapperOutPath

func (c PackageConfig) ResolvedWrapperOutPath(packageDir string) string

func (PackageConfig) TypeHasHandler

func (c PackageConfig) TypeHasHandler(name string) *TypeHandler

type PackageGenerator

type PackageGenerator struct {
	NameSpace *string
	Name      *string
	Path      *string
	RootNode  *sitter.Node
	Input     *[]byte
	// contains filtered or unexported fields
}

Responsible for generating the code for an input package

func (*PackageGenerator) Generate

func (g *PackageGenerator) Generate() (string, string, string, error)

func (*PackageGenerator) WriteEnvClassWrapper

func (g *PackageGenerator) WriteEnvClassWrapper(className string, class *CPPClass, methods map[string]*CPPMethod, processedMethods map[string]*CPPMethod) string

func (*PackageGenerator) WriteEnvExports

func (g *PackageGenerator) WriteEnvExports(classes map[string]*CPPClass, methods map[string]*CPPMethod, processedMethods map[string]*CPPMethod) string

func (*PackageGenerator) WriteEnvImports

func (g *PackageGenerator) WriteEnvImports(classes map[string]*CPPClass, methods map[string]*CPPMethod, processedMethods map[string]*CPPMethod) string

func (*PackageGenerator) WriteEnvWrappedFns

func (g *PackageGenerator) WriteEnvWrappedFns(methods map[string]*CPPMethod, processedMethods map[string]*CPPMethod, classes map[string]*CPPClass) string

func (*PackageGenerator) WriteEnvWrapper

func (g *PackageGenerator) WriteEnvWrapper(sb *strings.Builder, classes map[string]*CPPClass, methods map[string]*CPPMethod, processedMethods map[string]*CPPMethod)

type ParsedClassDecl

type ParsedClassDecl struct {
	Ident        *string
	Args         *[]*CPPArg
	Returns      *string
	Explicit     bool
	Virtual      bool
	IsDestructor bool
}

type ParsedMethod

type ParsedMethod struct {
	Ident   *string
	Args    *[]*CPPArg
	Returns *string
}

type PreprocessBlock

type PreprocessBlock struct {
	Node    *sitter.Node
	RawArgs *string
	RawRes  *string
	Expr    bool
}

type QualifiedIdentifier

type QualifiedIdentifier struct {
	Scope        *string
	Name         *string
	TemplateArgs *[]*TemplateArg
}

type ResHelpers

type ResHelpers struct {
	FFIType     string
	CGoWrapType string
	OGGoType    string
	ASTType     *ast.Expr
}

type TSGo

type TSGo struct {
	// contains filtered or unexported fields
}

Generator for one or more input packages, responsible for linking them together if necessary.

func New

func New(config *Config) *TSGo

func (*TSGo) Generate

func (g *TSGo) Generate() error

type TemplateArg

type TemplateArg struct {
	Identifier *string
}

type TemplateDecl

type TemplateDecl struct {
	Args *[]*TemplateDeclArg
}

type TemplateDeclArg

type TemplateDeclArg struct {
	Identifier *string
	MetaType   *string
}

type TemplateMethod

type TemplateMethod struct {
	TemplateDecl          *TemplateDecl
	Returns               *string
	PointerMethod         bool
	StorageClassSpecifier *string
	RefDecl               *string
	Ident                 *string
	Args                  *[]*CPPArg
	TypeQualifier         *string
}

type TypeHandler

type TypeHandler struct {
	OutType string `yaml:"out_type"`
	OutVar  string `yaml:"out_var"`
	Handler string `yaml:"handler"`
}

type TypeMap

type TypeMap struct {
	TSType   string `yaml:"ts"`
	NapiType string `yaml:"napi"`
	CastsTo  string `yaml:"casts_to"`
	CastNapi string `yaml:"cast_napi"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL