Skip to content

Commit

Permalink
implemented 'expose all' for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
katsaii committed Aug 3, 2024
1 parent 1dcb62f commit ec5ef0a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function CatspeakForeignInterface() constructor {
/// @experimental
///
/// @remark
/// **Does not** support the physics capabilities of GameMaker because of some
/// weird quirks with how functions are bound.
///
/// @warning
/// Potentially extremely slow, since every global variable will iterate over
/// a massive list of constants and functions in order to find a reference.
///
Expand Down Expand Up @@ -83,6 +87,13 @@ function CatspeakForeignInterface() constructor {
if (variable_struct_exists(db, name)) {
return db[$ name];
}
var asset = asset_get_index(name);
if (asset != -1) {
if (asset_get_type(name) == asset_script) {
return method(undefined, asset);
}
return asset;
}
} catch (_) {
__catspeak_error_silent("GML interface not included, defaulting to `undefined`");
}
Expand Down Expand Up @@ -126,7 +137,7 @@ function CatspeakForeignInterface() constructor {
if (exposeEverythingIDontCareIfModdersCanEditUsersSaveFilesJustLetMeDoThis) {
try {
var db = __catspeak_get_gml_interface();
return variable_struct_exists(db, name);
return variable_struct_exists(db, name) || asset_get_index(name) != -1;
} catch (_) {
__catspeak_error_silent("GML interface not included, defaulting to `false`");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,20 @@ test_add(function() : Test("expose-everything-func") constructor {
assertEq(true, result[1](""));
assertEq(false, result[1](-12));
assertEq(sha1_string_unicode("some hash"), result[2]("some hash"));
});

test_add(function() : Test("expose-everything-assets") constructor {
var env = new CatspeakEnvironment();
env.interface.exposeEverythingIDontCareIfModdersCanEditUsersSaveFilesJustLetMeDoThis = true;
var ir = env.parseString(@'
let inst = instance_create_depth(1, 2, 3, obj_unit_test_inst);
return inst;
');
var fun = env.compile(ir);
var result = fun();
assert(instance_exists(result));
assertEq(1, result.x);
assertEq(2, result.y);
assertEq(3, result.depth);
instance_destroy(result);
});

0 comments on commit ec5ef0a

Please sign in to comment.