Types - KidneyThief/TinScript1.0 GitHub Wiki

The following is a list of the types available within Tinscript, for both literal values, and for variables. All types are supported as part of the integration to C++, in that any C++ function signature that is comprised of any combination of the following types, can be directly registered and called from script. The reverse is true as well - any scripted function can be called from code.

Table of Contents

int

  • Identical to the standard C++ implementation, this type stores a 32-bit signed integer value.
  • Assignment can be in decimal, hexadecimal or binary
    • e.g. int value = 13;
    • e.g. int value = 0x0d; // also 13
    • e.g. int value = 0b1101 // also 13
  • Conversion from other types include:
Convert from type Description Example Result
float Numerical assignment, with loss of precision int x = 5.3f; x contains 5
bool Assigns the numerical value 1 or 0, converted from true or false int x = true;
int x = false;
x contains 1.0
x contains 0.0
string Assigns the value of a valid numerical string, 0 otherwise int x = "5";
int x = "cat";
x contains 5
x contains 0
object Because type object is stored internally as an unsigned
32-bit int, conversion to int gives the numerical value, but
the value itself has no meaning beyond a reference.
However, if the object does not exist, the value is 0.
// assume object obj
int i = obj;
x is non-zero
if 'obj' exists;
0 otherwise

float

  • Identical to the standard C++ implementation, this type stores a 32-bit signed real value.
  • Assignment can include the trailing 'f' (as per C++)
    • e.g. float x = 3.5f;
  • Conversion from other types include:
Convert from type Description Example Result
int Numerical assignment float x = 5; x contains 5.0
bool Assigns the numerical value 1.0 or 0.0, converted from true or false float x = true;
float x = "cat";
x contains 1
x contains 0
string Assigns the value of a valid numerical string, 0.0 otherwise float x = "5.3f";
float x = "cat";
x contains 5.3
x contains 0.0
object There is no conversion from type object to float

bool

  • Identical to the standard C++ implementation, the value this type stores is either true or false.
  • Assignment uses the keywords true and false
    • e.g. bool success = true;
Convert from type Description Example Result
int Non-zero values are true bool value = 5; value contains true
float Non-zero values are true bool value = -5.3f; value contains true
string Strings "true" and "false" convert directly;
Numerically valid non-zero strings are true
Non-empty strings are true (including " ")
All other strings are false
bool value = "false";
bool value = "-3.4f";
bool value = "cat"
value contains false
value contains true
value contains true
object The converted value is true, if the object exists,
false otherwise. However, using IsObject() is
recommended.
// assume object obj
bool val = obj;
val is true if 'obj'
exists; false otherwise

string

  • The C++ equivalent to a string is a const char*.
  • Assignment would resemble a literal string assignment, as opposed to a cout or sprintf() implementation.
    • e.g. string hello = "Hello world!";
  • String literals are delineated by double quotes, single quotes, or back quotes, to provide a way to embed delineation characters without having to escape them.
    • e.g. string str = 'This is one way to print a " (double quote) character';
  • String values are stored in a reference counted string table, so their storage is protected as long as there is at least one variable still assigned to that string value. Unreferenced strings are removed from the string table upon completion of a function call.
  • Conversion to and from a string is guaranteed for all types. This is guaranteed as one of the requirements of registering a type includes registering both "to string" and "from string" methods.
Convert from type Description Example Result
int Assigns the numerical string equivalent string str = 5; str contains "5"
float Assigns the numerical string equivalent,
although the trailing 'f' is removed,
and the string will contain 4x decimal places.
string str = -5.43f; str contains "-5.4300"
bool Boolean values are converted to "true" and "false"; string str = true; str contains "true"
object As with converting from type object to type int,
The numerical value of the "object handle"
will be converted to a string.
// assume object obj
string str = obj;
str is non-zero
if 'obj' exists;
"0" otherwise

object

  • The C++ equivalent to an object value is a 32-bit unsigned integer, equivalent to an ID number assigned to each instance.
  • It has a unique type, to ensure we script math operations using object types.
  • Variables of type object are usually assigned as the result either a "create" statement, or a call to FindObject().
  • Assigning an object value never creates a duplicate of the object - they should be treated as handles.
  • There are no valid conversions to type object - instead, use the function FindObject();
    • e.g. object playerObject = create CScriptObject("Player");
    • e.g. object playerObject = FindObject("Player");
  • C++ registered functions that manipulate objects (not object members, but objects passed as parameters) must call FindObjectEntry(<objectID>), and static_cast<> the result back to the appropriate C++ pointer.
  • As objects are a key component of the integration of TinScript into a C++ project, more information on using objects can be found in their own section.
⚠️ **GitHub.com Fallback** ⚠️