C++ types of local variables

YYC Boost can inject native C++ types into local variables. These types should be compatible with GML:

const char*
int
double

Write a comment /*:cpp_type*/ after variable name to specify its C++ type.

#macro COUNT 10000
var _t;

_t = get_timer();
for (var i = 0; i < COUNT; ++i) {}
show_debug_message(get_timer() - _t);

// This loop runs faster compared to when a regular var is used
_t = get_timer();
for (var j/*:int*/= 0; j < COUNT; ++j) {}
show_debug_message(get_timer() - _t);

Known limitations

Variable types can be defined only once for vars with the same name in the same scope! In the following code the variable _a would always be defined as an int.

if (wholeNumbersOnly)
{
    var _a/*:int*/ = 0;
}
else
{
    var _a/*:double*/ = 0.0;
}
Do you find this page helpful?

Copyright © 2021, Patrik Kraif. Built on October 14, 2021 using GMDoc.