Documentation ¶
Index ¶
- Constants
- Variables
- func ExecLgoEntryPoint(parent LgoContext, main func()) error
- func ExitIfCtxDone()
- func FinalizeGoroutine(e *ExecutionState)
- func LgoPrintln(args ...interface{})
- func LgoRegisterVar(name string, p interface{})
- func RegisterLgoPrinter(p LgoPrinter)
- func UnregisterLgoPrinter(p LgoPrinter)
- func ZeroClearAllVars()
- type DataDisplayer
- type ExecutionState
- type LgoContext
- type LgoPrinter
Constants ¶
const SelfPkgPath = "github.com/yunabe/lgo/core"
SelfPkgPath is the package path of this package
Variables ¶
var AllVars = make(map[string][]interface{})
AllVars keeps pointers to all variables defined in the current lgo process. AllVars is keyed by variable names.
var Bailout = errors.New("canceled")
Bailout is thrown to cancel lgo code execution internally. Bailout is exported to be used from converted code (See converter/autoexit.go).
Functions ¶
func ExecLgoEntryPoint ¶
func ExecLgoEntryPoint(parent LgoContext, main func()) error
ExecLgoEntryPoint executes main under a new code execution context which is derived from parent.
func ExitIfCtxDone ¶
func ExitIfCtxDone()
ExitIfCtxDone checkes the current code execution status and throws Bailout to exit the execution if the execution is canceled.
func FinalizeGoroutine ¶
func FinalizeGoroutine(e *ExecutionState)
FinalizeGoroutine is called when a goroutine invoked in lgo quits.
func LgoPrintln ¶
func LgoPrintln(args ...interface{})
LgoPrintln prints args with registered LgoPrinters.
func LgoRegisterVar ¶
func LgoRegisterVar(name string, p interface{})
LgoRegisterVar is used to register a variable to AllVars internally.
func RegisterLgoPrinter ¶
func RegisterLgoPrinter(p LgoPrinter)
RegisterLgoPrinter registers a LgoPrinter to print the result of the last lgo expression.
func UnregisterLgoPrinter ¶
func UnregisterLgoPrinter(p LgoPrinter)
UnregisterLgoPrinter removes a registered LgoPrinter.
func ZeroClearAllVars ¶
func ZeroClearAllVars()
ZeroClearAllVars clear all existing variables defined in lgo with zero-values. You can release memory holded from old variables easily with this function.
Types ¶
type DataDisplayer ¶
type DataDisplayer interface { JavaScript(s string, id *string) HTML(s string, id *string) Markdown(s string, id *string) Latex(s string, id *string) SVG(s string, id *string) PNG(b []byte, id *string) JPEG(b []byte, id *string) GIF(b []byte, id *string) PDF(b []byte, id *string) Text(s string, id *string) Raw(contentType string, v interface{}, id *string) error }
DataDisplayer is the interface that wraps Jupyter Notebook display_data protocol. The list of supported content types are based on Jupyter Notebook implementation[2]. Each method receives a content and an display id. If id is nil, the method does not use id. If id is not nil and it points an empty string, the method reserves a new display ID and stores it to id. If id is not nil and it points a non-empty string, the method overwrites a content with the same ID in Jupyter Notebooks.
Please note that JavaScript output is disabled in JupyterLab[3].
References: [1] http://jupyter-client.readthedocs.io/en/latest/messaging.html#display-data [2] https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/outputarea.js [3] https://github.com/jupyterlab/jupyterlab/issues/3748
type ExecutionState ¶
type ExecutionState struct { Context LgoContext // contains filtered or unexported fields }
ExecutionState maintains the state of the current code execution in lgo.
func InitGoroutine ¶
func InitGoroutine() *ExecutionState
InitGoroutine is called internally before lgo starts a new goroutine so that lgo can manage goroutines.
type LgoContext ¶
type LgoContext struct { // Go context.Context. context.Context // Display displays non-text content in Jupyter Notebook. Display DataDisplayer }
A LgoContext carries a context of lgo execution.
func GetExecContext ¶
func GetExecContext() LgoContext
GetExecContext returns the context of the current code execution. It returns a canceled context when lgo does not execute any code blocks. _ctx in lgo is converted to this function internally.
type LgoPrinter ¶
type LgoPrinter interface {
Println(args ...interface{})
}
LgoPrinter is the interface that prints the result of the last lgo expression.