You.i Engine
Binding

Detailed Description

Classes providing script access to You.i Engine.

Note
Currently provided as a preview.

You.i Engine provides bindings for accessing You.i Engine classes from a scripting language.

Supported Scripting Languages:

Getting Started

To acceess script source code from within a You.i Engine application the user must instance a CYIBindingContext. Currently the only available binding context is the Duktape binding context – CYIDTBindingContext. Once instanced the binding context must be initialized. Initializing the binding context loads all You.i Engine class bindings into the binding engine. Once the binding context has been instanced and initialized script source code can be executed either via a string or a CYIAssetScript.

Example:

    void InitializeAndExecuteScript()
    {
            // Instance and initialize the binding context.
            CYIDTBindingContext bindingContext;
            bindingContext.Init();

            // The binding engine is now ready to execute script source code.
            bindingContext.ExecuteString("print(\"HelloWorld\")");
    }

Custom Bindings

You.i Engine provides tools for generating custom bindings for supported binding engines. These tools are located in the SDK package under tools/Scripting. The binding generator uses an interface definition language (IDL) to generate the bindings. This languages is structured using the json format. For more information on IDL structure see the read me located in the tools/Scripting/ folder.

Duktape Engine

Location of the binding generator in the SDK package: tools/Scripting/Duktape/Binding

The generator must be provided with an input path (where the IDL files are located) and an output path (where the generated C++ source files will be generated to).

Example:

    Mac/BindingGenerator -i /path/to/idl/files -o /output/path

Once generated and compiled into an application each binding must be registered with the binding engine so that it can be accessed in script source code, this should be done before executing script source using the CYIDTBindingContext. The following example illustrates registering a Duktape binding with the Duktape engine:

    // Registers the bound class with Duktape making it accessible in script source. 
    YiSceneView_DTWrapper::CreateTemplateOnStack(m_pDKContext);

All You.i Engine bindings are registered when the CYIDTBindingContext is initialized.

Note
Bound classes must be registered in prototypical order. Meaning the first object in the prototype chain must be registered first.

Debugging

Duktape Engine

To debug Javascript source code when using a CYIDTBindingContext the Duktape debugger can be used. This debugger is located in the SDK package under tools/Scripting/DukDebug/Debugger. There are two steps to debugging first the Duktape debugger must be launched, specifying the path to the Javascript source code that is being generated. Note that only Javascript source code executed via a CYIAssetScript may be debugged. Once the debugger is launched the application code which also calls CYIBindingContext::ConnectDebugger() can be launched. It is recommended that ConnectDebugger is only called for debug builds of the application. The debugger will pause at the first line of Javascript source code. To view the Duktape debugger interface open a web browser to the url localhost:9092.

Example:

    // Starts the Duktape debugger.
    ./duk_debug.sh (.bat on Windows) /path/to/javascript/source/code

    ...

    // From application source connect the debugger.
    CYIDTBindingContext bindingContext;
    bindingContext.Init();

    #ifndef NDEBUG
    // Attempt to connect the debugger only for debug builds.
    bindingContext.ConnectDebugger();
    #endif

    // Script can now be executed and debugged. 

Classes

class  CYIBindingContext
 The entry point for executing script source code in You.i Engine. More...
 
class  CYIBindingImplementation
 The base class where binding occurs between C++ and another language. More...
 
class  CYIDTBindingContext
 A binding context implementation for the Duktape Javascript binding engine. More...
 
class  CYIDTBindingImplementation
 This is the base class for binding implementations between C++ and Javascript using the Duktape binding engine. More...
 
class  CYIScriptableObject
 The base class for an object accessible from script source code. More...
 
class  CYIScriptableRTTIObject
 The base class for an C++ object that has RTTI information and is accesible from script source code. More...
 
class  CYIScriptAppFactory