Latest version:
Tramway SDK 0.0.9
Github
Quick links
Home
Get Started

Scripting


The script system implements the scripting API. It allows you to call scripts from C++ without being concerned with which scripting language the script is actually implemented in.

Currently the only scripting language bindings that have been implemented are for the Lua language.

All scripts are located in the /scripts/ directory.

Programming in C++


#include <framework/script.h>
API documentation page.

First a script needs to be loaded. When a script is loaded from disk, it will be automatically executed.

Script::LoadScript("frog");

You can set global variables in the scripting context and retrieve global variables from it.

Script::SetGlobal("frog_status", 420);

value_t frogs = Script::GetGlobal("frog_count");

You can also register in C++ function which can be called from the scripting language. For example, this function, named frog, will accept a single integer parameter, which it will print to console. It will then return the value true if the integer inputted was 420.

Script::SetFunction("frog", {TYPE_INT},
            [](valuearray_t array) -> value_t {
    int32_t frog = array[0];
    printf("frog: %i", frog);

    return frog == 420;
});

You can also call script functions from C++.

bool result = Script::CallFunction("frog", {420});