Asset - Scripts Lightweight Data Structures

FrostyCat

Member
Lightweight Data Structures
Giving ds_*() functions a run for their money since 2020

Overview

This library implements struct-based, GC-friendly equivalents of GameMaker Studio's built-in data structures. It also adds the ability to save both single-layer and nested structures, in plaintext and RC4 ciphertext. Manual cleanups (i.e. ds_*_destroy() and the memory leaks that follow the omission thereof), manual type-marking (e.g. ds_list_mark_as_map()) and opaque single-layer read/write functions (i.e. ds_*_read() and ds_*_write()) are now relics of the past!

Downloads / Links
YoYo Marketplace: Link
GitHub: Link 1 (LDS+JSON Struct) | Link 2 (LDS only) | Repository | Wiki

Comparison

Post-2020 GML with Lightweight Data Structures:

GML:
var characters = new List(
    new Map("name", "Alice", "hp", 4),
    new Map("name", "Bob", "hp", 5),
    new Map("name", "Caitlyn", "hp", 6)
);

show_message("Caitlyn: " + string(characters.get(2).get("hp")) + "HP");
Pre-2020 stock GML:
GML:
var characters = ds_list_create();
ds_list_add(characters, ds_map_create());
ds_map_add(characters[| 0], "name", "Alice");
ds_map_add(characters[| 0], "HP", 4);
ds_list_mark_as_map(characters, 0);
ds_list_add(characters, ds_map_create());
ds_map_add(characters[| 1], "name", "Bob");
ds_map_add(characters[| 1], "HP", 5);
ds_list_mark_as_map(characters, 1);
ds_list_add(characters, ds_map_create());
ds_map_add(characters[| 2], "name", "Caitlyn");
ds_map_add(characters[| 2], "HP", 6);
ds_list_mark_as_map(characters, 2);

show_message("Caitlyn: " + string(characters.get(2).get("hp")) + "HP");

ds_list_destroy(characters);

Feedback Welcome!
If you have any suggestions or bug reports, please open an issue or contribute on GitHub.
 
Last edited:
Top