Drift Script
Introduction
DriftScript is the official scripting language of Drift Wars!
DriftScript allows you to create custom game logic for both melee and custom maps.
It is intended for people who already have good knowledge of other scripting languages such as Python.
If you are new to programming and want to start programming in DriftScript, it is recommended you
visit Python 3 and learn Python first, as it is probably easier
to learn due to more learning material.
Technical
DriftScript is a !!HEAVILY!! modified version of Squirrel 3.2 language.
Please refer to the squirrel language reference manual here:
http://squirrel-lang.org/squirreldoc/reference/language.html
Major changes from Squirrel:
- Comparison operators and tables reworked to use
_eq,_cmp, and_hash- Added user-implementable
bool _eq(other)meta-function.- Is invoked during
==and!=comparisons- If
_eqis not defined, will fallback to calling_cmpmeta-function - If
_eqand_cmpboth do not exist, fall-back to reference-equality for==.
- If
- Note: This is DIFFERENT than Squirrel's
==and!=which ALWAYS checks for reference-equality, even when_cmpis defined. - Keywords
isandis_notadded to check for reference-equality -- (i.e. Squirrel's==/!=behavior) - Keyword
not_inadded to complement existinginkeyword for checking if key exists in table.
- Is invoked during
- Added function
int hash(obj1, obj2, ..)that hashes objects/primitives - Added user-implementable
int _hash()meta-function.- Is invoked in calls to
hash(obj, ...) - If your custom class will be used as table, you should implement
_eqand_hashfunctions. - If
obj1 == obj2, thenhash(obj1) == hash(obj2)MUST be true.- If this is not true, your class will not work properly when used as keys in tables.
- Is invoked in calls to
- Tables now invoke
_hashand_eq/_cmpfor keys- Note: This is DIFFERENT than Squirrel which just checks for reference equality.
- Array and Table
==/!=operators invoke sub-object's_eq/_cmpmeta-functions.- Once again, this is DIFFERENT than Squirrel that checks for reference-equality.
- Can always use
isandis_notto compare if two arrays or tables are the same object (reference-equality)
- Added function
int object_id(obj)to get object id for class instances, arrays, and tables- returns
0for other types
- returns
array.find(value)modified to compare using_eq/_cmparray.find_ref(ref)added to check for reference-equality -- (i.e. Squirrel's behavior)
- Added user-implementable
- Added user-implementable
_unp(unary plus operator) meta-function- same as squirrel's
_unm(unary minus operator) except for+instead of-
- same as squirrel's
- Normal division operator
/always returns float now. - Added floor division operator
//. - Changed various lexing and parsing rules to be more intuitive
local a = .1is invalid in squirrel because floats must begin with a digit: i.e.0.1- However, this is valid Drift Script!
local a = +1is invalid in squirrel because numbers cannot begin with+.- However, this is valid Drift Script!
- Improved lexing of unicode source files
- Modified some additional lexing and parsing rules as well..
- Real Unicode support - very different from Squirrel.
- Drift Wars internally uses
utf-8, and so doesDrift Script! - However this adds some complexity to string operations, especially when dealing with emojis and korean characters
"🤦🏼♂️".len() == 17, and most korean characters have length3.- See https://hsivonen.fi/string-length/
- removed functions that are unsafe for
utf-8:.operator[idx],.slice(start, end),.find(str),foreach (c in string)removed.
- added new string functions:
.startswith(str),.endswith(str),.contains(str),.replace(search, replace),.split(str),.normalchars(),.empty(), andgx_str_*free functions- more string functions may be added later.
- Drift Wars internally uses
- Type changes:
inttypes are signed 64-bitfloattypes modified to be a 64-bitQ31.32fixed point types- more type information at scalar-types
- Enums and enum scopes reworked
- Function scopes reworked
- Various base library changes
- Bunch of other stuff..
Squirrel Standard Libraryis not supported.- Although, DriftScript provides many functions with identical behavior.
Future TODOs
- May add
globalkeyword for defining global variables easier - May add some form of
_destructmeta function for classes - Better error-handling and compilation/runtime errors.
- Improved vscode syntax-highlighting, auto-complete, etc.