progpAPI

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

#ProgpAPI

Introduction

This module contains the core API for the script engine and custom functions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchFatalErrors

func CatchFatalErrors()

func ConfigRegisterScriptEngineBuilder

func ConfigRegisterScriptEngineBuilder(engineName string, builder ScriptEngineBuilder)

func DeclareBackgroundTaskEnded

func DeclareBackgroundTaskEnded()

func DeclareBackgroundTaskStarted

func DeclareBackgroundTaskStarted()

func DynamicCallFunction

func DynamicCallFunction(toCall any, callArgs []reflect.Value) (result []reflect.Value, errorMsg string)

func EndOfAllBackgroundTasks

func EndOfAllBackgroundTasks()

func ExecuteScriptContent

func ExecuteScriptContent(scriptContent, scriptOrigin string, scriptEngine ScriptEngine)

func ForEachScriptEngine

func ForEachScriptEngine(f func(engine ScriptEngine))

func ForceExitingVM

func ForceExitingVM()

ForceExitingVM allows stopping the process without doing an os.exit. It's a requirement if profiling the memory, since without that, the log file isn't correctly flushed.

func GoStringToQuotedString2

func GoStringToQuotedString2(value string) string

func LogScriptError

func LogScriptError(error *ScriptErrorMessage)

func OnUnCatchScriptError

func OnUnCatchScriptError(error *ScriptErrorMessage)

func PauseMs

func PauseMs(timeInMs int)

func ReflectValueToAny

func ReflectValueToAny(resV reflect.Value) any

func SafeGoRoutine

func SafeGoRoutine(f func())

func SetErrorTranslator

func SetErrorTranslator(handler ErrorTranslatorF)

Types

type DisposeSharedResourceF

type DisposeSharedResourceF func(value any)

type EmbeddedFile

type EmbeddedFile struct {
	FS        embed.FS
	InnerPath string
}

func (*EmbeddedFile) Read

func (m *EmbeddedFile) Read() ([]byte, error)

type ErrorTranslatorF

type ErrorTranslatorF func(error *ScriptErrorMessage)

type FunctionGroup

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

func (*FunctionGroup) AddAsyncFunction

func (m *FunctionGroup) AddAsyncFunction(jsName string, goFunctionName string, jsFunction any)

func (*FunctionGroup) AddFunction

func (m *FunctionGroup) AddFunction(javascriptName string, goFunctionName string, goFunctionRef any)

type FunctionModule

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

func (*FunctionModule) AddAsyncFunction

func (m *FunctionModule) AddAsyncFunction(jsName string, goFunctionName string, jsFunction any)

AddAsyncFunction add an async function to a javascript group which name is the name of the go namespace last part.

func (*FunctionModule) AddFunction

func (m *FunctionModule) AddFunction(javascriptName string, goFunctionName string, goFunctionRef any)

AddFunction add a function to a javascript group which name is the name of the go namespace last part.

func (*FunctionModule) DeclareNodeModule

func (m *FunctionModule) DeclareNodeModule(embedded embed.FS, embeddedDirPath string, modName string)

func (*FunctionModule) GetFunctionRegistry

func (m *FunctionModule) GetFunctionRegistry() *FunctionRegistry

func (*FunctionModule) ModName

func (m *FunctionModule) ModName() string

func (*FunctionModule) UseCustomGroup

func (m *FunctionModule) UseCustomGroup(jsGroupName string) *FunctionGroup

UseCustomGroup allows using another javascript group than the default group for this go namespace.

func (*FunctionModule) UseGroupGlobal

func (m *FunctionModule) UseGroupGlobal() *FunctionGroup

UseGroupGlobal allows using the global group where functionsArray directly accessible to javascript scripts without importing them.

type FunctionRegistry

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

func GetFunctionRegistry

func GetFunctionRegistry() *FunctionRegistry

func (*FunctionRegistry) EnableDynamicMode

func (m *FunctionRegistry) EnableDynamicMode(enabled bool)

func (*FunctionRegistry) GetAllFunctions

func (m *FunctionRegistry) GetAllFunctions(sortList bool) []*RegisteredFunction

func (*FunctionRegistry) GetEmbeddedModulesTSX

func (m *FunctionRegistry) GetEmbeddedModulesTSX() map[string]EmbeddedFile

func (*FunctionRegistry) GetNamespaces

func (m *FunctionRegistry) GetNamespaces() map[string]bool

func (*FunctionRegistry) GetRefToFunction

func (m *FunctionRegistry) GetRefToFunction(jsFunctionName string) *RegisteredFunction

func (*FunctionRegistry) IsUsingDynamicMode

func (m *FunctionRegistry) IsUsingDynamicMode() bool

func (*FunctionRegistry) UseGoNamespace

func (m *FunctionRegistry) UseGoNamespace(goNamespace string) *FunctionModule

type ParsedGoFunction

type ParsedGoFunction struct {
	GeneratorUniqName string
	GoFunctionName    string

	ParamTypes          []string
	ParamTypeRefs       []reflect.Type
	CallParamNamespaces []string

	ReturnType        string
	ReturnErrorOffset int

	JsFunctionName string
	JsGroupName    string
}

func ParseGoFunction

func ParseGoFunction(fct *RegisteredFunction) (ParsedGoFunction, error)

func (*ParsedGoFunction) GetGoFunctionName

func (m *ParsedGoFunction) GetGoFunctionName() string

func (*ParsedGoFunction) GetJsFunctionName

func (m *ParsedGoFunction) GetJsFunctionName() string

type RegisteredFunction

type RegisteredFunction struct {
	IsAsync            bool
	Group              string
	JsFunctionName     string
	GoFunctionName     string
	GoFunctionFullName string
	GoFunctionRef      any
	GoFunctionInfos    ParsedGoFunction
}

type ScriptCallback

type ScriptCallback func(error *ScriptErrorMessage)

type ScriptEngine

type ScriptEngine interface {
	// Start the engine, which is call one all is initialized in the Go side.
	Start()

	// GetEngineLanguage allows to know if it' a "javascript" engine or a "python" engine.
	GetEngineLanguage() string

	// GetEngineName the name of the underlying engine. For exemple "progpv8".
	GetEngineName() string

	WaitDebuggerReady()

	// GetInternalEngineVersion the version of the engine used internally.
	// For exemple if it's using Google V8, then return the v8 engine version.
	GetInternalEngineVersion() string

	// ExecuteScript execute a script by giving his content.
	ExecuteScript(scriptContent string, compiledFilePath string) *ScriptErrorMessage

	// Shutdown stop the engine. He can't be used anymore after that.
	// It mainly occurs after a fatal error or at script ends.
	Shutdown()

	// DisarmError remove the current error and allows continuing execution.
	// The error params allows to avoid case where a new error occurs since.
	DisarmError(error *ScriptErrorMessage)
}

func GetScriptEngine

func GetScriptEngine(engineName string) ScriptEngine

type ScriptEngineBuilder

type ScriptEngineBuilder = func() ScriptEngine

type ScriptErrorMessage

type ScriptErrorMessage struct {
	ScriptEngine ScriptEngine

	Error      string
	ErrorLevel int

	StartColumn int
	EndColumn   int

	StartPosition int
	EndPosition   int

	SourceMapUrl string
	ScriptPath   string

	StackTraceFrameCount int
	StackTraceFrames     []StackTraceFrame
	// contains filtered or unexported fields
}

func (*ScriptErrorMessage) DisarmError

func (m *ScriptErrorMessage) DisarmError()

DisarmError allows to continue after an un-catch error.

func (*ScriptErrorMessage) Print

func (m *ScriptErrorMessage) Print()

func (*ScriptErrorMessage) StackTrace

func (m *ScriptErrorMessage) StackTrace() string

func (*ScriptErrorMessage) Translate

func (m *ScriptErrorMessage) Translate()

type ScriptExecResult

type ScriptExecResult struct {
	ScriptError *ScriptErrorMessage
	GoError     error
}

func (*ScriptExecResult) HasError

func (m *ScriptExecResult) HasError() bool

func (*ScriptExecResult) PrintError

func (m *ScriptExecResult) PrintError() bool

type ScriptFunction

type ScriptFunction interface {
	CallWithArrayBuffer(buffer []byte)
	CallWithString(value string)
	CallWithStringBuffer(value []byte)
	CallWithDouble(value float64)
	CallWithUndefined()
	CallWithError(err error)
	CallWithBool(value bool)
	CallWithResource(value *SharedResource)
	KeepAlive()
}

type SharedResource

type SharedResource struct {
	Value any
	// contains filtered or unexported fields
}

func GetSharedResource

func GetSharedResource(id int) *SharedResource

func NewSharedResource

func NewSharedResource(value any, onDispose DisposeSharedResourceF) *SharedResource

func (*SharedResource) Dispose

func (m *SharedResource) Dispose()

func (*SharedResource) GetId

func (m *SharedResource) GetId() int

type StackTraceFrame

type StackTraceFrame struct {
	Line     int
	Column   int
	Function string
	Source   string
}

type StringBuffer

type StringBuffer []byte

StringBuffer allows the code generator to known that we want this bytes to be send as if it was a string. Allows to avoid the cost of converting []byte to string before calling javascript.

type TaskQueue

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

TaskQueue allows executing the C++ calls from only one thread. Without that, Go can be short on available threads which lead to a crash.

This protection is only required where there is a lot of calls that can be blocked the thread. It's essentially when calling an event and calling a callback function.

func NewTaskQueue

func NewTaskQueue() *TaskQueue

func (*TaskQueue) Dispose

func (m *TaskQueue) Dispose()

func (*TaskQueue) IsDisposed

func (m *TaskQueue) IsDisposed() bool

func (*TaskQueue) Push

func (m *TaskQueue) Push(f func())

type V8ScriptCallback

type V8ScriptCallback func(result ScriptExecResult)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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