Visual Scripting Backend
Overview
- Parser
\Code\Common\Public\Common\Scripting\Parser - Interpreter
\Code\Common\Public\Common\Scripting\Interpreter - Compiler
\Code\Common\Public\Common\Scripting\Compiler - Virtual Machine
\Code\Common\Public\Common\Scripting\VirtualMachine
-
.script.sourcefor the text source file (we use LUA syntax for now) -
.script.binarycompiled binary format of.script.source
Compilation Options
SCRIPTING_USE_UNICODE
ngine::String and ngine::UnicodeString as script string typeSCRIPTING_DEBUG_INFO
- Enables additional debug information in the compiled byte code. For now this is only line numbers.
- Default: Enabled for now, since we are still in development (should be disabled for release)
SCRIPTING_DEBUG_TRACE_EXECUTION
- Enables virtual machine opcode execution tracing. Giving detailed output of each executed instruction with the current stack and upvalues.
- Default: Disabled should only be used when debugging VM execution bugs
SCRIPTING_DEBUG_GC_LOG
- Enables detailed log output for the script garbage collection
- Default: Disabled should only be used when debugging VM garbage collection bugs
SCRIPTING_VALUE_NAN_BOXING
- Enables nan boxing for compiled script values. This reduces the
ngine::Scripting::Valuesize from 16 bytes to 8 bytes. - Default: Disabled because runtime cost seems higher with the memory saving.
SCRIPTING_COMPONENT_USE_INTERPRETER
- Switches the script component to use AST interpretation instead of executing compiled code
- Default: Disabled because we prefer compiled code execution (optimized, smaller, faster)
Parser
ngine::Scripting::TokenListType and (if successful) produces a complete AST with the root node UniquePtr
Interpreter
UniquePtr and executes it by walking and interpreting the AST directly. This uses its own environment ngine::Scripting::Environment . For the execution a separate input ( SharedPtr ) of resolved variables is needed which can be generated from the Resolver ngine::Scripting::Resolver . The interpreter is exposed to the editor as a script component if interpretation is enabled and compiled in via SCRIPTING_COMPONENT_USE_INTERPRETER
Exposing of native functions
ngine::Scripting::ScriptFunction
GetArity() which should return the required amount of arguments and Call for the actual function implementation. Values can be marshalled (in both directions) through ngine::Scripting::Interpreter::Convert . It can be added to the environment via AddFunction(SCRIPT_STRING_LITERAL("name"), UniquePtr::Make())
Compiler
UniquePtr and generates self contained byte code UniquePtr that can be executed by the virtual machineVirtual Machine
UniquePtr and executes it. As environment table it uses the ngine::Scripting::EnvironmentObject which can be used to inject external values and functions.Exposing of native functions
bool MyFunction(ngine::Scripting::VMState& state, uint8, ngine::Scripting::Value* pArgs)ngine::Scripting::Convert . It can be added to the environment via ngine::Scripting::AddNativeFunctionToTable
Feedback
Please be sure to submit issues or feature requests through the embedded feedback form. In the event it is a major issue please contact us directly through Discord.












