Introduction

D0 uses the AngelScript scripting language for all of its inline snippets. AngelScript has similar syntax to C/C++ while being fast to compile. D0 also adds custom syntax and API's to make the language have a closer overlap with C++ programs.

Inserting a new snippet:

  • Attach or start a process with the Visual Studio debugger
  • Place the cursor on the line you want to insert a code snippet.
  • Right click on the line, and choose "Insert D0 snippet"
  • By default, the snippet will be a view() call. Check Available functions for other functions.
  • Close the snippet by pressing escape and go to Extensions, D0 and choose Show Object View

C/C++ interoperability

When D0 compiles your snippets, it detects the context a snippet is added in, using the PDB file. Local variables, functions and types are inferred dynamically, while the snippet is compiled. This might take more time depending on the size of the PDB file and used symbols.

Because AngelScript does not have a full feature set of C++, some functionality such as full template types is unavailable (D0 supports types which were instantiated at compile time of the target program).

Furthermore, member functions that are not used in the target program are usually not linked with the target program, which means that D0 won't be able to find them. This is something that we would like to be able to resolve in the future.

Variables

You can declare global or local variables inside snippets:

float aGlobalVariable = 5;
void ProgramClass::ProgramMethod()
{
    FunctionCall();
float aLocalVariable = 15.0f;
    aGlobalVariable = 10.0f;
AnotherFunction();
}

Global variables declared outside a function are available in any other snippet/file. Local variables are available only in the snippet they are in, as such, D0 does not support using a local variable declared in a snippet in the same function yet:

void Function()
{
bool value = false;
while (running) {
view(value);
        if (value) { // compiler error: value is not available here
            running = false;
        }
Draw();
    }
}

To workaround this issue, you can declare value as a global variable, outside of Function.

Namespaces

When referencing types or structs from your program, use the full name, including any namespaces:

Namespace::Namespace2::ClassName

If a function/class is in an anonymous namespace, this translates to no namespace at all, this class:

namespace {
    namespace Namespace {
        class Empty {

        }
    }
}

would be accessible with:

Namespace::Empty empty;

Classes & structs

AngelScript supports initialing an instance of a class the same way you would do in C++:

Namespace::Class instance;

If you are adding a snippet in a class member program function, using its members requires to prefix them with this->:

void ProgramClass::ProgramMethod()
{
    m_variable = 32;
this->m_variable++;
}

Additional behavior of native objects

Objects that are native to your program have additional behaviors that helps with introspection and using them in snippets.

Native objects can be implicitly casted into a pointer. Given a C++ function:
void Function(ProgramClass* instance)
{
    ...
}
It is possible to call the function in the snippet with a native object without explicit casts:
ProgramClass instance;
Function(instance); // gets casted to ptr<ProgramClass> implicitly

ptr<ProgramClass> instancePtr = instance;  // explicit cast
Function(instancePtr);

Native objects can be serialized to a string representation that log() normally prints:

ProgramClass instance;
string serialized = instance + "";
log(serialized); // prints the same as log(instance)